Module io.ebean.api
Package io.ebean

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 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).

      Specified by:
      loadCount in interface PagedList<T>
    • getFutureCount

      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 interface PagedList<T>
    • getList

      public List<T> getList()
      Description copied from interface: PagedList
      Return the list of entities for this page.
      Specified by:
      getList in interface PagedList<T>
    • 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 interface PagedList<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 interface PagedList<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 interface PagedList<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 interface PagedList<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.

      Specified by:
      hasNext in interface PagedList<T>
    • hasPrev

      public boolean hasPrev()
      Description copied from interface: PagedList
      Return true if there is a previous page.
      Specified by:
      hasPrev in interface PagedList<T>
    • 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 interface PagedList<T>
      Parameters:
      to - String to put between the first and last row
      of - String to put between the last row and the total row count
      Returns:
      String of the format XtoYofZ.