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;
import org.jetbrains.annotations.NotNull;
/**
* Oracle page helper, e.g.
*
* select *
* from (select t.*, rownum {@link #ROW_NUM_KEY}
* from (...) t
* where rownum <= :{@link #END_NUM_KEY})
* where {@link #ROW_NUM_KEY} >= :{@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 @NotNull String pagedSql(char namedParamPrefix, @NotNull String sql) {
return "select *\n" +
"from (select t.*, rownum " + ROW_NUM_KEY + "\n" +
" from (" + sql + ") t\n" +
" where rownum <= " + namedParamPrefix + END_NUM_KEY + ")\n" +
" where " + ROW_NUM_KEY + " >= " + namedParamPrefix + START_NUM_KEY;
}
@Override
public @NotNull Args pagedArgs() {
return Args.of(START_NUM_KEY, start()).add(END_NUM_KEY, end());
}
}