Skip to content

Commit

Permalink
fix pagination ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jun 17, 2010
1 parent cd3cf14 commit e5b99b2
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -207,15 +207,18 @@ public List<CodeFragment> searchCodeFragments(CodeFragment codeFragment, int pag
criteria.where(predicates.toArray(new Predicate[0])).orderBy(builder.desc(root.get(CodeFragment_.datetime)));

Query q = entityManager.createQuery(criteria);

int totalRecords = q.getResultList().size();

q.setFirstResult(page * PAGE_SIZE);
q.setMaxResults(PAGE_SIZE);

@SuppressWarnings("unchecked")
List<CodeFragment> codes = q.getResultList();

paginator.setPage(page);
paginator.setRecordsCount(codes.size());
paginator.setPagesCount(codes.size() / PAGE_SIZE);
paginator.setRecordsCount(totalRecords);
paginator.setPagesCount(totalRecords / PAGE_SIZE);

return codes;
}
Expand Down

0 comments on commit e5b99b2

Please sign in to comment.