Record Class Limit
- Record Components:
maxResults
- maximum number of results for a query.startAt
- starting position for query results (1 is the first result).
Limits the number of results of a single invocation of a repository find method to a maximum amount or to within a positional range.
Limit
is optionally specified as a parameter to a
repository method in one of the parameter positions after the
query parameters. For example,
@Query("SELECT o FROM Products o WHERE o.weight <= ?1 AND o.width * o.length * o.height <= ?2 ORDER BY o.price DESC") Product[] freeShippingEligible(float maxWeight, float maxVolume, Limit limit); ... mostExpensive50 = products.freeShippingEligible(6.0f, 360.0f, Limit.of(50)); ... secondMostExpensive50 = products.freeShippingEligible(6.0f, 360.0f, Limit.range(51, 100));
A repository method will fail if
- multiple
Limit
parameters are supplied to the same method. Limit
andPageable
parameters are supplied to the same method.- a
Limit
parameter is supplied 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...By
or@Query
method; will never be null. - 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...By
or@Query
method; will never be null. - Throws:
IllegalArgumentException
- ifstartAt
is less than 1 orendAt
is less thanstartAt
, or the range fromstartAt
toendAt
exceedsInteger.MAX_VALUE
.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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 '=='.
-