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
Pageable
parameters are supplied to the same method. Pageable
andLimit
parameters are supplied to the same method.- a
Pageable
parameter is supplied in combination with theFirst
keyword. - a
Pageable
parameter is supplied and separateSort
parameters are also supplied to the same method. - the database is incapable of ordering with the requested sort criteria.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Represents keyset values, which can be a starting point for requesting a next or previous page.static enum
The type of pagination, which can be offset pagination or keyset cursor pagination which includes a direction. -
Method Summary
Modifier and TypeMethodDescriptionafterKeyset
(Object... keyset) Requestskeyset pagination
in the forward direction, starting after the specified keyset values.afterKeysetCursor
(Pageable.Cursor keysetCursor) Requestskeyset pagination
in the forward direction, starting after the specified keyset values.beforeKeyset
(Object... keyset) Requestskeyset pagination
in the reverse direction, starting after the specified keyset values.beforeKeysetCursor
(Pageable.Cursor keysetCursor) Requestskeyset pagination
in the reverse direction, starting after the specified keyset values.cursor()
Returns the keyset values which are the starting point for keyset pagination.boolean
Compares with another instance to determine if both represent the same pagination information.mode()
Returns the type of pagination.next()
Returns thePageable
requesting the next page if using offset pagination.static Pageable
ofPage
(long pageNumber) Creates a newPageable
with the given page number and with a default size of 10.static Pageable
ofSize
(int maxPageSize) Creates a newPageable
for requesting pages of the specified size, starting with the first page number, which is 1.long
page()
Returns the page to be returned.page
(long pageNumber) Creates a newPageable
instance representing the same pagination information, except with the specified page number.int
size()
Returns the requested size of each pagesize
(int maxPageSize) Creates a newPageable
instance representing the same pagination information, except with the specified maximum page size.Creates a newPageable
instance representing the same pagination information, except using the specified sort criteria.Creates a newPageable
instance 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 newPageable
with 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 newPageable
for 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 pagination
in the forward direction, starting after the specified keyset values.- Parameters:
keyset
- keyset values, the order and number of which must match theOrderBy
annotations,Sort
parameters, orOrderBy
name pattern of the repository method to which this pagination will be supplied.- Returns:
- a new instance of
Pageable
with forward keyset pagination. This method never returnsnull
. - Throws:
IllegalArgumentException
- if no keyset values are provided.
-
beforeKeyset
Requests
keyset pagination
in the reverse direction, starting after the specified keyset values.- Parameters:
keyset
- keyset values, the order and number of which must match theOrderBy
annotations,Sort
parameters, orOrderBy
name pattern of the repository method to which this pagination will be supplied.- Returns:
- a new instance of
Pageable
with reverse keyset pagination. This method never returnsnull
. - Throws:
IllegalArgumentException
- if no keyset values are provided.
-
afterKeysetCursor
Requests
keyset pagination
in the forward direction, starting after the specified keyset values.- Parameters:
keysetCursor
- cursor with keyset values, the order and number of which must match theOrderBy
annotations,Sort
parameters, orOrderBy
name pattern of the repository method to which this pagination will be supplied.- Returns:
- a new instance of
Pageable
with forward keyset pagination. This method never returnsnull
. - Throws:
IllegalArgumentException
- if no keyset values are provided.
-
beforeKeysetCursor
Requests
keyset pagination
in the reverse direction, starting after the specified keyset values.- Parameters:
keysetCursor
- cursor with keyset values, the order and number of which must match theOrderBy
annotations,Sort
parameters, orOrderBy
name pattern of the repository method to which this pagination will be supplied.- Returns:
- a new instance of
Pageable
with 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;
null
if 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
Pageable
requesting 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 thisPageable
has aCursor
.
-
page
Creates a new
Pageable
instance 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
Pageable
instance 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
Pageable
instance 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 theOrderBy
keyword,OrderBy
annotation orORDER BY
clause of a theQuery
annotation) followed by the order of theIterable
that 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
Pageable
instance 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 theOrderBy
keyword,OrderBy
annotation orORDER BY
clause of a theQuery
annotation) followed by the order in which theSort
parameters to this method are listed.- Parameters:
sorts
- sort criteria to use. This method can be invoked without parameters to request aPageable
that does not specify sort criteria.- Returns:
- a new instance of
Pageable
. This method never returnsnull
.
-