FindCount & PagedList

How Ebean's findCount query works and how to use PagedList


The benefit of using PagedList over just using the normal Query with Query.setFirstRow(int) and Query.setMaxRows(int) is that it additionally wraps functionality that can call Query.findFutureCount() to determine total row count, total page count etc.

Internally this works using Query.setFirstRow(int) and Query.setMaxRows(int) on the query. This translates into SQL that uses limit offset, rownum or row_number function to limit the result set.

Example: typical use including total row count

// Find the first 100 new orders

PagedList<Order> pagedOrders
  = Order.find.where()

// Optional: initiate the loading of the total
// row count in a background thread

// fetch and return the list in the foreground thread
List<Order> orders = pagedOrders.getList();

  // get the total row count (from the future)
int totalRowCount = pagedOrders.getTotalRowCount();