Here is the scenario. I had a page with a list of records shown all (without pagination).
Now at the backend side, the records are retrieved with a combination of 2 separate named queries for each part (one each for actual records/count of part1/part2);
@NamedQuery(name = "CustomDOTO.findPart1", query = "SELECT part1";
@NamedQuery(name = "CustomDOTO.findPart1Count", query = "SELECT count(part1)";
@NamedQuery(name = "CustomDOTO.findPart2", query = "SELECT part2";
@NamedQuery(name = "CustomDOTO.findPart2Count", query = "SELECT count(part2)";
Now I need to implement pagination for the same. So I use a custom class PagedResponse for the same which actually just consists 2 things;
private Long totalRecords;
private List<T> records;
Also I use a custom method runPaginatedQuery to return paginated response;
protected <T> PagedResponse<T> runPaginatedQuery(Query query, Query cntQuery, int startingResult, int maxResults) {
}
My question is since I have 2 separate named queries, if I call the runPaginatedQuery
method 2 times for each of the named queries, it does not help me, since the max results would increase on each call.
How do I handle the same on the Java side? I already have the UI ready to handle.