Skip to content

Commit

Permalink
fixed #271 result set reversal on backwards keyset pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobe91 committed Oct 22, 2016
1 parent 783ea02 commit bbaeb28
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public PagedList<X> getResultList() {
}

List<X> queryResultList = objectQuery.getResultList();

if (keysetMode == KeysetMode.PREVIOUS) {
Collections.reverse(queryResultList);
}

PagedList<X> pagedResultList = new PagedListImpl<X>(queryResultList, newKeyset, totalSize, queryFirstResult, pageSize);
return pagedResultList;
} else {
Expand All @@ -141,6 +146,10 @@ public PagedList<X> getResultList() {
return new PagedListImpl<X>(newKeysetPage, totalSize, queryFirstResult, pageSize);
}

if (keysetMode == KeysetMode.PREVIOUS) {
Collections.reverse(result);
}

KeysetPage newKeyset = null;

if (keysetExtraction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ public void simpleNormalTest() {
simpleTest(crit, pcb, result);
}

@Test
public void backwardsPaginationResultSetOrder() {
CriteriaBuilder<Tuple> crit = cbf.create(em, Tuple.class).from(Document.class, "d")
.select("d.name").select("d.owner.name");
crit.orderByDesc("d.owner.name")
.orderByDesc("d.name")
.orderByAsc("d.id");

PaginatedCriteriaBuilder<Tuple> pcb = crit.page(null, 2, 1);
PagedList<Tuple> result = pcb.getResultList();

// scroll backwards
result = crit.page(result.getKeysetPage(), 0, 2).getResultList();

assertEquals(2, result.getSize());
assertEquals("doc3", result.get(0).get(0));
assertEquals("doc2", result.get(1).get(0));
}

@Test
public void testWithReferenceObject() {
Document reference = cbf.create(em, Document.class).where("name").eq("doc3").getSingleResult();
Expand Down

0 comments on commit bbaeb28

Please sign in to comment.