Class EmptyPagedList<T>
- java.lang.Object
-
- io.ebean.EmptyPagedList<T>
-
- All Implemented Interfaces:
PagedList<T>
public class EmptyPagedList<T> extends Object implements PagedList<T>
An empty PagedList.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
Constructors Constructor Description EmptyPagedList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getDisplayXtoYofZ(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.Future<Integer>
getFutureCount()
Return the Future row count.List<T>
getList()
Return the list of entities for this page.int
getPageIndex()
Return the index position of this page (Zero based).int
getPageSize()
Return the page size used for this query.int
getTotalCount()
Return the total row count for all pages.int
getTotalPageCount()
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
loadCount()
Initiate the loading of the total row count in the background.
-
-
-
Constructor Detail
-
EmptyPagedList
public EmptyPagedList()
-
-
Method Detail
-
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
@Nonnull public Future<Integer> 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
@Nonnull public List<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
public String getDisplayXtoYofZ(String to, String of)
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.
-
-