Top Description Fields Constructors Methods
jakarta.data

public final Record Limit

extends Record
Class Inheritance
Record Components
maxResults:int
maximum number of results for a query.
startAt:long
starting position for query results (1 is the first result).
Imports
jakarta.data.page.PageRequest

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:

Field Summary

Modifier and TypeField 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
startAt

Record Component accessed by startAt().

starting position for query results (1 is the first result).

Constructor Summary

AccessConstructor 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.

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public int

Returns:

maximum number of results for a query.
maxResults
()

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.
of
(int
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.
range
(long
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 startAt position and ending after the endAt position or the position of the final result, whichever comes first.

public long

Returns:

offset of the first result.
startAt
()

Record Component getter of startAt.

Offset at which to start when returning query results.

Record Component starting position for query results (1 is the first result).

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

DEFAULT_START_ATback to summary
private static final long DEFAULT_START_AT
maxResultsback to summary
private final int maxResults

Record Component accessed by maxResults().

maximum number of results for a query.

startAtback to summary
private final long startAt

Record Component accessed by startAt().

starting position for query results (1 is the first result).

Constructor Detail

Limitback to summary
public Limit(int maxResults, long startAt)

Limits query results. For more descriptive code, use:

Parameters
maxResults:int

maximum number of results for a query.

startAt:long

starting position for query results (1 is the first result).

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

maxResultsback 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.

Record Component
maximum number of results for a query.
Returns:int

maximum number of results for a query.

ofback 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.

Parameters
maxResults:int

maximum number of results.

Returns:Limit

limit that can be supplied to a find method or @Query method that performs a find operation; will never be null.

Exceptions
IllegalArgumentException:
if maxResults is less than 1.
rangeback to summary
public static Limit range(long startAt, long endAt)

Create a limit that restricts the results to a range, beginning with the startAt position and ending after the endAt position or the position of the final result, whichever comes first.

Parameters
startAt:long

position at which to start including results. The first query result is position 1.

endAt:long

position after which to cease including results.

Returns:Limit

limit that can be supplied to a find method or or a @Query method that performs a find operation; will never be null.

Exceptions
IllegalArgumentException:
if startAt is less than 1 or endAt is less than startAt, or the range from startAt to endAt exceeds Integer#MAX_VALUE.
startAtback 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 1.

Record Component
starting position for query results (1 is the first result).
Returns:long

offset of the first result.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

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.

Returns:String

a string representation of the object.