Package NTNU.IDATT1002.repository
Class Sort
java.lang.Object
NTNU.IDATT1002.repository.Sort
public class Sort
extends java.lang.Object
Represents a part of a sorted
PageRequest
.
Composes an Order
wrapped in an Optional
which can be used when building an ordered CriteriaQuery
.
If no sorting is specified or required, empty()
should be used.
This returns a Optional.empty()
when building queries.
The default order is ascending.-
Method Summary
Modifier and Type Method Description Sort
ascending()
Return aSort
in ascending order.static Sort
by(java.lang.String field)
Return aSort
by given field.Sort
descending()
Return aSort
in descending order.static Sort
empty()
Return aSort
which does not sort by any field.<T> java.util.Optional<javax.persistence.criteria.Order>
getOrder(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.Root<T> from)
Compose and return thisSort
as anOrder
wrapped in anOptional
which can be used when building queries withCriteriaQuery
.
-
Method Details
-
by
Return aSort
by given field. -
descending
Return aSort
in descending order. -
ascending
Return aSort
in ascending order. -
empty
Return aSort
which does not sort by any field. -
getOrder
public <T> java.util.Optional<javax.persistence.criteria.Order> getOrder(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.Root<T> from)Compose and return thisSort
as anOrder
wrapped in anOptional
which can be used when building queries withCriteriaQuery
. ReturnOptional.empty()
if thisSort
is empty,- Parameters:
criteriaBuilder
- theCriteriaBuilder
to build theOrder
fromfrom
- theRoot
specifying which table the query acts on.
-