- Record Components:
maxResults
- maximum number of results for a query.startAt
- starting position for query results (1 is the first result).
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:
- more than one parameter of type
Limit
, - a parameter of type
Limit
and a parameter of typePageRequest
, or - a parameter of type
Limit
in combination with theFirst
keyword.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.int
Maximum number of results that can be returned for a single invocation of the repository method.static Limit
of
(int maxResults) Create a limit that caps the number of results at the specified maximum, starting from the first result.static Limit
range
(long startAt, long endAt) Create a limit that restricts the results to a range, beginning with thestartAt
position and ending after theendAt
position or the position of the final result, whichever comes first.long
startAt()
Offset at which to start when returning query results.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
Limit
public Limit(int maxResults, long startAt) Limits query results. For more descriptive code, use:
Limit.of(maxResults)
to cap the number of results.Limit.range(startAt, endAt)
to limit to a range.
- Parameters:
maxResults
- maximum number of results for a query.startAt
- starting position for query results (1 is the first result).
-
-
Method Details
-
maxResults
public int maxResults()Maximum number of results that can be returned for a single invocation of the repository method.
- Returns:
- maximum number of results for a query.
-
startAt
public long startAt()Offset at which to start when returning query results. The first query result is position
1
.- Returns:
- offset of the first result.
-
of
Create a limit that caps the number of results at the specified maximum, starting from the first result.
- Parameters:
maxResults
- maximum number of results.- Returns:
- limit that can be supplied to a find method
or
@Query
method that performs a find operation; will never benull
. - Throws:
IllegalArgumentException
- if maxResults is less than 1.
-
range
Create a limit that restricts the results to a range, beginning with the
startAt
position and ending after theendAt
position or the position of the final result, whichever comes first.- Parameters:
startAt
- position at which to start including results. The first query result is position 1.endAt
- position after which to cease including results.- Returns:
- limit that can be supplied to a find method or
or a
@Query
method that performs a find operation; will never benull
. - Throws:
IllegalArgumentException
- ifstartAt
is less than 1 orendAt
is less thanstartAt
, or the range fromstartAt
toendAt
exceedsInteger.MAX_VALUE
.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
-