Skip to content

Commit f6add9d

Browse files
committed
simplify the generated code for cursored pagination
as suggested by Nathan Rauh Signed-off-by: Gavin King <[email protected]>
1 parent 6beb011 commit f6add9d

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -376,22 +376,10 @@ void makeKeyedPage(StringBuilder declaration, List<String> paramTypes) {
376376
"\t\t\t\t\t\t.stream()\n" +
377377
"\t\t\t\t\t\t.map(_key -> Cursor.forKey(_key.toArray()))\n" +
378378
"\t\t\t\t\t\t.collect(toList());\n" +
379-
"\t\tvar _next =\n" +
380-
"\t\t\t\tPageRequest.of(Entity.class)\n" +
381-
//SHOULD NOT have cast to raw Iterable
382-
"\t\t\t\t\t\t.sortBy((Iterable) pageRequest.sorts())\n" +
383-
"\t\t\t\t\t\t.size(pageRequest.size())\n" +
384-
"\t\t\t\t\t\t.page(pageRequest.page() + 1);\n" +
385-
"\t\tvar _last =\n" +
386-
"\t\t\t\tPageRequest.of(Entity.class)\n" +
387-
//SHOULD NOT have cast to raw Iterable
388-
"\t\t\t\t\t\t.sortBy((Iterable) pageRequest.sorts())\n" +
389-
"\t\t\t\t\t\t.size(pageRequest.size())\n" +
390-
"\t\t\t\t\t\t.page(pageRequest.page() - 1);\n" +
391379
//SHOULD BE new CursoredPageRecord<>
392380
"\t\treturn new CursoredPageRecord(_results.getResultList(), _cursors, _totalResults, pageRequest,\n" +
393-
"\t\t\t\t_results.isLastPage() ? null : _next.afterKey(_results.getNextPage().getKey().toArray()),\n" +
394-
"\t\t\t\t_results.isFirstPage() ? null : _last.beforeKey(_results.getPreviousPage().getKey().toArray()));";
381+
"\t\t\t\t_results.isLastPage() ? null : pageRequest.page(pageRequest.page()+1).afterCursor(_cursors.get(_cursors.size()-1)),\n" +
382+
"\t\t\t\t_results.isFirstPage() ? null : pageRequest.page(pageRequest.page()-1).beforeCursor(_cursors.get(0)));";
395383

396384
static final String MAKE_KEYED_PAGE
397385
= "\tvar _unkeyedPage =\n" +

0 commit comments

Comments
 (0)