Class JpaSort

java.lang.Object
org.springframework.data.domain.Sort
org.springframework.data.jpa.domain.JpaSort
All Implemented Interfaces:
Serializable, Iterable<org.springframework.data.domain.Sort.Order>, Supplier<Stream<org.springframework.data.domain.Sort.Order>>, org.springframework.data.util.Streamable<org.springframework.data.domain.Sort.Order>

public class JpaSort extends org.springframework.data.domain.Sort
Sort option for queries that wraps JPA meta-model Attributes for sorting.
Author:
Thomas Darimont, Oliver Gierke, Christoph Strobl, David Madden
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Custom Sort.Order that keeps a flag to indicate unsafe property handling, i.e. the String provided is not necessarily a property but can be an arbitrary expression piped into the query execution.
    static class 
    Value object to abstract a collection of Attributes.

    Nested classes/interfaces inherited from class org.springframework.data.domain.Sort

    org.springframework.data.domain.Sort.Direction, org.springframework.data.domain.Sort.NullHandling, org.springframework.data.domain.Sort.Order, org.springframework.data.domain.Sort.TypedSort<T extends Object>
  • Field Summary

    Fields inherited from class org.springframework.data.domain.Sort

    DEFAULT_DIRECTION
  • Constructor Summary

    Constructors
    Constructor
    Description
    JpaSort(jakarta.persistence.metamodel.Attribute<?,?>... attributes)
    Deprecated.
    since 2.3, use of(Attribute...) instead.
    JpaSort(org.springframework.data.domain.Sort.Direction direction, jakarta.persistence.metamodel.Attribute<?,?>... attributes)
    Deprecated.
    since 2.3, use of(Direction, Attribute...) instead.
    JpaSort(org.springframework.data.domain.Sort.Direction direction, JpaSort.Path<?,?>... paths)
    Deprecated.
    since 2.3, use of(Direction, Path...) instead.
    JpaSort(JpaSort.Path<?,?>... paths)
    Deprecated.
    since 2.3, use {@link JpaSort#of(Path...))} instead.
  • Method Summary

    Modifier and Type
    Method
    Description
    and(org.springframework.data.domain.Sort.Direction direction, jakarta.persistence.metamodel.Attribute<?,?>... attributes)
    Returns a new JpaSort with the given sorting criteria added to the current one.
    and(org.springframework.data.domain.Sort.Direction direction, JpaSort.Path<?,?>... paths)
    Returns a new JpaSort with the given sorting criteria added to the current one.
    andUnsafe(org.springframework.data.domain.Sort.Direction direction, String... properties)
    Returns a new JpaSort with the given sorting criteria added to the current one.
    static JpaSort
    of(jakarta.persistence.metamodel.Attribute<?,?>... attributes)
    Creates a new JpaSort for the given attributes with the default sort direction.
    static JpaSort
    of(org.springframework.data.domain.Sort.Direction direction, jakarta.persistence.metamodel.Attribute<?,?>... attributes)
    Creates a new JpaSort for the given direction and attributes.
    static JpaSort
    of(org.springframework.data.domain.Sort.Direction direction, JpaSort.Path<?,?>... paths)
    Creates a new JpaSort for the given direction and JpaSort.Paths.
    static JpaSort
    of(JpaSort.Path<?,?>... paths)
    Creates a new JpaSort instance with the given JpaSort.Paths.
    static <A extends jakarta.persistence.metamodel.Attribute<T, S>, T, S>
    JpaSort.Path<T,S>
    path(A attribute)
    Creates a new JpaSort.Path for the given Attribute.
    static <P extends jakarta.persistence.metamodel.PluralAttribute<T, ?, S>, T, S>
    JpaSort.Path<T,S>
    path(P attribute)
    Creates a new JpaSort.Path for the given PluralAttribute.
    static JpaSort
    unsafe(String... properties)
    Creates new unsafe JpaSort based on given properties.
    static JpaSort
    unsafe(org.springframework.data.domain.Sort.Direction direction, String... properties)
    Creates new unsafe JpaSort based on given Sort.Direction and properties.
    static JpaSort
    unsafe(org.springframework.data.domain.Sort.Direction direction, List<String> properties)
    Creates new unsafe JpaSort based on given Sort.Direction and properties.

    Methods inherited from class org.springframework.data.domain.Sort

    and, ascending, by, by, by, by, descending, doReverse, equals, getOrderFor, hashCode, isEmpty, isSorted, isUnsorted, iterator, reverse, sort, toString, unsorted

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface org.springframework.data.util.Streamable

    and, and, and, and, filter, flatMap, get, map, stream, toList, toSet
  • Constructor Details

    • JpaSort

      @Deprecated public JpaSort(jakarta.persistence.metamodel.Attribute<?,?>... attributes)
      Deprecated.
      since 2.3, use of(Attribute...) instead.
      Creates a new JpaSort for the given attributes with the default sort direction.
      Parameters:
      attributes - must not be null or empty.
    • JpaSort

      @Deprecated public JpaSort(JpaSort.Path<?,?>... paths)
      Deprecated.
      since 2.3, use {@link JpaSort#of(Path...))} instead.
      Creates a new JpaSort instance with the given JpaSort.Paths.
      Parameters:
      paths - must not be null or empty.
    • JpaSort

      @Deprecated public JpaSort(org.springframework.data.domain.Sort.Direction direction, jakarta.persistence.metamodel.Attribute<?,?>... attributes)
      Deprecated.
      since 2.3, use of(Direction, Attribute...) instead.
      Creates a new JpaSort for the given direction and attributes.
      Parameters:
      direction - the sorting direction.
      attributes - must not be null or empty.
    • JpaSort

      @Deprecated public JpaSort(org.springframework.data.domain.Sort.Direction direction, JpaSort.Path<?,?>... paths)
      Deprecated.
      since 2.3, use of(Direction, Path...) instead.
      Creates a new JpaSort for the given direction and JpaSort.Paths.
      Parameters:
      direction - the sorting direction.
      paths - must not be null or empty.
  • Method Details

    • of

      public static JpaSort of(jakarta.persistence.metamodel.Attribute<?,?>... attributes)
      Creates a new JpaSort for the given attributes with the default sort direction.
      Parameters:
      attributes - must not be null or empty.
    • of

      public static JpaSort of(JpaSort.Path<?,?>... paths)
      Creates a new JpaSort instance with the given JpaSort.Paths.
      Parameters:
      paths - must not be null or empty.
    • of

      public static JpaSort of(org.springframework.data.domain.Sort.Direction direction, jakarta.persistence.metamodel.Attribute<?,?>... attributes)
      Creates a new JpaSort for the given direction and attributes.
      Parameters:
      direction - the sorting direction.
      attributes - must not be null or empty.
    • of

      public static JpaSort of(org.springframework.data.domain.Sort.Direction direction, JpaSort.Path<?,?>... paths)
      Creates a new JpaSort for the given direction and JpaSort.Paths.
      Parameters:
      direction - the sorting direction.
      paths - must not be null or empty.
    • and

      public JpaSort and(@Nullable org.springframework.data.domain.Sort.Direction direction, jakarta.persistence.metamodel.Attribute<?,?>... attributes)
      Returns a new JpaSort with the given sorting criteria added to the current one.
      Parameters:
      direction - can be null.
      attributes - must not be null.
      Returns:
    • and

      public JpaSort and(@Nullable org.springframework.data.domain.Sort.Direction direction, JpaSort.Path<?,?>... paths)
      Returns a new JpaSort with the given sorting criteria added to the current one.
      Parameters:
      direction - can be null.
      paths - must not be null.
      Returns:
    • andUnsafe

      public JpaSort andUnsafe(@Nullable org.springframework.data.domain.Sort.Direction direction, String... properties)
      Returns a new JpaSort with the given sorting criteria added to the current one.
      Parameters:
      direction - can be null.
      properties - must not be null or empty.
      Returns:
    • path

      public static <A extends jakarta.persistence.metamodel.Attribute<T, S>, T, S> JpaSort.Path<T,S> path(A attribute)
      Creates a new JpaSort.Path for the given Attribute.
      Parameters:
      attribute - must not be null.
      Returns:
    • path

      public static <P extends jakarta.persistence.metamodel.PluralAttribute<T, ?, S>, T, S> JpaSort.Path<T,S> path(P attribute)
      Creates a new JpaSort.Path for the given PluralAttribute.
      Parameters:
      attribute - must not be null.
      Returns:
    • unsafe

      public static JpaSort unsafe(String... properties)
      Creates new unsafe JpaSort based on given properties.
      Parameters:
      properties - must not be null or empty.
      Returns:
    • unsafe

      public static JpaSort unsafe(org.springframework.data.domain.Sort.Direction direction, String... properties)
      Creates new unsafe JpaSort based on given Sort.Direction and properties.
      Parameters:
      direction - must not be null.
      properties - must not be null or empty.
      Returns:
    • unsafe

      public static JpaSort unsafe(org.springframework.data.domain.Sort.Direction direction, List<String> properties)
      Creates new unsafe JpaSort based on given Sort.Direction and properties.
      Parameters:
      direction - must not be null.
      properties - must not be null or empty.
      Returns: