Skip to content

Commit

Permalink
refactored the pagination SQL for readAll()
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Jun 15, 2018
1 parent 6db4a56 commit 3626e7f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main/java/com/erudika/para/persistence/H2Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,19 @@ protected static <P extends ParaObject> List<P> scanRows(String appid, Pager pag
String table = getTableNameForAppid(appid);
int start = pager.getPage() <= 1 ? 0 : (int) (pager.getPage() - 1) * pager.getLimit();
try (Connection conn = getConnection(); PreparedStatement p = conn.prepareStatement(
"SELECT ROWNUM(), json, json_updates FROM (SELECT json, json_updates FROM " + table + ") "
+ "WHERE ROWNUM() > ? LIMIT ?")) {
Utils.formatMessage("SELECT json, json_updates FROM {0} LIMIT ? OFFSET ?", table))) {

List<P> results = new ArrayList<>(pager.getLimit());
p.setInt(1, start);
p.setInt(2, pager.getLimit());
p.setInt(1, pager.getLimit());
p.setInt(2, start);
try (ResultSet res = p.executeQuery()) {
int i = 0;
while (res.next()) {
P obj = ParaObjectUtils.fromJSON(res.getString(2));
P obj = ParaObjectUtils.fromJSON(res.getString(1));
if (obj != null) {
if (res.getString(3) != null) {
if (res.getString(2) != null) {
results.add(ParaObjectUtils.setAnnotatedFields(obj,
ParaObjectUtils.getJsonReader(Map.class).readValue(res.getString(3)), null));
ParaObjectUtils.getJsonReader(Map.class).readValue(res.getString(2)), null));
} else {
results.add(obj);
}
Expand Down

0 comments on commit 3626e7f

Please sign in to comment.