Specifies a limit on the number of results retrieved by a repository method. The results of a single invocation of a repository method may be limited to a given maximum number of results or to a given positioned range defined in terms of an offset and maximum number of results.
A query method of a repository may have a parameter of type
Limit if its return type indicates that it may return multiple
entities. The parameter of type Limit must occur after the
method parameters representing regular parameters of the query itself.
For example,
Product[] findByNameLike(String namePattern, Limit limit, Sort<?>... sorts);
...
mostExpensive50 = products.findByNameLike(pattern, Limit.of(50), Sort.desc("price"));
...
secondMostExpensive50 = products.findByNameLike(pattern, Limit.range(51, 100), Sort.desc("price"));
A repository method may not be declared with:
Limit,Limit and a parameter of type
PageRequest, orLimit in combination with the
First keyword.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | |
| private final int | maxResults
Record Component accessed by maxResults(). maximum number of results for a query. |
| private final long |
| Access | Constructor and Description |
|---|---|
| public | Limit(int
maximum number of results for a query. maxResults, long starting position for query results (1 is the first result). startAt)Limits query results. |
| Modifier and Type | Method and Description |
|---|---|
| public final boolean | equals(Object
the reference object with which to compare. o)Implements abstract java. Indicates whether some other object is "equal to" this one. |
| public final int | |
| public int | Returns: maximum number of results for a query.Record Component getter of maxResults. Maximum number of results that can be returned for a single invocation of the repository method. Record Component maximum number of results for a query. |
| public static Limit | Returns: limit that can be supplied to a find method or@Query method that performs a find operation; will never be null.maximum number of results. maxResults)Create a limit that caps the number of results at the specified maximum, starting from the first result. |
| public static Limit | Returns: limit that can be supplied to a find method or or a@Query method that performs a find operation; will never be null.position at which to start including results.
The first query result is position 1. startAt, long position after which to cease including results. endAt)Create a limit that restricts the results to a range,
beginning with the |
| public long | |
| public final String | toString()
Implements abstract java. Returns a string representation of the record. |
| DEFAULT_START_AT | back to summary |
|---|---|
| private static final long DEFAULT_START_AT | |
| maxResults | back to summary |
|---|---|
| private final int maxResults Record Component accessed by maxResults(). maximum number of results for a query. | |
| startAt | back to summary |
|---|---|
| private final long startAt Record Component accessed by startAt(). starting position for query results (1 is the first result). | |
| Limit | back to summary |
|---|---|
| public Limit(int maxResults, long startAt) Limits query results. For more descriptive code, use:
| |
| equals | back to summary |
|---|---|
| public final boolean equals(Object o) Implements abstract java. Doc from java. Indicates whether some other object is "equal to" this one. In addition
to the general contract of
R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
| |
| hashCode | back to summary |
|---|---|
| public final int hashCode() Implements abstract java. Doc from java. Returns a hash code value for the record.
Obeys the general contract of
| |
| maxResults | back to summary |
|---|---|
| public int maxResults() Record Component getter of maxResults. Maximum number of results that can be returned for a single invocation of the repository method.
| |
| of | back to summary |
|---|---|
| public static Limit of(int maxResults) Create a limit that caps the number of results at the specified maximum, starting from the first result.
| |
| range | back to summary |
|---|---|
| public static Limit range(long startAt, long endAt) Create a limit that restricts the results to a range,
beginning with the
| |
| startAt | back to summary |
|---|---|
| public long startAt() Record Component getter of startAt. Offset at which to start when returning query results.
The first query result is position
| |
| toString | back to summary |
|---|---|
| public final String toString() Implements abstract java. Doc from java. Returns a string representation of the record.
In accordance with the general contract of In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.
| |