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
public abstract class SQLExpression extends 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
Nested Classes Modifier and Type Class Description static class
SQLExpression.ColumnExpressionList
-
Field Summary
Fields Modifier and Type Field Description protected org.datanucleus.store.query.expression.Expression.Operator
lowestOperator
protected JavaTypeMapping
mapping
Mapping for this expression, defining how it is get/set.protected String
parameterName
Parameter name that this represents (if this is a parameter, "?" in JDBC).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
Constructors Modifier Constructor Description protected
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 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SQLExpression
add(SQLExpression expr)
Additive Operator.BooleanExpression
and(SQLExpression expr)
Conditional AND.SQLExpression
bitAnd(SQLExpression expr)
BITWISE AND operation.SQLExpression
bitOr(SQLExpression expr)
BITWISE OR operation.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.SQLExpression
com()
Bitwise Complement OperatorSQLExpression
distinct()
Distinct operator.SQLExpression
div(SQLExpression expr)
Division Operator.SQLExpression
encloseInParentheses()
Method to request the enclosure of this expression within parentheses.BooleanExpression
eor(SQLExpression expr)
Exclusive ORBooleanExpression
eq(SQLExpression expr)
Equality operator (equals to)BooleanExpression
ge(SQLExpression expr)
Relational operator (greater than or equals)JavaTypeMapping
getJavaTypeMapping()
org.datanucleus.store.query.expression.Expression.Operator
getLowestOperator()
int
getNumberOfSubExpressions()
String
getParameterName()
SQLStatement
getSQLStatement()
SQLTable
getSQLTable()
ColumnExpression
getSubExpression(int index)
BooleanExpression
gt(SQLExpression expr)
Relational operator (greater than)BooleanExpression
in(SQLExpression expr, boolean not)
In expression.SQLExpression
invoke(String methodName, List args)
Invocation of a method on this expression.BooleanExpression
ior(SQLExpression expr)
Conditional OR.BooleanExpression
is(SQLExpression expr, boolean not)
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 OperatorBooleanExpression
ne(SQLExpression expr)
Not equality operator (not equals to)SQLExpression
neg()
Unary Minus OperatorBooleanExpression
not()
Logical complementvoid
setJavaTypeMapping(JavaTypeMapping mapping)
SQLExpression
sub(SQLExpression expr)
Additive Operator.SQLText
toSQLText()
Method to return the SQL form of this expression.SQLExpression
unDistinct()
Method to remove a previously applied DISTINCT operator, to get back to the contained expression.
-
-
-
Field Detail
-
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 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.store.query.expression.Expression.Operator lowestOperator
-
subExprs
protected SQLExpression.ColumnExpressionList subExprs
Sub-expressions, where we have a field with multiple columns for example.
-
parameterName
protected String parameterName
Parameter name that this represents (if this is a parameter, "?" in JDBC).
-
-
Constructor Detail
-
SQLExpression
protected SQLExpression(SQLStatement stmt, SQLTable table, JavaTypeMapping mapping)
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 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 Detail
-
getLowestOperator
public org.datanucleus.store.query.expression.Expression.Operator getLowestOperator()
-
getNumberOfSubExpressions
public int getNumberOfSubExpressions()
-
getSubExpression
public ColumnExpression getSubExpression(int index)
-
getSQLStatement
public SQLStatement getSQLStatement()
-
isParameter
public boolean isParameter()
-
getParameterName
public String getParameterName()
-
getJavaTypeMapping
public JavaTypeMapping getJavaTypeMapping()
-
setJavaTypeMapping
public void setJavaTypeMapping(JavaTypeMapping mapping)
-
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, boolean not)
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
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.
-
distinct
public SQLExpression distinct()
Distinct operator.- Returns:
- converts the expression into "DISTINCT (expr)"
-
unDistinct
public SQLExpression unDistinct()
Method to remove a previously applied DISTINCT operator, to get back to the contained expression.- Returns:
- This expression with DISTINCT removed
-
bitAnd
public SQLExpression bitAnd(SQLExpression expr)
BITWISE AND operation.- Parameters:
expr
- expression representing the bitset- Returns:
- the bitwise AND expression
-
bitOr
public SQLExpression bitOr(SQLExpression expr)
BITWISE OR operation.- Parameters:
expr
- expression representing the bitset- Returns:
- the bitwise OR expression
-
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, boolean not)
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
public SQLExpression invoke(String methodName, List args)
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
-
-