com.avaje.ebean
Interface PagingList<T>

Type Parameters:
T - the entity bean type

public interface PagingList<T>

Used to page through a query result rather than fetching all the results in a single query.

Has the ability to use background threads to 'fetch ahead' the next page and get the total row count.

If you are building a stateless web application and not keeping the PagingList over multiple requests then there is not much to be gained in using PagingList. Instead you can just use Query.setFirstRow(int) and Query.setMaxRows(int).

If you are using PagingList is a stateful web application where the PagingList is held over multiple requests then PagingList provides the extra benefits of

So with PagingList when you use Page 2 it can automatically fetch Page 3 data in the background (using a findFutureList() query). It also automatically propagates the persistence context so that all the queries executed by the PagingList all use the same persistence context.

 PagingList<TOne> pagingList = 
     Ebean.find(TOne.class)
         .where().gt("name", "2")
                   .findPagingList(10);
 
 // get the row count in the background...
 // ... otherwise it is fetched on demand
 // ... when getRowCount() or getPageCount() 
 // ... is called
 pagingList.getFutureRowCount();
 
 // get the first page
 Page<TOne> page = pagingList.getPage(0);
 
 // get the beans from the page as a list
 List<TOne> list = page.getList();
 

Author:
rbygrave

Method Summary
 List<T> getAsList()
          Return the data for all the pages in the form of a single List.
 Future<Integer> getFutureRowCount()
          Return the Future for getting the total row count.
 Page<T> getPage(int i)
          Return the page for a given page position (starting at 0).
 int getPageSize()
          Return the page size.
 int getTotalPageCount()
          Return the total page count.
 int getTotalRowCount()
          Return the total row count.
 void refresh()
          Refresh will clear all the pages and row count forcing them to be re-fetched when next required.
 PagingList<T> setFetchAhead(boolean fetchAhead)
          By default fetchAhead is true so use this to turn off fetchAhead.
 

Method Detail

refresh

void refresh()
Refresh will clear all the pages and row count forcing them to be re-fetched when next required.


setFetchAhead

PagingList<T> setFetchAhead(boolean fetchAhead)
By default fetchAhead is true so use this to turn off fetchAhead.

Set this to false if you don't want to fetch ahead using background fetching.

If set to true (or left as to default) then the next page is fetched in the background as soon as the list is accessed.


getFutureRowCount

Future<Integer> getFutureRowCount()
Return the Future for getting the total row count.


getAsList

List<T> getAsList()
Return the data for all the pages in the form of a single List.

Iterating through this list will automatically fire the paging queries as required.


getPageSize

int getPageSize()
Return the page size. This is the number of rows per page.


getTotalRowCount

int getTotalRowCount()
Return the total row count.

This gets the result from getFutureRowCount and will wait until that query has completed.


getTotalPageCount

int getTotalPageCount()
Return the total page count.

This is based on the total row count. This will wait until the row count has returned if it has not already.


getPage

Page<T> getPage(int i)
Return the page for a given page position (starting at 0).



Copyright © 2010. All Rights Reserved.