- All Implemented Interfaces:
PagedList<T>
For use in application code when we need to return a PagedList but don't want to execute a query.
PagedList<Customer> empty = PagedList.emptyList();
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetDisplayXtoYofZ
(String to, String of) Helper method to return a "X to Y of Z" string for this page where X is the first row, Y the last row and Z the total row count.Return the Future row count.getList()
Return the list of entities for this page.int
Return the index position of this page (Zero based).int
Return the page size used for this query.int
Return the total row count for all pages.int
Return the total number of pages based on the page size and total row count.boolean
hasNext()
Return true if there is a next page.boolean
hasPrev()
Return true if there is a previous page.void
Initiate the loading of the total row count in the background.
-
Constructor Details
-
EmptyPagedList
public EmptyPagedList()
-
-
Method Details
-
loadCount
public void loadCount()Description copied from interface:PagedList
Initiate the loading of the total row count in the background.// initiate the loading of the total row count // in a background thread pagedList.loadRowCount(); // fetch and return the list in the foreground thread List<Order> orders = pagedList.getList(); // get the total row count (from the future) int totalRowCount = pagedList.getTotalRowCount();
Also note that using loadRowCount() and getTotalRowCount() rather than getFutureRowCount() means that exceptions ExecutionException, InterruptedException, TimeoutException are instead wrapped in the unchecked PersistenceException (which might be preferrable).
-
getFutureCount
Description copied from interface:PagedList
Return the Future row count. You might get this if you wish to cancel the total row count query or specify a timeout for the row count query.The loadRowCount() and getTotalRowCount() methods internally make use of this getFutureRowCount() method. Generally I expect people to prefer loadRowCount() and getTotalRowCount() over getFutureRowCount().
// initiate the row count query in the background thread Future<Integer> rowCount = pagedList.getFutureRowCount(); // fetch and return the list in the foreground thread List<Order> orders = pagedList.getList(); // now get the total count with a timeout Integer totalRowCount = rowCount.get(30, TimeUnit.SECONDS); // or ge the total count without a timeout Integer totalRowCountViaFuture = rowCount.get(); // which is actually the same as ... int totalRowCount = pagedList.getTotalRowCount();
- Specified by:
getFutureCount
in interfacePagedList<T>
-
getList
Description copied from interface:PagedList
Return the list of entities for this page. -
getTotalCount
public int getTotalCount()Description copied from interface:PagedList
Return the total row count for all pages.If loadRowCount() has already been called then the row count query is already executing in a background thread and this gets the associated Future and gets the value waiting for the future to finish.
If loadRowCount() has not been called then this executes the find row count query and returns the result and this will just occur in the current thread and not use a background thread.
// Optional: initiate the loading of the total // row count in a background thread pagedList.loadRowCount(); // fetch and return the list in the foreground thread List<Order> orders = pagedList.getList(); // get the total row count (which was being executed // in a background thread if loadRowCount() was used) int totalRowCount = pagedList.getTotalRowCount();
- Specified by:
getTotalCount
in interfacePagedList<T>
-
getTotalPageCount
public int getTotalPageCount()Description copied from interface:PagedList
Return the total number of pages based on the page size and total row count.This method requires that the total row count has been fetched and will invoke the total row count query if it has not already been invoked.
- Specified by:
getTotalPageCount
in interfacePagedList<T>
-
getPageSize
public int getPageSize()Description copied from interface:PagedList
Return the page size used for this query. This is the same value as maxRows used by the query.- Specified by:
getPageSize
in interfacePagedList<T>
-
getPageIndex
public int getPageIndex()Description copied from interface:PagedList
Return the index position of this page (Zero based).This is a calculated value based on firstRow/maxRows.
- Specified by:
getPageIndex
in interfacePagedList<T>
-
hasNext
public boolean hasNext()Description copied from interface:PagedList
Return true if there is a next page.This method requires that the total row count has been fetched and will invoke the total row count query if it has not already been invoked.
-
hasPrev
public boolean hasPrev()Description copied from interface:PagedList
Return true if there is a previous page. -
getDisplayXtoYofZ
Description copied from interface:PagedList
Helper method to return a "X to Y of Z" string for this page where X is the first row, Y the last row and Z the total row count.This method requires that the total row count has been fetched and will invoke the total row count query if it has not already been invoked.
- Specified by:
getDisplayXtoYofZ
in interfacePagedList<T>
- Parameters:
to
- String to put between the first and last rowof
- String to put between the last row and the total row count- Returns:
- String of the format XtoYofZ.
-