Package org.kiwiproject.jdbc
Enum Class SqlOrder
- All Implemented Interfaces:
Serializable,Comparable<SqlOrder>,Constable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic SqlOrderGiven 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.toSql()Return a string that can be used directly in a SQLORDER BYclause.static SqlOrderReturns the enum constant of this class with the specified name.static SqlOrder[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
ASC
-
DESC
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified nameNullPointerException- if the argument is null
-
from
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
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
Return a string that can be used directly in a SQLORDER BYclause.- Returns:
- a string that can be used in a SQL query
-