Class Where
Provides a convenient way to build Where clause, reactive-style. Supports where clause nesting.
Where clauses can be chained using either and(Where)
and or(Where)
, depending on the desired operator.
Each and(Where)
and or(Where)
have shortcut methods, respectively and(String, String, Object)
and or(String, String, Object)
, to avoid creating new unnecessary Where clauses.
Nesting is supported by simply chaining another Where clause.
( new Where( "col1", "=", "val1" ) ).or( ( new Where( "col2", "{@literal <}", "val2" ) ).and( "col3", "{@literal >=}", "val3" ) ).toString();
will generate : (col1 = 'val1' OR ((col2 {@literal <} 'val2') AND (col3 {@literal >=} 'val3')))
Where supports Reactive-style programming to create more compact code.
As such,
Where o = new Where( "col1", "=", "val1" ); o.and( "col2", "<", "val2" ); String v = o.toString();
can be written
String v = ( new Where( "col1", "=", "val1" ) ).and( "col2", "<", "val2" ).toString();
Nesting is still supported when using reactive-style programming.
- Author:
- Virgile, Nicolas, Louis-Félix
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionChain a new where clause using the boolean AND.and
(String column, String comparator, SQLRequest subquery) Chain a new where clause using the boolean AND, using the provided values and subquery.Chain a new where clause using the boolean AND, using the provided values.Gets the parameters to use in the prepared statement.Object[]
Gets the parameters to use in the prepared statement.Chain a new where clause using the boolean OR.or
(String column, String comparator, SQLRequest subquery) Chain a new where clause using the boolean OR, using the provided values and subquery.Chain a new where clause using the boolean OR, using the provided values.toString()
Gets the corresponding SQL Where clause, for use in a prepared statement.
-
Constructor Details
-
Where
public Where()Creates a new chainable, empty Where clause. -
Where
Creates a new chainable Where clause.- Parameters:
column
- Column to targetcomparator
- Comparator to usevalue
- Comparison value
-
Where
Creates a new chainable Where clause with a subquery.- Parameters:
column
- Column to targetcomparator
- Comparator to usesubquery
- Sub query
-
-
Method Details
-
and
Chain a new where clause using the boolean AND.- Parameters:
condition
- Where clause to chain- Returns:
- This Where clause helper
-
or
Chain a new where clause using the boolean OR.- Parameters:
condition
- Where clause to chain- Returns:
- This Where clause helper
-
and
Chain a new where clause using the boolean AND, using the provided values.- Parameters:
column
- Column to targetcomparator
- Comparator to usevalue
- Comparison value- Returns:
- This Where clause helper
-
or
Chain a new where clause using the boolean OR, using the provided values.- Parameters:
column
- Column to targetcomparator
- Comparator to usevalue
- Comparison value- Returns:
- This Where clause helper
-
and
Chain a new where clause using the boolean AND, using the provided values and subquery.- Parameters:
column
- Column to targetcomparator
- Comparator to usesubquery
- Sub query- Returns:
- This Where clause helper
-
or
Chain a new where clause using the boolean OR, using the provided values and subquery.- Parameters:
column
- Column to targetcomparator
- Comparator to usesubquery
- Sub query- Returns:
- This Where clause helper
-
toString
Gets the corresponding SQL Where clause, for use in a prepared statement. -
getParameters
Gets the parameters to use in the prepared statement.- Returns:
- Statement parameters
-
getParametersArray
Gets the parameters to use in the prepared statement.- Returns:
- Statement parameters
-