org.datanucleus.store.rdbms.sql.expression
Class SQLExpression

java.lang.Object
  extended by org.datanucleus.store.rdbms.sql.expression.SQLExpression
Direct Known Subclasses:
ArrayExpression, BooleanExpression, CharacterExpression, CollectionExpression, ColumnExpression, EnumExpression, MapExpression, MapLiteral.MapKeyLiteral, MapLiteral.MapValueLiteral, NewObjectExpression, NullLiteral, NumericExpression, ObjectExpression, ParameterLiteral, StringExpression, SubqueryExpression, TemporalExpression

public abstract class SQLExpression
extends java.lang.Object

Base expression for SQL. The principle here is that any expression (be it a field, literal, parameter, variable etc) has a type and so needs a JavaTypeMapping to control reading/writing of that type. An expression will typically have an SQLTable (in the overall statement) that it refers to. A literal will not have an SQLTable since it represents a value. The actual SQL for the expression is embodied in the SQLText field. Construction typically sets the SQL for the respective expression.


Nested Class Summary
 class SQLExpression.ColumnExpressionList
           
 
Field Summary
protected  boolean isParameter
          Whether this expression is an input parameter (so will be "?" in the SQL).
protected static org.datanucleus.util.Localiser LOCALISER
          Localiser for messages
protected  org.datanucleus.query.expression.Expression.Operator lowestOperator
           
protected  org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping
          Mapping for this expression, defining how it is get/set.
protected  SQLText st
          The Statement Text representing the SQL for this expression.
protected  SQLStatement stmt
          The SQL statement that this is part of.
protected  SQLExpression.ColumnExpressionList subExprs
          Sub-expressions, where we have a field with multiple columns for example.
protected  SQLTable table
          Table in the SQL statement that this mapping applies to.
 
Constructor Summary
protected SQLExpression(org.datanucleus.query.expression.Expression.MonadicOperator op, SQLExpression expr1)
          Perform an operation "op" on expression "expr1".
protected SQLExpression(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping, java.lang.String functionName, java.util.List<SQLExpression> args, java.util.List types)
          Generates statement as "FUNCTION_NAME(arg [AS type] [,argN [AS typeN]])".
protected SQLExpression(SQLExpression expr1, org.datanucleus.query.expression.Expression.DyadicOperator op, SQLExpression expr2)
          Perform an operation "op" between "expr1" and "expr2".
protected SQLExpression(SQLStatement stmt, SQLTable table, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
          Constructor for an SQL expression for a (field) mapping in a specified table.
 
Method Summary
 SQLExpression add(SQLExpression expr)
          Additive Operator.
 BooleanExpression and(SQLExpression expr)
          Conditional And.
 SQLExpression cast(SQLExpression expr)
          A cast expression converts, at run time, a value of one type to a similar value of another type; or confirms, at compile time, that the type of an expression is boolean; or checks, at run time, that a reference value refers to an object whose class is compatible with a specified reference type.
protected  void checkForAndCorrectParameterComparison(SQLExpression expr)
          Convenience method that checks this expression and the provided expression for use in a comparison operation, and if both are parameters then will swap one for its value (if known).
 SQLExpression com()
          Bitwise Complement Operator
 SQLExpression div(SQLExpression expr)
          Division Operator.
 SQLExpression encloseInParentheses()
          Method to request the enclosure of this expression within parentheses.
 BooleanExpression eor(SQLExpression expr)
          Exclusive OR
 BooleanExpression eq(SQLExpression expr)
          Equality operator (equals to)
 BooleanExpression ge(SQLExpression expr)
          Relational operator (greater than or equals)
 org.datanucleus.store.mapped.mapping.JavaTypeMapping getJavaTypeMapping()
           
 int getNumberOfSubExpressions()
           
 SQLStatement getSQLStatement()
           
 SQLTable getSQLTable()
           
 BooleanExpression gt(SQLExpression expr)
          Relational operator (greater than)
 BooleanExpression in(SQLExpression expr)
          In expression.
 SQLExpression invoke(java.lang.String methodName, java.util.List args)
          Invocation of a method on this expression.
 BooleanExpression ior(SQLExpression expr)
          Conditional OR.
 BooleanExpression is(SQLExpression expr)
          An "is" (instanceOf) expression, providing a BooleanExpression whether this expression is an instanceof the provided type.
 boolean isParameter()
           
 BooleanExpression le(SQLExpression expr)
          Relational operator (lower than or equals)
 BooleanExpression lt(SQLExpression expr)
          Relational operator (lower than)
 SQLExpression mod(SQLExpression expr)
          Remainder Operator.
 SQLExpression mul(SQLExpression expr)
          Multiplication Operator
 BooleanExpression ne(SQLExpression expr)
          Not equality operator (not equals to)
 SQLExpression neg()
          Unary Minus Operator
 BooleanExpression not()
          Logical complement
 SQLExpression sub(SQLExpression expr)
          Additive Operator.
 SQLText toSQLText()
          Method to return the SQL form of this expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER
Localiser for messages


stmt

protected SQLStatement stmt
The SQL statement that this is part of.


table

protected SQLTable table
Table in the SQL statement that this mapping applies to.


mapping

protected org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping
Mapping for this expression, defining how it is get/set.


st

protected final SQLText st
The Statement Text representing the SQL for this expression.


lowestOperator

protected org.datanucleus.query.expression.Expression.Operator lowestOperator

subExprs

protected SQLExpression.ColumnExpressionList subExprs
Sub-expressions, where we have a field with multiple columns for example.


isParameter

protected boolean isParameter
Whether this expression is an input parameter (so will be "?" in the SQL).

Constructor Detail

SQLExpression

protected SQLExpression(SQLStatement stmt,
                        SQLTable table,
                        org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
Constructor for an SQL expression for a (field) mapping in a specified table.

Parameters:
stmt - The statement
table - The table in the statement
mapping - The mapping for the field

SQLExpression

protected SQLExpression(org.datanucleus.query.expression.Expression.MonadicOperator op,
                        SQLExpression expr1)
Perform an operation "op" on expression "expr1".

Parameters:
op - operator
expr1 - operand

SQLExpression

protected SQLExpression(SQLExpression expr1,
                        org.datanucleus.query.expression.Expression.DyadicOperator op,
                        SQLExpression expr2)
Perform an operation "op" between "expr1" and "expr2".

Parameters:
expr1 - the first expression
op - the operator between operands
expr2 - the second expression

SQLExpression

protected SQLExpression(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping,
                        java.lang.String functionName,
                        java.util.List<SQLExpression> args,
                        java.util.List types)
Generates statement as "FUNCTION_NAME(arg [AS type] [,argN [AS typeN]])". Number of objects in types (when supplied) is assumed to be the same as the number of arguments.

Parameters:
mapping - Mapping to use
functionName - Name of function
args - SQLExpression list
types - List of String/SQLExpression for the types of arguments
Method Detail

getNumberOfSubExpressions

public int getNumberOfSubExpressions()

getSQLStatement

public SQLStatement getSQLStatement()

isParameter

public boolean isParameter()

getJavaTypeMapping

public org.datanucleus.store.mapped.mapping.JavaTypeMapping getJavaTypeMapping()

getSQLTable

public SQLTable getSQLTable()

toSQLText

public SQLText toSQLText()
Method to return the SQL form of this expression.

Returns:
The SQL

encloseInParentheses

public SQLExpression encloseInParentheses()
Method to request the enclosure of this expression within parentheses.

Returns:
the enclosed expression

and

public BooleanExpression and(SQLExpression expr)
Conditional And. Evaluates its right-hand operand only if the value of its left-hand operand is true.

Parameters:
expr - the right-hand operand
Returns:
the result value is true if both operand values are true; otherwise, the result is false.

eor

public BooleanExpression eor(SQLExpression expr)
Exclusive OR

Parameters:
expr - the right-hand operand
Returns:
the result value is the bitwise exclusive OR of the operand values.

ior

public BooleanExpression ior(SQLExpression expr)
Conditional OR. Evaluates its right-hand operand only if the value of its left-hand operand is false.

Parameters:
expr - the right-hand operand
Returns:
the result value is false if both operand values are false; otherwise, the result is true.

not

public BooleanExpression not()
Logical complement

Returns:
the result value is false if operand is true; otherwise, the result is true.

eq

public BooleanExpression eq(SQLExpression expr)
Equality operator (equals to)

Parameters:
expr - the right-hand operand
Returns:
The type of an equality expression is a boolean

ne

public BooleanExpression ne(SQLExpression expr)
Not equality operator (not equals to)

Parameters:
expr - the right-hand operand
Returns:
The type of an equality expression is a boolean

lt

public BooleanExpression lt(SQLExpression expr)
Relational operator (lower than)

Parameters:
expr - the right-hand operand
Returns:
true if the value of the left-hand operand is less than the value of the right-hand operand, and otherwise is false.

le

public BooleanExpression le(SQLExpression expr)
Relational operator (lower than or equals)

Parameters:
expr - the right-hand operand
Returns:
true if the value of the left-hand operand is less than or equal to the value of the right-hand operand, and otherwise is false.

gt

public BooleanExpression gt(SQLExpression expr)
Relational operator (greater than)

Parameters:
expr - the right-hand operand
Returns:
true if the value of the left-hand operand is greater than the value of the right-hand operand, and otherwise is false.

ge

public BooleanExpression ge(SQLExpression expr)
Relational operator (greater than or equals)

Parameters:
expr - the right-hand operand
Returns:
true if the value of the left-hand operand is greater than or equal the value of the right-hand operand, and otherwise is false.

in

public BooleanExpression in(SQLExpression expr)
In expression. Return true if this is contained by expr

Parameters:
expr - the right-hand expression
Returns:
true if the left-hand expression is contained by the right-hand expression. Otherwise the result is false.

add

public SQLExpression add(SQLExpression expr)
Additive Operator. The binary + operator performs addition when applied to two operands of numeric type, producing the sum of the operands. If the type of either operand of a + operator is String, then the operation is string concatenation.

Parameters:
expr - the right-hand operand
Returns:
If one of the operands is String, the returned value is the string concatenation; The sum of two operands of numeric type. The left-hand operand is the minuend and the right-hand operand is the subtrahend;

sub

public SQLExpression sub(SQLExpression expr)
Additive Operator. The binary - operator subtracts right-hand operand from left-hand operand.

Parameters:
expr - the right-hand operand
Returns:
The binary - operator performs subtraction when applied to two operands of numeric type producing the difference of its operands; the left-hand operand is the minuend and the right-hand operand is the subtrahend.

mul

public SQLExpression mul(SQLExpression expr)
Multiplication Operator

Parameters:
expr - the right-hand operator
Returns:
The binary * operator performs multiplication, producing the product of its operands.

div

public SQLExpression div(SQLExpression expr)
Division Operator. The left-hand operand is the dividend and the right-hand operand is the divisor.

Parameters:
expr - the right-hand operator
Returns:
The binary / operator performs division, producing the quotient of its operands

mod

public SQLExpression mod(SQLExpression expr)
Remainder Operator. The left-hand operand is the dividend and the right-hand operand is the divisor.

Parameters:
expr - the right-hand operator
Returns:
The binary % operator is said to yield the remainder of its operands from an implied division

neg

public SQLExpression neg()
Unary Minus Operator

Returns:
the type of the unary minus expression is the promoted type of the operand.

com

public SQLExpression com()
Bitwise Complement Operator

Returns:
the type of the unary bitwise complement expression is the promoted type of the operand.

cast

public SQLExpression cast(SQLExpression expr)
A cast expression converts, at run time, a value of one type to a similar value of another type; or confirms, at compile time, that the type of an expression is boolean; or checks, at run time, that a reference value refers to an object whose class is compatible with a specified reference type. The type of the operand expression must be converted to the type explicitly named by the cast operator.

Parameters:
expr - expression representing the type to cast to
Returns:
the converted value

is

public BooleanExpression is(SQLExpression expr)
An "is" (instanceOf) expression, providing a BooleanExpression whether this expression is an instanceof the provided type.

Parameters:
expr - the expression representing the type
Returns:
Whether this expression is an instance of the provided type

invoke

public SQLExpression invoke(java.lang.String methodName,
                            java.util.List args)
Invocation of a method on this expression.

Parameters:
methodName - name of the method to invoke
args - Args to this method (if any)
Returns:
the converted value

checkForAndCorrectParameterComparison

protected void checkForAndCorrectParameterComparison(SQLExpression expr)
Convenience method that checks this expression and the provided expression for use in a comparison operation, and if both are parameters then will swap one for its value (if known). This is because in JDBC we cannot have "? = ?"

Parameters:
expr - The other expression to compare with


Copyright © 2009. All Rights Reserved.