org.datanucleus.store.mapped.expression
Class ScalarExpression

java.lang.Object
  extended by org.datanucleus.store.mapped.expression.ScalarExpression
Direct Known Subclasses:
AnalysisExpression, ArrayExpression, BinaryExpression, BooleanExpression, CharacterExpression, ClassExpression, CollectionExpression, CollectionLiteral, CollectionSubqueryExpression, JDOHelperExpression, JoinExpression, MapExpression, MapKeyLiteral, MapLiteral, MapValueLiteral, MathExpression, NewObjectExpression, NullLiteral, NumericExpression, ObjectExpression, ReferenceExpression, ScalarExpression.DatastoreFieldExpression, SqlTemporalExpression, StringExpression, TemporalExpression, UnboundVariable

public abstract class ScalarExpression
extends java.lang.Object

A Scalar expression in a Query. Used to compute values with a resulting type .


Nested Class Summary
static class ScalarExpression.DatastoreFieldExpression
          A field expression represents a storage location for the value with an associated type
protected static class ScalarExpression.DyadicOperator
          "Dyadic" operator performs operation on one or two operands
 class ScalarExpression.ExpressionList
          Ordered list of expressions comma separated
static class ScalarExpression.IllegalArgumentTypeException
          An illegal argument error represents method invocations with unsupported/invalid argument types
static class ScalarExpression.IllegalOperationException
          Inner class representing an illegal operation.
static class ScalarExpression.MethodInvocationException
          A method invocation error represents an effort to invoke a operation on a expression
protected static class ScalarExpression.MonadicOperator
          "Monadic" operator performs a function on one operand.
protected static class ScalarExpression.Operator
          Inner class representing an Operator
 
Field Summary
protected  java.lang.String aliasIdentifier
          alias identifier for this expression
protected  boolean checkForTypeAssignability
          Flag whether we should make checks for type assignability (currently for JPA).
protected  ScalarExpression.ExpressionList expressionList
          List of sub-expressions.
static int FILTER
          when translated to StatementText, the expression is generated to be used as filter to a executing statement
protected static Localiser LOCALISER
          Localiser for messages
protected  ScalarExpression.Operator lowestOperator
           
protected  JavaTypeMapping mapping
          Mapping for the field.
static ScalarExpression.DyadicOperator OP_ADD
          ADD
static ScalarExpression.DyadicOperator OP_AND
          AND
static ScalarExpression.DyadicOperator OP_BETWEEN
          BETWEEN
static ScalarExpression.MonadicOperator OP_COM
          COM
static ScalarExpression.DyadicOperator OP_CONCAT
          CONCAT
static ScalarExpression.DyadicOperator OP_DIV
          DIV
static ScalarExpression.DyadicOperator OP_EQ
          EQ
static ScalarExpression.DyadicOperator OP_GT
          GT
static ScalarExpression.DyadicOperator OP_GTEQ
          GTEQ
static ScalarExpression.DyadicOperator OP_IN
          IN
static ScalarExpression.DyadicOperator OP_IS
          IS
static ScalarExpression.DyadicOperator OP_ISNOT
          ISNOT
static ScalarExpression.DyadicOperator OP_LIKE
          LIKE
static ScalarExpression.DyadicOperator OP_LT
          LT
static ScalarExpression.DyadicOperator OP_LTEQ
          LTEQ
static ScalarExpression.DyadicOperator OP_MOD
          MOD
static ScalarExpression.DyadicOperator OP_MUL
          MUL
static ScalarExpression.MonadicOperator OP_NEG
          NEG
static ScalarExpression.MonadicOperator OP_NOT
          NOT
static ScalarExpression.DyadicOperator OP_NOTEQ
          NOTEQ
static ScalarExpression.DyadicOperator OP_NOTIN
          NOT IN
static ScalarExpression.DyadicOperator OP_NOTLIKE
          NOT LIKE
static ScalarExpression.DyadicOperator OP_OR
          OR
static ScalarExpression.DyadicOperator OP_SUB
          SUB
protected  java.lang.String parameterName
          Name of a parameter that this expression/literal represents (if any).
static int PROJECTION
          when translated to StatementText, the expression is generated to be projected as result of executing a statement
protected  QueryExpression qs
          The Query Expression.
protected  StatementText st
          The Statement Text for this expression.
protected  LogicSetExpression te
          The table expression being used.
 
Constructor Summary
protected ScalarExpression(QueryExpression qs)
          Constructor.
protected ScalarExpression(QueryExpression qs, JavaTypeMapping mapping, LogicSetExpression te)
          Constructor for an expression of the mapping in the specified table.
protected ScalarExpression(ScalarExpression.MonadicOperator op, ScalarExpression operand)
          Perform a function op on operand
protected ScalarExpression(ScalarExpression operand1, ScalarExpression.DyadicOperator op, ScalarExpression operand2)
          Performs a function on two arguments.
protected ScalarExpression(java.lang.String functionName, java.util.List args)
          Generates statement as e.g.
protected ScalarExpression(java.lang.String functionName, java.util.List args, java.util.List types)
          Generates statement as e.g.
 
Method Summary
 ScalarExpression accessField(java.lang.String fieldName, boolean innerJoin)
          A field access expression may access a field of an object or array, a reference to which is the value of an expression
 ScalarExpression add(ScalarExpression expr)
          Additive Operator.
 BooleanExpression and(ScalarExpression expr)
          Conditional And.
 ScalarExpression as(java.lang.String aliasIdentifier)
          Define a new identifier for this expression
protected  void assertValidTypeForParameterComparison(ScalarExpression expr, java.lang.Class type)
          Method to check if the passed expression when being a parameter is of a valid type for comparison.
 ScalarExpression callMethod(java.lang.String methodName, java.util.List arguments)
          Invoke a function in a expression.
 ScalarExpression cast(java.lang.Class type)
          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.
 void checkForTypeAssignability()
          Method to mark this expression/literal as needing checking for type assignability.
 ScalarExpression com()
          Bitwise Complement Operator
 ScalarExpression div(ScalarExpression expr)
          Division Operator.
 ScalarExpression encloseWithInParentheses()
          Method to request the enclosure of this expression within parentheses
 BooleanExpression eor(ScalarExpression expr)
          Exclusive OR
 BooleanExpression eq(ScalarExpression expr)
          Equality operator (equals to)
 boolean equals(java.lang.Object o)
          Equality operator providing a simple comparison of expressions.
 java.lang.String getAlias()
          Accessor for the alias (if any).
protected  ScalarExpression getConsistentTypeForParameterComparison(ScalarExpression expr)
          Convenience method to return a ScalarExpression that we can use to compare against this object.
 ScalarExpression.ExpressionList getExpressionList()
          Returns the expression list.
 LogicSetExpression getLogicSetExpression()
          Accessor for the table expression being used by this expression.
 JavaTypeMapping getMapping()
          Accessor for the mapping for this expression (if any).
 java.lang.String getNonAliasExpression()
          Accessor for the expression without any alias.
 QueryExpression getQueryExpression()
          Accessor for the query expression.
 BooleanExpression gt(ScalarExpression expr)
          Relational operator (greater than)
 BooleanExpression gteq(ScalarExpression expr)
          Relational operator (greater than or equals)
 BooleanExpression in(ScalarExpression expr)
          In expression.
 BooleanExpression instanceOf(ScalarExpression expr)
          Type Comparison Operator instanceof
 BooleanExpression ior(ScalarExpression expr)
          Conditional OR.
 BooleanExpression lt(ScalarExpression expr)
          Relational operator (lower than)
 BooleanExpression lteq(ScalarExpression expr)
          Relational operator (lower than or equals)
 ScalarExpression mod(ScalarExpression expr)
          Remainder Operator.
 ScalarExpression mul(ScalarExpression expr)
          Multiplication Operator
 ScalarExpression neg()
          Unary Minus Operator
 BooleanExpression not()
          Logical complement
 BooleanExpression noteq(ScalarExpression expr)
          Equality operator (not equals to)
 void setParameterName(java.lang.String paramName)
          Mutator to set the parameter name that this expression/literal represents.
 ScalarExpression sub(ScalarExpression expr)
          Additive Operator.
 StatementText toStatementText(int mode)
          StatementText representation of this expression.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localiser for messages


PROJECTION

public static int PROJECTION
when translated to StatementText, the expression is generated to be projected as result of executing a statement


FILTER

public static int FILTER
when translated to StatementText, the expression is generated to be used as filter to a executing statement


OP_OR

public static final ScalarExpression.DyadicOperator OP_OR
OR


OP_AND

public static final ScalarExpression.DyadicOperator OP_AND
AND


OP_NOT

public static final ScalarExpression.MonadicOperator OP_NOT
NOT


OP_EQ

public static final ScalarExpression.DyadicOperator OP_EQ
EQ


OP_NOTEQ

public static final ScalarExpression.DyadicOperator OP_NOTEQ
NOTEQ


OP_LT

public static final ScalarExpression.DyadicOperator OP_LT
LT


OP_LTEQ

public static final ScalarExpression.DyadicOperator OP_LTEQ
LTEQ


OP_GT

public static final ScalarExpression.DyadicOperator OP_GT
GT


OP_GTEQ

public static final ScalarExpression.DyadicOperator OP_GTEQ
GTEQ


OP_LIKE

public static final ScalarExpression.DyadicOperator OP_LIKE
LIKE


OP_NOTLIKE

public static final ScalarExpression.DyadicOperator OP_NOTLIKE
NOT LIKE


OP_BETWEEN

public static final ScalarExpression.DyadicOperator OP_BETWEEN
BETWEEN


OP_IS

public static final ScalarExpression.DyadicOperator OP_IS
IS


OP_ISNOT

public static final ScalarExpression.DyadicOperator OP_ISNOT
ISNOT


OP_IN

public static final ScalarExpression.DyadicOperator OP_IN
IN


OP_NOTIN

public static final ScalarExpression.DyadicOperator OP_NOTIN
NOT IN


OP_ADD

public static final ScalarExpression.DyadicOperator OP_ADD
ADD


OP_SUB

public static final ScalarExpression.DyadicOperator OP_SUB
SUB


OP_CONCAT

public static final ScalarExpression.DyadicOperator OP_CONCAT
CONCAT


OP_MUL

public static final ScalarExpression.DyadicOperator OP_MUL
MUL


OP_DIV

public static final ScalarExpression.DyadicOperator OP_DIV
DIV


OP_MOD

public static final ScalarExpression.DyadicOperator OP_MOD
MOD


OP_NEG

public static final ScalarExpression.MonadicOperator OP_NEG
NEG


OP_COM

public static final ScalarExpression.MonadicOperator OP_COM
COM


qs

protected final QueryExpression qs
The Query Expression.


te

protected LogicSetExpression te
The table expression being used.


st

protected final StatementText st
The Statement Text for this expression.


lowestOperator

protected ScalarExpression.Operator lowestOperator

aliasIdentifier

protected java.lang.String aliasIdentifier
alias identifier for this expression


mapping

protected JavaTypeMapping mapping
Mapping for the field.


expressionList

protected ScalarExpression.ExpressionList expressionList
List of sub-expressions. Used where we have a field that has multiple datastore mappings (one subexpression for each).


parameterName

protected java.lang.String parameterName
Name of a parameter that this expression/literal represents (if any).


checkForTypeAssignability

protected boolean checkForTypeAssignability
Flag whether we should make checks for type assignability (currently for JPA).

Constructor Detail

ScalarExpression

protected ScalarExpression(QueryExpression qs)
Constructor.

Parameters:
qs - The Query Expression

ScalarExpression

protected ScalarExpression(QueryExpression qs,
                           JavaTypeMapping mapping,
                           LogicSetExpression te)
Constructor for an expression of the mapping in the specified table. Creates a list of (field) expressions for the datastore mappings of the specified field.

Parameters:
qs - The Query Expression
mapping - The field mapping
te - The table

ScalarExpression

protected ScalarExpression(java.lang.String functionName,
                           java.util.List args)
Generates statement as e.g. FUNCTION_NAME(arg[,argN])

Parameters:
functionName - Name of the function
args - ScalarExpression list

ScalarExpression

protected ScalarExpression(java.lang.String functionName,
                           java.util.List args,
                           java.util.List types)
Generates statement as e.g. FUNCTION_NAME(arg AS type[,argN as typeN])

Parameters:
functionName - Name of function
args - ScalarExpression list
types - String or ScalarExpression list

ScalarExpression

protected ScalarExpression(ScalarExpression.MonadicOperator op,
                           ScalarExpression operand)
Perform a function op on operand

Parameters:
op - operator
operand - operand

ScalarExpression

protected ScalarExpression(ScalarExpression operand1,
                           ScalarExpression.DyadicOperator op,
                           ScalarExpression operand2)
Performs a function on two arguments. op(operand1,operand2) operand1 op operand2

Parameters:
operand1 - the first expression
op - the operator between operands
operand2 - the second expression
Method Detail

setParameterName

public void setParameterName(java.lang.String paramName)
Mutator to set the parameter name that this expression/literal represents.

Parameters:
paramName - Name of the parameter

checkForTypeAssignability

public void checkForTypeAssignability()
Method to mark this expression/literal as needing checking for type assignability. TODO Make this part of ObjectManager and allow ScalarExpression to reach the ObjectManager so we don't need to propagate the info


getQueryExpression

public QueryExpression getQueryExpression()
Accessor for the query expression.

Returns:
The query expression

getLogicSetExpression

public LogicSetExpression getLogicSetExpression()
Accessor for the table expression being used by this expression.

Returns:
Returns the table expression for this expression.

and

public BooleanExpression and(ScalarExpression 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(ScalarExpression 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(ScalarExpression 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(ScalarExpression expr)
Equality operator (equals to)

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

noteq

public BooleanExpression noteq(ScalarExpression expr)
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(ScalarExpression 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.

lteq

public BooleanExpression lteq(ScalarExpression 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(ScalarExpression 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.

gteq

public BooleanExpression gteq(ScalarExpression 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.

instanceOf

public BooleanExpression instanceOf(ScalarExpression expr)
Type Comparison Operator instanceof

Parameters:
expr - the right-hand ReferenceType expression
Returns:
true if the value of the RelationalExpression is not null and the reference could be cast to the ReferenceType without raising a ClassCastException. Otherwise the result is false.

in

public BooleanExpression in(ScalarExpression 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 ScalarExpression add(ScalarExpression 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 ScalarExpression sub(ScalarExpression 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 ScalarExpression mul(ScalarExpression expr)
Multiplication Operator

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

div

public ScalarExpression div(ScalarExpression 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 ScalarExpression mod(ScalarExpression 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 ScalarExpression neg()
Unary Minus Operator

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

com

public ScalarExpression com()
Bitwise Complement Operator

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

cast

public ScalarExpression cast(java.lang.Class type)
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:
type - the type named by the cast operator
Returns:
the converted value

accessField

public ScalarExpression accessField(java.lang.String fieldName,
                                    boolean innerJoin)
A field access expression may access a field of an object or array, a reference to which is the value of an expression

Parameters:
fieldName - the field identifier
innerJoin - true if in datastore to use inner joins; false to use left joins
Returns:
the field expression

as

public ScalarExpression as(java.lang.String aliasIdentifier)
Define a new identifier for this expression

Parameters:
aliasIdentifier - the alias
Returns:
this

getAlias

public java.lang.String getAlias()
Accessor for the alias (if any).

Returns:
Returns the alias.

getNonAliasExpression

public java.lang.String getNonAliasExpression()
Accessor for the expression without any alias.

Returns:
Returns the nonAliasExpression.

callMethod

public ScalarExpression callMethod(java.lang.String methodName,
                                   java.util.List arguments)
Invoke a function in a expression. The scalar expression must have a method with the signature "methodNameMethod([ScalarExpression argument1, [ScalarExpression argument2],...])". The number of arguments is equivalent to the size of the arguments list.

Parameters:
methodName - the function name
arguments - the arguments
Returns:
the result returned when invoking the function

encloseWithInParentheses

public ScalarExpression encloseWithInParentheses()
Method to request the enclosure of this expression within parentheses

Returns:
the enclosed expression

toStatementText

public StatementText toStatementText(int mode)
StatementText representation of this expression. I.E. A Boolean field may be stored in boolean format like 0 or 1, and it can also be stored in other formats, like Y or N, TRUE or FALSE, and so on. The projection mode for the boolean field is the real content of the value stored, (e.g. Y or N), and opposed to that the filter mode for the boolean field is always represented by a boolean expression (e.g. Y=Y or N=N) In SQL, the projection can be exemplified as "SELECT BOOLEAN_FIELD ... " and the filter as "SELECT COLUMNS ... WHERE BOOLEAN_FIELD ='Y'"

Parameters:
mode - (0=PROJECTION;1=FILTER)
Returns:
the StatementText

equals

public boolean equals(java.lang.Object o)
Equality operator providing a simple comparison of expressions.

Overrides:
equals in class java.lang.Object
Parameters:
o - The other object
Returns:
Whether they are equal

toString

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

assertValidTypeForParameterComparison

protected void assertValidTypeForParameterComparison(ScalarExpression expr,
                                                     java.lang.Class type)
Method to check if the passed expression when being a parameter is of a valid type for comparison. Throws a QueryInvalidParametersException if not of the same type.

Parameters:
expr - The other expression

getConsistentTypeForParameterComparison

protected ScalarExpression getConsistentTypeForParameterComparison(ScalarExpression expr)
Convenience method to return a ScalarExpression that we can use to compare against this object. Returns the input expression unless it is for a parameter and the parameter expression has a different datastore mapping (the default mapping whereas this has had its datastore mapping specially selected).

Parameters:
expr - The expression to check
Returns:
The expression to use

getMapping

public JavaTypeMapping getMapping()
Accessor for the mapping for this expression (if any).

Returns:
Returns the mapping.

getExpressionList

public ScalarExpression.ExpressionList getExpressionList()
Returns the expression list.

Returns:
The expressions list with atomic expressions (ScalarExpression.FieldExpression). A expression in this list can't be split down


Copyright © 2010. All Rights Reserved.