Package org.kiwiproject.jdbc
Enum SqlOrder
- java.lang.Object
-
- java.lang.Enum<SqlOrder>
-
- org.kiwiproject.jdbc.SqlOrder
-
- All Implemented Interfaces:
Serializable,Comparable<SqlOrder>
public enum SqlOrder extends Enum<SqlOrder>
Simple enum that represents the values for SQLORDER BYclauses.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 aSqlOrderinstance. Then, you could use it in a JDBISqlQueryannotation as one example.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SqlOrderfrom(String value)Given a string value, return aSqlOrder, ignoring case and leading/trailing whitespace.<T> List<T>searchWith(Supplier<List<T>> ascSearch, Supplier<List<T>> descSearch)Perform a search in either ascending or descending order using the givenSupplierinstances.StringtoSql()Return a string that can be used directly in a SQLORDER BYclause.static SqlOrdervalueOf(String name)Returns the enum constant of this type with the specified name.static SqlOrder[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
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 nameNullPointerException- if the argument is null
-
from
public static SqlOrder from(String value)
Given a string value, return aSqlOrder, 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 givenSupplierinstances. If this instance isASCthen the ascending search is executed, otherwise ifDESCthe descending search is executed.- Type Parameters:
T- the result type- Parameters:
ascSearch- the logic to perform an ascending searchdescSearch- 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 SQLORDER BYclause.- Returns:
- a string that can be used in a SQL query
-
-