com.github.chengyuxing.sql.page.impl.OraclePageHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rabbit-sql Show documentation
Show all versions of rabbit-sql Show documentation
Light wrapper of JDBC, support ddl, dml, query, plsql/procedure/function, transaction and manage sql
file.
package com.github.chengyuxing.sql.page.impl;
import com.github.chengyuxing.sql.Args;
import com.github.chengyuxing.sql.page.PageHelper;
/**
* Oracle page helper, e.g.
*
* SELECT *
* FROM (SELECT t.*, ROWNUM RN_4_RABBIT
* FROM (...) t
* WHERE ROWNUM <= :{@link #END_NUM_KEY})
* WHERE RN_4_RABBIT >= :{@link #START_NUM_KEY}
*
*
* @see #pagedArgs()
*/
public class OraclePageHelper extends PageHelper {
public int end() {
int end = pageNumber * pageSize;
if (end > recordCount)
end = recordCount;
return end;
}
public int start() {
return (pageNumber - 1) * pageSize + 1;
}
@Override
public String pagedSql(String sql) {
return "SELECT *\n" +
"FROM (SELECT t.*, ROWNUM " + ROW_NUM_KEY + "\n" +
" FROM (" + sql + ") t\n" +
" WHERE ROWNUM <= " + end() + ")\n" +
" WHERE " + ROW_NUM_KEY + " >= " + start();
}
@Override
public Args pagedArgs() {
return Args.of(START_NUM_KEY, start()).add(END_NUM_KEY, end());
}
}