public class Oracle10gDialectPaging extends Oracle10gDialect {
@Override
public String getLimitString(String sql, boolean hasOffset) {
sql = sql.trim();
String forUpdateClause = null;
boolean isForUpdate = false;
final int forUpdateIndex = sql.toLowerCase().lastIndexOf("for update");
if (forUpdateIndex > -1) {
forUpdateClause = sql.substring(forUpdateIndex);
sql = sql.substring(0, forUpdateIndex - 1);
isForUpdate = true;
}
StringBuilder pagingSelect = new StringBuilder(sql.length() + 100);
pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
pagingSelect.append(sql);
if (hasOffset) {
pagingSelect.append(" ) row_) where rownum_ <= ? and rownum_ > ?");
} else {
pagingSelect.append(" ) row_) where rownum_ <= ?");
}
if (isForUpdate) {
pagingSelect.append(" ");
pagingSelect.append(forUpdateClause);
}
return pagingSelect.toString();
}