Class Sort

java.lang.Object
io.quarkus.panache.common.Sort

public class Sort extends Object

Utility class to build and represent SQL sorting specifications. A Sort instance represents a list of columns to sort on, each with a direction to use for sorting.

Usage:

 Sort sort = Sort.by("name").and("age", Direction.Descending);
 Sort sort2 = Sort.ascending("name", "age");
 Sort sort3 = Sort.descending("name", "age");
 
Author:
Stéphane Épardaud
See Also:
  • Method Details

    • by

      public static Sort by(String column)
      Sort by the given column, in ascending order.
      Parameters:
      column - the column to sort on, in ascending order.
      Returns:
      a new Sort instance which sorts on the given column in ascending order.
      See Also:
    • by

      public static Sort by(String column, Sort.Direction direction)
      Sort by the given column, in the given order.
      Parameters:
      column - the column to sort on, in the given order.
      direction - the direction to sort on.
      Returns:
      a new Sort instance which sorts on the given column in the given order.
      See Also:
    • by

      public static Sort by(String column, Sort.NullPrecedence nullPrecedence)
      Sort by the given column, in the given order and in the given null precedence.
      Parameters:
      column - the column to sort on, in the given order.
      nullPrecedence - the null precedence to use.
      Returns:
      a new Sort instance which sorts on the given column in the given order and null precedence.
      See Also:
    • by

      public static Sort by(String column, Sort.Direction direction, Sort.NullPrecedence nullPrecedence)
      Sort by the given column, in the given order and in the given null precedence.
      Parameters:
      column - the column to sort on, in the given order.
      direction - the direction to sort on.
      nullPrecedence - the null precedence to use.
      Returns:
      a new Sort instance which sorts on the given column in the given order and null precedence.
      See Also:
    • by

      public static Sort by(String... columns)
      Sort by the given columns, in ascending order. Equivalent to ascending(String...).
      Parameters:
      columns - the columns to sort on, in ascending order.
      Returns:
      a new Sort instance which sorts on the given columns in ascending order.
      See Also:
    • ascending

      public static Sort ascending(String... columns)
      Sort by the given columns, in ascending order. Equivalent to by(String...).
      Parameters:
      columns - the columns to sort on, in ascending order.
      Returns:
      a new Sort instance which sorts on the given columns in ascending order.
      See Also:
    • descending

      public static Sort descending(String... columns)
      Sort by the given columns, in descending order.
      Parameters:
      columns - the columns to sort on, in descending order.
      Returns:
      a new Sort instance which sorts on the given columns in descending order.
      See Also:
    • descending

      public Sort descending()
      Sets the order to descending for all current sort columns.
      Returns:
      this instance, modified.
      See Also:
    • ascending

      public Sort ascending()
      Sets the order to ascending for all current sort columns.
      Returns:
      this instance, modified.
      See Also:
    • direction

      public Sort direction(Sort.Direction direction)
      Sets the order to all current sort columns.
      Parameters:
      direction - the direction to use for all current sort columns.
      Returns:
      this instance, modified.
      See Also:
    • and

      public Sort and(String name)
      Adds a sort column, in ascending order.
      Parameters:
      name - the new column to sort on, in ascending order.
      Returns:
      this instance, modified.
      See Also:
    • and

      public Sort and(String name, Sort.Direction direction)
      Adds a sort column, in the given order.
      Parameters:
      name - the new column to sort on, in the given order.
      direction - the direction to sort on.
      Returns:
      this instance, modified.
      See Also:
    • and

      public Sort and(String name, Sort.NullPrecedence nullPrecedence)
      Adds a sort column, in the given null precedence.
      Parameters:
      name - the new column to sort on, in the given null precedence.
      nullPrecedence - the null precedence to use.
      Returns:
      this instance, modified.
      See Also:
    • and

      public Sort and(String name, Sort.Direction direction, Sort.NullPrecedence nullPrecedence)
      Adds a sort column, in the given order and null precedence.
      Parameters:
      name - the new column to sort on, in the given order and null precedence.
      direction - the direction to sort on.
      nullPrecedence - the null precedence to use.
      Returns:
      this instance, modified.
      See Also:
    • getColumns

      public List<Sort.Column> getColumns()
      Get the sort columns
      Returns:
      the sort columns
    • empty

      public static Sort empty()
      Creates an Empty Sort instance. Equivalent to #by().
      Returns:
      a new empty Sort instance
      See Also: