All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avaje.ebean.PagingList Maven / Gradle / Ivy

The newest version!
package com.avaje.ebean;

import java.util.List;
import java.util.concurrent.Future;

/**
 * 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 {@link Query#setFirstRow(int)} and * {@link 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 *

    *
  • Fetch ahead - automatically fetching the next page via background query * execution
  • *
  • Automatic propagation of the persistence context
  • *
*

*

* 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 * * @param * the entity bean type */ public interface PagingList { /** * Refresh will clear all the pages and row count forcing them to be * re-fetched when next required. */ public void refresh(); // public void fetchAll(); // public String? getOrderBy(); // public void setOrderBy(String?); /** * 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. *

*/ public PagingList setFetchAhead(boolean fetchAhead); /** * Return the Future for getting the total row count. */ public Future getFutureRowCount(); /** * 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. *

*/ public List getAsList(); /** * Return the page size. This is the number of rows per page. */ public int getPageSize(); /** * Return the total row count. *

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

*/ public int getTotalRowCount(); /** * 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. *

*/ public int getTotalPageCount(); /** * Return the page for a given page position (starting at 0). */ public Page getPage(int i); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy