Class SQLExpression
java.lang.Object
org.datanucleus.store.rdbms.sql.expression.SQLExpression
- Direct Known Subclasses:
ArrayExpression
,BinaryExpression
,BooleanExpression
,CaseExpression
,CharacterExpression
,CollectionExpression
,ColumnExpression
,DelegatedExpression
,MapExpression
,MapLiteral.MapKeyLiteral
,MapLiteral.MapValueLiteral
,NewObjectExpression
,NullLiteral
,NumericExpression
,ObjectExpression
,ParameterLiteral
,ResultAliasExpression
,StringExpression
,SubqueryExpression
,TemporalExpression
,UnboundExpression
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
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.datanucleus.store.query.expression.Expression.Operator
protected JavaTypeMapping
Mapping for this expression, defining how it is get/set.protected String
Parameter name that this represents (if this is a parameter, "?" in JDBC).protected final SQLText
The Statement Text representing the SQL for this expression.protected SQLStatement
The SQL statement that this is part of.protected SQLExpression.ColumnExpressionList
Sub-expressions, where we have a field with multiple columns for example.protected SQLTable
Table in the SQL statement that this mapping applies to. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SQLExpression
(org.datanucleus.store.query.expression.Expression.MonadicOperator op, SQLExpression expr1) Perform an operation "op" on expression "expr1".protected
SQLExpression
(SQLExpression expr1, org.datanucleus.store.query.expression.Expression.DyadicOperator op, SQLExpression expr2) Perform an operation "op" between "expr1" and "expr2".protected
SQLExpression
(SQLStatement stmt, JavaTypeMapping mapping, String functionName, List<SQLExpression> args, List<Object> types) Generates statement as "FUNCTION_NAME(arg [AS type] [,argN [AS typeN]])".protected
SQLExpression
(SQLStatement stmt, SQLTable table, JavaTypeMapping mapping) Constructor for an SQL expression for a (field) mapping in a specified table. -
Method Summary
Modifier and TypeMethodDescriptionadd
(SQLExpression expr) Additive Operator.and
(SQLExpression expr) Conditional AND.bitAnd
(SQLExpression expr) BITWISE AND operation.bitOr
(SQLExpression expr) BITWISE OR operation.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.com()
Bitwise Complement Operatordistinct()
Distinct operator.div
(SQLExpression expr) Division Operator.Method to request the enclosure of this expression within parentheses.eor
(SQLExpression expr) Exclusive OReq
(SQLExpression expr) Equality operator (equals to)ge
(SQLExpression expr) Relational operator (greater than or equals)org.datanucleus.store.query.expression.Expression.Operator
int
getSubExpression
(int index) gt
(SQLExpression expr) Relational operator (greater than)in
(SQLExpression expr, boolean not) In expression.invoke
(String methodName, List<SQLExpression> args) Invocation of a method on this expression.ior
(SQLExpression expr) Conditional OR.is
(SQLExpression expr, boolean not) An "is" (instanceOf) expression, providing a BooleanExpression whether this expression is an instanceof the provided type.boolean
le
(SQLExpression expr) Relational operator (lower than or equals)lt
(SQLExpression expr) Relational operator (lower than)mod
(SQLExpression expr) Remainder Operator.mul
(SQLExpression expr) Multiplication Operatorne
(SQLExpression expr) Not equality operator (not equals to)neg()
Unary Minus Operatornot()
Logical complementvoid
setJavaTypeMapping
(JavaTypeMapping mapping) sub
(SQLExpression expr) Additive Operator.Method to return the SQL form of this expression.Method to remove a previously applied DISTINCT operator, to get back to the contained expression.
-
Field Details
-
stmt
The SQL statement that this is part of. -
table
Table in the SQL statement that this mapping applies to. -
mapping
Mapping for this expression, defining how it is get/set. -
st
The Statement Text representing the SQL for this expression. -
lowestOperator
protected org.datanucleus.store.query.expression.Expression.Operator lowestOperator -
subExprs
Sub-expressions, where we have a field with multiple columns for example. -
parameterName
Parameter name that this represents (if this is a parameter, "?" in JDBC).
-
-
Constructor Details
-
SQLExpression
Constructor for an SQL expression for a (field) mapping in a specified table.- Parameters:
stmt
- The statementtable
- The table in the statementmapping
- The mapping for the field
-
SQLExpression
protected SQLExpression(org.datanucleus.store.query.expression.Expression.MonadicOperator op, SQLExpression expr1) Perform an operation "op" on expression "expr1".- Parameters:
op
- operatorexpr1
- operand
-
SQLExpression
protected SQLExpression(SQLExpression expr1, org.datanucleus.store.query.expression.Expression.DyadicOperator op, SQLExpression expr2) Perform an operation "op" between "expr1" and "expr2".- Parameters:
expr1
- the first expressionop
- the operator between operandsexpr2
- the second expression
-
SQLExpression
protected SQLExpression(SQLStatement stmt, JavaTypeMapping mapping, String functionName, List<SQLExpression> args, List<Object> 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:
stmt
- The statement to use for this expressionmapping
- Mapping to usefunctionName
- Name of functionargs
- SQLExpression listtypes
- List of String/SQLExpression for the types of arguments
-
-
Method Details
-
getLowestOperator
public org.datanucleus.store.query.expression.Expression.Operator getLowestOperator() -
getNumberOfSubExpressions
public int getNumberOfSubExpressions() -
getSubExpression
-
getSQLStatement
-
isParameter
public boolean isParameter() -
getParameterName
-
getJavaTypeMapping
-
setJavaTypeMapping
-
getSQLTable
-
toSQLText
Method to return the SQL form of this expression.- Returns:
- The SQL
-
encloseInParentheses
Method to request the enclosure of this expression within parentheses.- Returns:
- the enclosed expression
-
and
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
Exclusive OR- Parameters:
expr
- the right-hand operand- Returns:
- the result value is the bitwise exclusive OR of the operand values.
-
ior
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
Logical complement- Returns:
- the result value is false if operand is true; otherwise, the result is true.
-
eq
Equality operator (equals to)- Parameters:
expr
- the right-hand operand- Returns:
- The type of an equality expression is a boolean
-
ne
Not equality operator (not equals to)- Parameters:
expr
- the right-hand operand- Returns:
- The type of an equality expression is a boolean
-
lt
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
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
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
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
In expression. Return true if this is contained byexpr
- Parameters:
expr
- the right-hand expressionnot
- Whether we really want "not in"- Returns:
- true if the left-hand expression is contained by the right-hand expression. Otherwise the result is false.
-
add
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
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
Multiplication Operator- Parameters:
expr
- the right-hand operator- Returns:
- The binary * operator performs multiplication, producing the product of its operands.
-
div
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
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
Unary Minus Operator- Returns:
- the type of the unary minus expression is the promoted type of the operand.
-
com
Bitwise Complement Operator- Returns:
- the type of the unary bitwise complement expression is the promoted type of the operand.
-
distinct
Distinct operator.- Returns:
- converts the expression into "DISTINCT (expr)"
-
unDistinct
Method to remove a previously applied DISTINCT operator, to get back to the contained expression.- Returns:
- This expression with DISTINCT removed
-
bitAnd
BITWISE AND operation.- Parameters:
expr
- expression representing the bitset- Returns:
- the bitwise AND expression
-
bitOr
BITWISE OR operation.- Parameters:
expr
- expression representing the bitset- Returns:
- the bitwise OR expression
-
cast
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
An "is" (instanceOf) expression, providing a BooleanExpression whether this expression is an instanceof the provided type.- Parameters:
expr
- the expression representing the typenot
- Whether we really want "!instanceof"- Returns:
- Whether this expression is an instance of the provided type
-
invoke
Invocation of a method on this expression.- Parameters:
methodName
- name of the method to invokeargs
- Args to this method (if any)- Returns:
- the converted value
-