Interface Pageable
This class represents pagination information.
Pageable is optionally specified as a parameter to a
repository method in one of the parameter positions after the
query parameters. For example,
@OrderBy("age")
@OrderBy("ssn")
Person[] findByAgeBetween(int minAge, int maxAge, Pageable pagination);
...
for (Pageable p = Pageable.ofSize(100); p != null; p = page.length == 0 ? null : p.next()) {
page = people.findByAgeBetween(35, 59, p);
...
}
A repository method will fail with a
DataException
or a more specific subclass if
- multiple
Pageableparameters are supplied to the same method. PageableandLimitparameters are supplied to the same method.- a
Pageableparameter is supplied in combination with theFirstkeyword. - a
Pageableparameter is supplied and separateSortparameters are also supplied to the same method. - the database is incapable of ordering with the requested sort criteria.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents keyset values, which can be a starting point for requesting a next or previous page.static enumThe type of pagination, which can be offset pagination or keyset cursor pagination which includes a direction. -
Method Summary
Modifier and TypeMethodDescriptionafterKeyset(Object... keyset) Requestskeyset paginationin the forward direction, starting after the specified keyset values.afterKeysetCursor(Pageable.Cursor keysetCursor) Requestskeyset paginationin the forward direction, starting after the specified keyset values.beforeKeyset(Object... keyset) Requestskeyset paginationin the reverse direction, starting after the specified keyset values.beforeKeysetCursor(Pageable.Cursor keysetCursor) Requestskeyset paginationin the reverse direction, starting after the specified keyset values.cursor()Returns the keyset values which are the starting point for keyset pagination.booleanCompares with another instance to determine if both represent the same pagination information.mode()Returns the type of pagination.next()Returns thePageablerequesting the next page if using offset pagination.static PageableofPage(long pageNumber) Creates a newPageablewith the given page number and with a default size of 10.static PageableofSize(int maxPageSize) Creates a newPageablefor requesting pages of the specified size, starting with the first page number, which is 1.longpage()Returns the page to be returned.page(long pageNumber) Creates a newPageableinstance representing the same pagination information, except with the specified page number.intsize()Returns the requested size of each pagesize(int maxPageSize) Creates a newPageableinstance representing the same pagination information, except with the specified maximum page size.Creates a newPageableinstance representing the same pagination information, except using the specified sort criteria.Creates a newPageableinstance representing the same pagination information, except using the specified sort criteria.sorts()Return the order collection if it was specified on thisPageable, otherwise an empty list.
-
Method Details
-
ofPage
Creates a newPageablewith the given page number and with a default size of 10.- Parameters:
pageNumber- The page number.- Returns:
- a new instance of
Pageable. This method never returnsnull. - Throws:
IllegalArgumentException- when the page number is negative or zero.
-
ofSize
Creates a newPageablefor requesting pages of the specified size, starting with the first page number, which is 1.- Parameters:
maxPageSize- The number of query results in a full page.- Returns:
- a new instance of
Pageable. This method never returnsnull. - Throws:
IllegalArgumentException- when maximum page size is negative or zero.
-
afterKeyset
Requests
keyset paginationin the forward direction, starting after the specified keyset values.- Parameters:
keyset- keyset values, the order and number of which must match theOrderByannotations,Sortparameters, orOrderByname pattern of the repository method to which this pagination will be supplied.- Returns:
- a new instance of
Pageablewith forward keyset pagination. This method never returnsnull. - Throws:
IllegalArgumentException- if no keyset values are provided.
-
beforeKeyset
Requests
keyset paginationin the reverse direction, starting after the specified keyset values.- Parameters:
keyset- keyset values, the order and number of which must match theOrderByannotations,Sortparameters, orOrderByname pattern of the repository method to which this pagination will be supplied.- Returns:
- a new instance of
Pageablewith reverse keyset pagination. This method never returnsnull. - Throws:
IllegalArgumentException- if no keyset values are provided.
-
afterKeysetCursor
Requests
keyset paginationin the forward direction, starting after the specified keyset values.- Parameters:
keysetCursor- cursor with keyset values, the order and number of which must match theOrderByannotations,Sortparameters, orOrderByname pattern of the repository method to which this pagination will be supplied.- Returns:
- a new instance of
Pageablewith forward keyset pagination. This method never returnsnull. - Throws:
IllegalArgumentException- if no keyset values are provided.
-
beforeKeysetCursor
Requests
keyset paginationin the reverse direction, starting after the specified keyset values.- Parameters:
keysetCursor- cursor with keyset values, the order and number of which must match theOrderByannotations,Sortparameters, orOrderByname pattern of the repository method to which this pagination will be supplied.- Returns:
- a new instance of
Pageablewith reverse keyset pagination. This method never returnsnull. - Throws:
IllegalArgumentException- if no keyset values are provided.
-
equals
Compares with another instance to determine if both represent the same pagination information. -
cursor
Pageable.Cursor cursor()Returns the keyset values which are the starting point for keyset pagination.- Returns:
- the keyset values;
nullif using offset pagination.
-
mode
Pageable.Mode mode()Returns the type of pagination.- Returns:
- the type of pagination.
-
page
long page()Returns the page to be returned.- Returns:
- the page to be returned.
-
size
int size()Returns the requested size of each page- Returns:
- the requested size of each page
-
sorts
Return the order collection if it was specified on thisPageable, otherwise an empty list.- Returns:
- the order collection; will never be null.
-
next
Pageable next()Returns the
Pageablerequesting the next page if using offset pagination.If using keyset pagination, traversal of pages must only be done via the
KeysetAwareSlice.nextPageable(),KeysetAwareSlice.previousPageable(), orkeyset cursor, not with this method.- Returns:
- The next pageable.
- Throws:
UnsupportedOperationException- if thisPageablehas aCursor.
-
page
Creates a new
Pageableinstance representing the same pagination information, except with the specified page number.- Parameters:
pageNumber- The page number- Returns:
- a new instance of
Pageable. This method never returnsnull.
-
size
Creates a new
Pageableinstance representing the same pagination information, except with the specified maximum page size.- Parameters:
maxPageSize- the number of query results in a full page.- Returns:
- a new instance of
Pageable. This method never returnsnull.
-
sortBy
Creates a new
Pageableinstance representing the same pagination information, except using the specified sort criteria. The order of precedence for sort criteria is that of any statically specified sort criteria (from theOrderBykeyword,OrderByannotation orORDER BYclause of a theQueryannotation) followed by the order of theIterablethat is supplied to this method.- Parameters:
sorts- sort criteria to use.- Returns:
- a new instance of
Pageable. This method never returnsnull.
-
sortBy
Creates a new
Pageableinstance representing the same pagination information, except using the specified sort criteria. The order of precedence for sort criteria is that of any statically specified sort criteria (from theOrderBykeyword,OrderByannotation orORDER BYclause of a theQueryannotation) followed by the order in which theSortparameters to this method are listed.- Parameters:
sorts- sort criteria to use. This method can be invoked without parameters to request aPageablethat does not specify sort criteria.- Returns:
- a new instance of
Pageable. This method never returnsnull.
-