simplify the generated code for cursored pagination

as suggested by Nathan Rauh

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-03-29 23:40:03 +01:00
parent 6beb011369
commit f6add9dbbb
1 changed files with 2 additions and 14 deletions

View File

@ -376,22 +376,10 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
"\t\t\t\t\t\t.stream()\n" +
"\t\t\t\t\t\t.map(_key -> Cursor.forKey(_key.toArray()))\n" +
"\t\t\t\t\t\t.collect(toList());\n" +
"\t\tvar _next =\n" +
"\t\t\t\tPageRequest.of(Entity.class)\n" +
//SHOULD NOT have cast to raw Iterable
"\t\t\t\t\t\t.sortBy((Iterable) pageRequest.sorts())\n" +
"\t\t\t\t\t\t.size(pageRequest.size())\n" +
"\t\t\t\t\t\t.page(pageRequest.page() + 1);\n" +
"\t\tvar _last =\n" +
"\t\t\t\tPageRequest.of(Entity.class)\n" +
//SHOULD NOT have cast to raw Iterable
"\t\t\t\t\t\t.sortBy((Iterable) pageRequest.sorts())\n" +
"\t\t\t\t\t\t.size(pageRequest.size())\n" +
"\t\t\t\t\t\t.page(pageRequest.page() - 1);\n" +
//SHOULD BE new CursoredPageRecord<>
"\t\treturn new CursoredPageRecord(_results.getResultList(), _cursors, _totalResults, pageRequest,\n" +
"\t\t\t\t_results.isLastPage() ? null : _next.afterKey(_results.getNextPage().getKey().toArray()),\n" +
"\t\t\t\t_results.isFirstPage() ? null : _last.beforeKey(_results.getPreviousPage().getKey().toArray()));";
"\t\t\t\t_results.isLastPage() ? null : pageRequest.page(pageRequest.page()+1).afterCursor(_cursors.get(_cursors.size()-1)),\n" +
"\t\t\t\t_results.isFirstPage() ? null : pageRequest.page(pageRequest.page()-1).beforeCursor(_cursors.get(0)));";
static final String MAKE_KEYED_PAGE
= "\tvar _unkeyedPage =\n" +