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
Sortparameter is specified in combination with aPageableparameter withPageable.sorts(). - the database is incapable of ordering with the requested sort criteria.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SortCreate aSortinstance with ascending directionDirection.ASCthat does not request case insensitive ordering.static SortascIgnoreCase(String property) Create aSortinstance with ascending directionDirection.ASCand case insensitive ordering.static SortCreate aSortinstance with descending directionDirection.DESCthat does not request case insensitive ordering.static SortdescIgnoreCase(String property) Create aSortinstance with descending directionDirection.DESCand case insensitive ordering.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanIndicates whether or not to request case insensitive ordering from a database with case sensitive collation.booleanIndicates whether to sort the property in ascending order (true) or descending order (false).booleanIndicates whether to sort the property in descending order (true) or ascending order (false).static SortCreate aSortinstanceproperty()Name of the property to order by.final StringtoString()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
ignoreCasevalue.- 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 aSortinstance- Parameters:
property- the property name to order bydirection- the direction in which to order.ignoreCase- whether to request a case insensitive ordering.- Returns:
- an
Sortinstance. Nevernull. - Throws:
NullPointerException- when there is a null parameter
-
asc
Create aSortinstance with ascending directionDirection.ASCthat does not request case insensitive ordering.- Parameters:
property- the property name to order by- Returns:
- a
Sortinstance. Nevernull. - Throws:
NullPointerException- when the property is null
-
ascIgnoreCase
Create aSortinstance with ascending directionDirection.ASCand case insensitive ordering.- Parameters:
property- the property name to order by.- Returns:
- a
Sortinstance. Nevernull. - Throws:
NullPointerException- when the property is null.
-
desc
Create aSortinstance with descending directionDirection.DESCthat does not request case insensitive ordering.- Parameters:
property- the property name to order by- Returns:
- a
Sortinstance. Nevernull. - Throws:
NullPointerException- when the property is null
-
descIgnoreCase
Create aSortinstance with descending directionDirection.DESCand case insensitive ordering.- Parameters:
property- the property name to order by.- Returns:
- a
Sortinstance. 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 '=='.
-