java.lang.Object
ece.ing3.java.projet.database.sql.clauses.Where

public class Where extends Object
Where clause helper.

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 Details

    • Where

      public Where()
      Creates a new chainable, empty Where clause.
    • Where

      public Where(String column, String comparator, Object value)
      Creates a new chainable Where clause.
      Parameters:
      column - Column to target
      comparator - Comparator to use
      value - Comparison value
    • Where

      public Where(String column, String comparator, SQLRequest subquery)
      Creates a new chainable Where clause with a subquery.
      Parameters:
      column - Column to target
      comparator - Comparator to use
      subquery - Sub query
  • Method Details

    • and

      public Where and(Where condition)
      Chain a new where clause using the boolean AND.
      Parameters:
      condition - Where clause to chain
      Returns:
      This Where clause helper
    • or

      public Where or(Where condition)
      Chain a new where clause using the boolean OR.
      Parameters:
      condition - Where clause to chain
      Returns:
      This Where clause helper
    • and

      public Where and(String column, String comparator, Object value)
      Chain a new where clause using the boolean AND, using the provided values.
      Parameters:
      column - Column to target
      comparator - Comparator to use
      value - Comparison value
      Returns:
      This Where clause helper
    • or

      public Where or(String column, String comparator, Object value)
      Chain a new where clause using the boolean OR, using the provided values.
      Parameters:
      column - Column to target
      comparator - Comparator to use
      value - Comparison value
      Returns:
      This Where clause helper
    • and

      public Where and(String column, String comparator, SQLRequest subquery)
      Chain a new where clause using the boolean AND, using the provided values and subquery.
      Parameters:
      column - Column to target
      comparator - Comparator to use
      subquery - Sub query
      Returns:
      This Where clause helper
    • or

      public Where or(String column, String comparator, SQLRequest subquery)
      Chain a new where clause using the boolean OR, using the provided values and subquery.
      Parameters:
      column - Column to target
      comparator - Comparator to use
      subquery - Sub query
      Returns:
      This Where clause helper
    • toString

      public String toString()
      Gets the corresponding SQL Where clause, for use in a prepared statement.
      Overrides:
      toString in class Object
      Returns:
      SQL Order By clause
    • getParameters

      public List<Object> getParameters()
      Gets the parameters to use in the prepared statement.
      Returns:
      Statement parameters
    • getParametersArray

      public Object[] getParametersArray()
      Gets the parameters to use in the prepared statement.
      Returns:
      Statement parameters