Record Class Sort
- Record Components:
property
- name of the property to order by.isAscending
- whether ordering for this property is ascending (true) or descending (false).ignoreCase
- whether or not to request case insensitive ordering from a database with case sensitive collation.
Sort
allows the application to dynamically provide
sort criteria which includes a case sensitivity request,
a Direction
and a property.
Dynamic Sort
criteria can be specified when
requesting a page of results
or can be optionally specified as
parameters to a repository method in any of the positions that are after
the query parameters. You can use Sort...
to allow a variable
number of Sort
criteria. For example,
Employee[] findByYearHired(int yearYired, Limit maxResults, Sort... sortBy); ... highestPaidNewHires = employees.findByYearHired(Year.now(), Limit.of(10), Sort.desc("salary"), Sort.asc("lastName"), Sort.asc("firstName"));
When combined on a method with static sort criteria
(OrderBy
keyword or OrderBy
annotation or
Query
with an ORDER BY
clause), the static
sort criteria is applied first, followed by the dynamic sort criteria
that is defined by Sort
instances in the order listed.
A repository method will fail with a
DataException
or a more specific subclass if
- a
Sort
parameter is specified in combination with aPageable
parameter withPageable.sorts()
. - the database is incapable of ordering with the requested sort criteria.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Sort
Create aSort
instance with ascending directionDirection.ASC
that does not request case insensitive ordering.static Sort
ascIgnoreCase
(String property) Create aSort
instance with ascending directionDirection.ASC
and case insensitive ordering.static Sort
Create aSort
instance with descending directionDirection.DESC
that does not request case insensitive ordering.static Sort
descIgnoreCase
(String property) Create aSort
instance with descending directionDirection.DESC
and case insensitive ordering.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.boolean
Indicates whether or not to request case insensitive ordering from a database with case sensitive collation.boolean
Indicates whether to sort the property in ascending order (true) or descending order (false).boolean
Indicates whether to sort the property in descending order (true) or ascending order (false).static Sort
Create aSort
instanceproperty()
Name of the property to order by.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
Sort
Defines sort criteria for an entity property. For more descriptive code, use:
Sort.asc(propertyName)
for ascending sort on a property.Sort.ascIgnoreCase(propertyName)
for case insensitive ascending sort on a property.Sort.desc(propertyName)
for descending sort on a property.Sort.descIgnoreCase(propertyName)
for case insensitive descending sort on a property.
- Parameters:
property
- name of the property to order by.isAscending
- whether ordering for this property is ascending (true) or descending (false).ignoreCase
- whether or not to request case insensitive ordering from a database with case sensitive collation.
-
-
Method Details
-
property
Name of the property to order by.- Returns:
- The property name to order by; will never be null.
-
ignoreCase
public boolean ignoreCase()Indicates whether or not to request case insensitive ordering from a database with case sensitive collation. A database with case insensitive collation performs case insensitive ordering regardless of the requested
ignoreCase
value.- Returns:
- Returns whether or not to request case insensitive sorting for the property.
-
isAscending
public boolean isAscending()Indicates whether to sort the property in ascending order (true) or descending order (false).- Returns:
- Returns whether sorting for this property shall be ascending.
-
isDescending
public boolean isDescending()Indicates whether to sort the property in descending order (true) or ascending order (false).- Returns:
- Returns whether sorting for this property shall be descending.
-
of
Create aSort
instance- Parameters:
property
- the property name to order bydirection
- the direction in which to order.ignoreCase
- whether to request a case insensitive ordering.- Returns:
- an
Sort
instance. Nevernull
. - Throws:
NullPointerException
- when there is a null parameter
-
asc
Create aSort
instance with ascending directionDirection.ASC
that does not request case insensitive ordering.- Parameters:
property
- the property name to order by- Returns:
- a
Sort
instance. Nevernull
. - Throws:
NullPointerException
- when the property is null
-
ascIgnoreCase
Create aSort
instance with ascending directionDirection.ASC
and case insensitive ordering.- Parameters:
property
- the property name to order by.- Returns:
- a
Sort
instance. Nevernull
. - Throws:
NullPointerException
- when the property is null.
-
desc
Create aSort
instance with descending directionDirection.DESC
that does not request case insensitive ordering.- Parameters:
property
- the property name to order by- Returns:
- a
Sort
instance. Nevernull
. - Throws:
NullPointerException
- when the property is null
-
descIgnoreCase
Create aSort
instance with descending directionDirection.DESC
and case insensitive ordering.- Parameters:
property
- the property name to order by.- Returns:
- a
Sort
instance. Nevernull
. - Throws:
NullPointerException
- when the property is null.
-
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. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with '=='.
-