Enum SqlOrder

  • All Implemented Interfaces:
    Serializable, Comparable<SqlOrder>

    public enum SqlOrder
    extends Enum<SqlOrder>
    Simple enum that represents the values for SQL ORDER BY clauses.

    This is useful in building queries, for example when using JDBI and the SQL objects API you might need to add dynamic ordering based on user input but want to ensure no SQL injection attack is possible. So you would accept user input and then use from(String) to get a SqlOrder instance. Then, you could use it in a JDBI SqlQuery annotation as one example.

    • Enum Constant Detail

      • DESC

        public static final SqlOrder DESC
    • Method Detail

      • values

        public static SqlOrder[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (SqlOrder c : SqlOrder.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static SqlOrder valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • from

        public static SqlOrder from​(String value)
        Given a string value, return a SqlOrder, ignoring case and leading/trailing whitespace.
        Parameters:
        value - the value to convert from
        Returns:
        the SqlOrder enum corresponding to the given value
        Throws:
        IllegalArgumentException - if an invalid value is provided that does not map to a SqlOrder enum constant
      • searchWith

        public <T> List<T> searchWith​(Supplier<List<T>> ascSearch,
                                      Supplier<List<T>> descSearch)
        Perform a search in either ascending or descending order using the given Supplier instances. If this instance is ASC then the ascending search is executed, otherwise if DESC the descending search is executed.
        Type Parameters:
        T - the result type
        Parameters:
        ascSearch - the logic to perform an ascending search
        descSearch - the logic to perform a descending search
        Returns:
        a list of results in either ascending or descending order based on this instance
      • toSql

        public String toSql()
        Return a string that can be used directly in a SQL ORDER BY clause.
        Returns:
        a string that can be used in a SQL query