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
Limitparameters are supplied to the same method. LimitandPageableparameters are supplied to the same method.- a
Limitparameter is supplied in combination with theFirstkeyword.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intMaximum number of results that can be returned for a single invocation of the repository method.static Limitof(int maxResults) Create a limit that caps the number of results at the specified maximum, starting from the first result.static Limitrange(long startAt, long endAt) Create a limit that restricts the results to a range, beginning with thestartAtposition and ending after theendAtposition or the position of the final result, whichever comes first.longstartAt()Offset at which to start when returning query results.final StringtoString()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...Byor@Querymethod; 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
startAtposition and ending after theendAtposition 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...Byor@Querymethod; will never be null. - Throws:
IllegalArgumentException- ifstartAtis less than 1 orendAtis less thanstartAt, or the range fromstartAttoendAtexceedsInteger.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 '=='.
-