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 a Sort in ascending order.
    static Sort by​(java.lang.String field)
    Return a Sort by given field.
    Sort descending()
    Return a Sort in descending order.
    static Sort empty()
    Return a Sort 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 this Sort as an Order wrapped in an Optional which can be used when building queries with CriteriaQuery.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • by

      public static Sort by​(java.lang.String field)
      Return a Sort by given field.
    • descending

      public Sort descending()
      Return a Sort in descending order.
    • ascending

      public Sort ascending()
      Return a Sort in ascending order.
    • empty

      public static Sort empty()
      Return a Sort 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 this Sort as an Order wrapped in an Optional which can be used when building queries with CriteriaQuery. Return Optional.empty() if this Sort is empty,
      Parameters:
      criteriaBuilder - the CriteriaBuilder to build the Order from
      from - the Root specifying which table the query acts on.