de.mathema.pride
Class SQLExpression

java.lang.Object
  extended by de.mathema.pride.SQLExpression

public class SQLExpression
extends java.lang.Object

Convenience class for simplified assembly of SQL expressions

Author:
Jan Lessner

Nested Class Summary
static interface SQLExpression.Direction
           
static interface SQLExpression.Operator
           
 
Field Summary
static java.lang.String REVISION_ID
           
 
Constructor Summary
SQLExpression(SQLFormatter formatter)
          Create a new empty SQL expression
SQLExpression(SQLFormatter formatter, java.lang.String expression)
          Create a new SQL expression
SQLExpression(SQLFormatter formatter, java.lang.String expression, java.lang.String orderByExpression)
          Create a new SQL expression
 
Method Summary
 SQLExpression and(SQLExpression rhsExpression)
           
 SQLExpression and(java.lang.String rhsExpression)
           
 SQLExpression and(java.lang.String field, boolean value)
           
 SQLExpression and(java.lang.String field, char value)
           
 SQLExpression and(java.lang.String field, double value)
           
 SQLExpression and(java.lang.String field, float value)
           
 SQLExpression and(java.lang.String field, int value)
           
 SQLExpression and(java.lang.String field, long value)
           
 SQLExpression and(java.lang.String field, java.lang.Object value)
          Returns a new SQLExpression representing the AND concatenation of this object's expression with a field assignment
 SQLExpression and(java.lang.String field, short value)
           
 SQLExpression and(java.lang.String field, java.lang.String operator, boolean value)
           
 SQLExpression and(java.lang.String field, java.lang.String operator, char value)
           
 SQLExpression and(java.lang.String field, java.lang.String operator, double value)
           
 SQLExpression and(java.lang.String field, java.lang.String operator, float value)
           
 SQLExpression and(java.lang.String field, java.lang.String operator, int value)
           
 SQLExpression and(java.lang.String field, java.lang.String operator, long value)
           
 SQLExpression and(java.lang.String field, java.lang.String operator, java.lang.Object value)
          Returns a new SQLExpression representing the AND concatenation of this object's expression and a field operation defined by the passed parameters.
 SQLExpression and(java.lang.String field, java.lang.String operator, short value)
           
protected  SQLExpression append(java.lang.String operation, java.lang.String subExpression)
          Appends a sub-expression to this object's expression
protected  java.lang.String assign(java.lang.String field, java.lang.Object value)
          Returns an SQL assignment expression for the passed field and value
 SQLExpression brace()
          Puts this object's expression in braces
protected  java.lang.String formatOperator(java.lang.String operator, java.lang.Object value)
           
protected  java.lang.String formatValue(java.lang.Object value)
          Format the passed value if there has a formatter been passed in the constructor and if the value is not of type SQLRaw
protected  boolean isEmpty()
          Returns true if the expression, represented by this object is empty, i.e. it is null or an empty string
protected  boolean isEmpty(java.lang.String string)
           
protected  java.lang.String operation(java.lang.String field, java.lang.String operator, java.lang.Object value)
           
 SQLExpression or(SQLExpression rhsExpression)
           
 SQLExpression or(java.lang.String rhsExpression)
           
 SQLExpression or(java.lang.String field, boolean value)
           
 SQLExpression or(java.lang.String field, char value)
           
 SQLExpression or(java.lang.String field, double value)
           
 SQLExpression or(java.lang.String field, float value)
           
 SQLExpression or(java.lang.String field, int value)
           
 SQLExpression or(java.lang.String field, long value)
           
 SQLExpression or(java.lang.String field, java.lang.Object value)
          Returns a new SQLExpression representing the OR concatenation of this object's expression with a field assignment
 SQLExpression or(java.lang.String field, short value)
           
 SQLExpression or(java.lang.String field, java.lang.String operator, boolean value)
           
 SQLExpression or(java.lang.String field, java.lang.String operator, char value)
           
 SQLExpression or(java.lang.String field, java.lang.String operator, double value)
           
 SQLExpression or(java.lang.String field, java.lang.String operator, float value)
           
 SQLExpression or(java.lang.String field, java.lang.String operator, int value)
           
 SQLExpression or(java.lang.String field, java.lang.String operator, long value)
           
 SQLExpression or(java.lang.String field, java.lang.String operator, java.lang.Object value)
          Returns a new SQLExpression representing the OR concatenation of this object's expression and a field operation defined by the passed parameters.
 SQLExpression or(java.lang.String field, java.lang.String operator, short value)
           
 SQLExpression orderBy(java.lang.String orderExpression)
           
 SQLExpression orderBy(java.lang.String orderExpression, java.lang.String direction)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION_ID

public static final java.lang.String REVISION_ID
See Also:
Constant Field Values
Constructor Detail

SQLExpression

public SQLExpression(SQLFormatter formatter)
Create a new empty SQL expression

Parameters:
formatter - A formatter object used to format SQL values. This may e.g. be a Database object.

SQLExpression

public SQLExpression(SQLFormatter formatter,
                     java.lang.String expression)
Create a new SQL expression

Parameters:
formatter - A formatter object úsed to format SQL values This may e.g. be a Database object.
expression - An initial expression

SQLExpression

public SQLExpression(SQLFormatter formatter,
                     java.lang.String expression,
                     java.lang.String orderByExpression)
Create a new SQL expression

Parameters:
formatter - A formatter object úsed to format SQL values This may e.g. be a Database object.
expression - An initial expression
orderByExpression - An initial order by expression
Method Detail

isEmpty

protected boolean isEmpty()
Returns true if the expression, represented by this object is empty, i.e. it is null or an empty string


formatValue

protected java.lang.String formatValue(java.lang.Object value)
Format the passed value if there has a formatter been passed in the constructor and if the value is not of type SQLRaw


formatOperator

protected java.lang.String formatOperator(java.lang.String operator,
                                          java.lang.Object value)

operation

protected java.lang.String operation(java.lang.String field,
                                     java.lang.String operator,
                                     java.lang.Object value)

assign

protected java.lang.String assign(java.lang.String field,
                                  java.lang.Object value)
Returns an SQL assignment expression for the passed field and value


append

protected SQLExpression append(java.lang.String operation,
                               java.lang.String subExpression)
Appends a sub-expression to this object's expression

Parameters:
operation - The appendence operator to use, e.g. AND, OR, ...
subExpression - The sub expression to append
Returns:
a new SQLExpression representing the assembled expression

and

public SQLExpression and(java.lang.String field,
                         java.lang.Object value)
Returns a new SQLExpression representing the AND concatenation of this object's expression with a field assignment

Parameters:
field - The field to assign a value to
value - The value to assign to the specified field. The value will be formatted by a call to formatValue(java.lang.Object).
Returns:
A new SQLExpression

and

public SQLExpression and(java.lang.String field,
                         java.lang.String operator,
                         java.lang.Object value)
Returns a new SQLExpression representing the AND concatenation of this object's expression and a field operation defined by the passed parameters.

Parameters:
field - The field to operate on
operator - The operator to apply. Supported values are listed in sub-interface SQLExpression.Operator.
value - The value to apply. In case of operator SQLExpression.Operator.BETWEEN, the value is supposed to be an array of two values. In case of operator SQLExpression.Operator.IN, the value is supposed to be an array of arbitrary length holding the values to compare the denoted field to.
Returns:
A new SQLExpression

and

public SQLExpression and(java.lang.String field,
                         boolean value)

and

public SQLExpression and(java.lang.String field,
                         java.lang.String operator,
                         boolean value)

and

public SQLExpression and(java.lang.String field,
                         char value)

and

public SQLExpression and(java.lang.String field,
                         java.lang.String operator,
                         char value)

and

public SQLExpression and(java.lang.String field,
                         short value)

and

public SQLExpression and(java.lang.String field,
                         java.lang.String operator,
                         short value)

and

public SQLExpression and(java.lang.String field,
                         int value)

and

public SQLExpression and(java.lang.String field,
                         java.lang.String operator,
                         int value)

and

public SQLExpression and(java.lang.String field,
                         long value)

and

public SQLExpression and(java.lang.String field,
                         java.lang.String operator,
                         long value)

and

public SQLExpression and(java.lang.String field,
                         float value)

and

public SQLExpression and(java.lang.String field,
                         java.lang.String operator,
                         float value)

and

public SQLExpression and(java.lang.String field,
                         double value)

and

public SQLExpression and(java.lang.String field,
                         java.lang.String operator,
                         double value)

and

public SQLExpression and(SQLExpression rhsExpression)

and

public SQLExpression and(java.lang.String rhsExpression)

or

public SQLExpression or(java.lang.String field,
                        java.lang.Object value)
Returns a new SQLExpression representing the OR concatenation of this object's expression with a field assignment

Parameters:
field - The fiels to assign a value to
value - The value to assign to the specified field. The value will be formatted by a call to formatValue(java.lang.Object).
Returns:
A new SQLExpression

or

public SQLExpression or(java.lang.String field,
                        java.lang.String operator,
                        java.lang.Object value)
Returns a new SQLExpression representing the OR concatenation of this object's expression and a field operation defined by the passed parameters.

Parameters:
field - The field to operate on
operator - The operator to apply. Supported values are listed in sub-interface SQLExpression.Operator.
value - The value to apply. In case of operator SQLExpression.Operator.BETWEEN, the value is supposed to be an array of two values. In case of operator SQLExpression.Operator.IN, the value is supposed to be an array of arbitrary length holding the values to compare the denoted field to.
Returns:
A new SQLExpression

or

public SQLExpression or(java.lang.String field,
                        boolean value)

or

public SQLExpression or(java.lang.String field,
                        java.lang.String operator,
                        boolean value)

or

public SQLExpression or(java.lang.String field,
                        char value)

or

public SQLExpression or(java.lang.String field,
                        java.lang.String operator,
                        char value)

or

public SQLExpression or(java.lang.String field,
                        short value)

or

public SQLExpression or(java.lang.String field,
                        java.lang.String operator,
                        short value)

or

public SQLExpression or(java.lang.String field,
                        int value)

or

public SQLExpression or(java.lang.String field,
                        java.lang.String operator,
                        int value)

or

public SQLExpression or(java.lang.String field,
                        long value)

or

public SQLExpression or(java.lang.String field,
                        java.lang.String operator,
                        long value)

or

public SQLExpression or(java.lang.String field,
                        float value)

or

public SQLExpression or(java.lang.String field,
                        java.lang.String operator,
                        float value)

or

public SQLExpression or(java.lang.String field,
                        double value)

or

public SQLExpression or(java.lang.String field,
                        java.lang.String operator,
                        double value)

or

public SQLExpression or(SQLExpression rhsExpression)

or

public SQLExpression or(java.lang.String rhsExpression)

brace

public SQLExpression brace()
Puts this object's expression in braces


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

orderBy

public SQLExpression orderBy(java.lang.String orderExpression)

orderBy

public SQLExpression orderBy(java.lang.String orderExpression,
                             java.lang.String direction)

isEmpty

protected boolean isEmpty(java.lang.String string)