public final class Tree extends NodeImpl implements QueryTree, ExpressionFactory
Constructor and Description |
---|
Tree()
The noarg constructor is called by persistence manager internal.
|
Tree(CandidateClass candidateClass,
ParameterDecl parameterDeclarations,
VariableDecl variableDeclarations,
OrderingExpr orderingExpressions,
Expr filter)
This constructor is called by semantic analysis only.
|
Modifier and Type | Method and Description |
---|---|
void |
addAscendingOrdering(Expression expression)
Adds an ascending ordering expression to this query tree.
|
void |
addDescendingOrdering(Expression expression)
Adds an descending ordering expression to this query tree.
|
void |
arrive(NodeVisitor visitor)
Delegates to the argument
visitor . |
protected java.lang.Object |
clone()
Creates and returns a copy of this object.
|
void |
declareParameter(java.lang.Class clazz,
java.lang.String parameter)
Declares a parameter for this query tree.
|
void |
declareVariable(java.lang.Class clazz,
java.lang.String variable)
Declares a variable for this query tree.
|
java.lang.Class |
getCandidateClass()
Returns the candidate class.
|
Node[] |
getChildren()
Returns the children of this node.
|
java.util.Map |
getDeclaredParameters()
Returns a map containing all declared parameters.
|
java.util.List |
getDeclaredParametersAsList()
Returns a list of all declared parameters.
|
java.util.Map |
getDeclaredVariables()
Returns a map containing all declared variables.
|
Expression |
getFilter()
Returns the filter expression of this query tree.
|
java.util.List |
getOrderingExpressions()
Returns a list of all added ordering expressions.
|
java.lang.String |
getSerializedCandidateClassName()
Returns the candidate class name calculated during serialization of
this query tree instance.
|
void |
initANTLRAST()
Ensures that this node has a corresponding ANTLR tree structure.
|
java.lang.Object |
leave(NodeVisitor visitor,
java.lang.Object[] results)
Delegates to the argument
visitor . |
AndExpression |
newAnd(Expression left,
Expression right)
Returns an and expression for the arguments
left and right . |
CastExpression |
newCast(java.lang.Class clazz,
Expression expression)
Returns an instance of
CastExpression . |
ComplementExpression |
newComplement(Expression expr)
Returns a complement expression for the argument
expr . |
ConditionalAndExpression |
newConditionalAnd(Expression left,
Expression right)
Returns a conditional and expression for the arguments
left and right . |
ConditionalOrExpression |
newConditionalOr(Expression left,
Expression right)
Returns a conditional or expression for the arguments
left and right . |
ConstantExpression |
newConstant(boolean b)
Returns an instance of
BooleanLiteralExpression . |
ConstantExpression |
newConstant(byte b)
Returns an instance of
ByteLiteralExpression . |
ConstantExpression |
newConstant(char c)
Returns an instance of
CharLiteralExpression . |
ConstantExpression |
newConstant(double d)
Returns an instance of
DoubleLiteralExpression . |
ConstantExpression |
newConstant(float f)
Returns an instance of
FloatLiteralExpression . |
ConstantExpression |
newConstant(int i)
Returns an instance of
IntLiteralExpression . |
ConstantExpression |
newConstant(long l)
Returns an instance of
LongLiteralExpression . |
ConstantExpression |
newConstant(java.lang.Object value)
Returns an instance of
ConstantExpression . |
ConstantExpression |
newConstant(short s)
Returns an instance of
ShortLiteralExpression . |
DivideExpression |
newDivide(Expression left,
Expression right)
Returns a divide expression for the arguments
left and right . |
EqualsExpression |
newEquals(Expression left,
Expression right)
Returns an equals expression for the arguments
left and right . |
StaticFieldAccessExpression |
newFieldAccess(java.lang.Class clazz,
java.lang.String fieldName)
Returns an instance of
StaticFieldAccessExpression . |
FieldAccessExpression |
newFieldAccess(Expression target,
java.lang.String fieldName)
Returns an instance of
FieldAccessExpression . |
GreaterThanExpression |
newGreaterThan(Expression left,
Expression right)
Returns a greater than expression for the arguments
left and right . |
GreaterThanEqualsExpression |
newGreaterThanEquals(Expression left,
Expression right)
Returns a greater than equals expression for the arguments
left and right . |
IdentifierExpression |
newIdentifier(java.lang.String identifier)
Returns an instance of either
ThisExpression or
VariableAccessExpression or
ParameterAccessExpression or FieldAccessExpression
depending on the fact which of the classes the argument
identifier maps to. |
LessThanExpression |
newLessThan(Expression left,
Expression right)
Returns a less than expression for the arguments
left and right . |
LessThanEqualsExpression |
newLessThanEquals(Expression left,
Expression right)
Returns a less than equals expression for the arguments
left and right . |
MethodCallExpression |
newMethodCall(Expression target,
java.lang.String methodName,
Expression[] arguments)
Returns an instance of
MethodCallExpression . |
UnaryMinusExpression |
newMinus(Expression expr)
Returns a unary minus expression for the argument
expr . |
MinusExpression |
newMinus(Expression left,
Expression right)
Returns a minus expression for the arguments
left and right . |
NotExpression |
newNot(Expression expr)
Returns a not expression for the argument
expr . |
NotEqualsExpression |
newNotEquals(Expression left,
Expression right)
Returns a not equals expression for the arguments
left and right . |
OrExpression |
newOr(Expression left,
Expression right)
Returns an or expression for the arguments
left and right . |
UnaryPlusExpression |
newPlus(Expression expr)
Returns a plus expression for the argument
expr . |
PlusExpression |
newPlus(Expression left,
Expression right)
Returns a plus expression for the arguments
left and right . |
TimesExpression |
newTimes(Expression left,
Expression right)
Returns a times expression for the arguments
left and right . |
void |
setCandidateClass(java.lang.Class clazz)
Sets the candidate class for this query tree.
|
void |
setFilter(Expression filter)
Sets the filter expression for this query tree.
|
boolean |
walkNextChild(NodeVisitor visitor,
java.lang.Object resultOfPreviousChild,
int indexOfNextChild)
Delegates to the argument
visitor . |
getJavaClass, getObject, getParent, getTokenType, setObject, setParent, toString
getColumn, getLine, getTypeInfo, initialize, initialize, initialize, setColumn, setLine, setTypeInfo, treeToString
addChild, decode, encode, equals, equalsList, equalsListPartial, equalsTree, equalsTreePartial, findAll, findAllPartial, getFirstChild, getNextSibling, getNumberOfChildren, getTokenNames, removeChildren, setFirstChild, setNextSibling, setVerboseStringConversion, toStringList, toStringTree, xmlSerialize, xmlSerializeNode, xmlSerializeRootClose, xmlSerializeRootOpen
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getJavaClass, getObject, getParent, getTokenType, setObject, setParent
public Tree()
public Tree(CandidateClass candidateClass, ParameterDecl parameterDeclarations, VariableDecl variableDeclarations, OrderingExpr orderingExpressions, Expr filter)
candidateClass
- the candidate classparameterDeclarations
- the antlr node containing all
parameter declaration nodes as siblingsvariableDeclarations
- the antlr node containing all
variable declaration nodes as siblingsorderingExpressions
- the antlr node containing all
ordering nodes as siblingsfilter
- the filter expressionprotected java.lang.Object clone() throws java.lang.CloneNotSupportedException
public void setCandidateClass(java.lang.Class clazz)
NullPointerException
if the argument
clazz
is null
.
Otherwise this method invalidates this tree:
Parameters, variables, orderings and the filter are nullified.setCandidateClass
in interface QueryTree
clazz
- the candidate classNullPointerException
- if the argument clazz
is nullpublic void declareParameter(java.lang.Class clazz, java.lang.String parameter)
NullPointerException
if one of the arguments
type
or parameter
are null
.
If a parameter is already declared having the same name
as the argument parameter
, then that declaration is
replaced by this declaration.
Once you have declared a parameter, you can access it using method
newIdentifier
.
Please note: You can not declare a parameter and a variable having the same name.declareParameter
in interface QueryTree
clazz
- the instance of a Java class which is the type of the declared parameterparameter
- the name of the declared parameterjava.lang.NullPointerException
- if type or parameter are nullJDOQueryException
- if a variable has been declared with the same namepublic void declareVariable(java.lang.Class clazz, java.lang.String variable)
NullPointerException
if one of the arguments
type
or variable
are null
.
If a variable is already declared having the same name
as the argument variable
, then that declaration is
replaced by this declaration.
Once you have declared a variable, you can access it using method
newIdentifier
.
Please note: You can not declare a parameter and a variable having the same name.declareVariable
in interface QueryTree
clazz
- the instance of a Java class which is the type of the declared variablevariable
- the name of the declared variablejava.lang.NullPointerException
- if type or variable are nullJDOQueryException
- if a parameter has been declared with the same namepublic void addAscendingOrdering(Expression expression)
NullPointerException
if the argument
expression
is null
.
The order of adding ascending and descending ordering expressions defines
the order of instances in the result collection of an executed query
instance corresponding with this query tree.addAscendingOrdering
in interface QueryTree
expression
- the order expressionjava.lang.NullPointerException
- if expression is nullpublic void addDescendingOrdering(Expression expression)
NullPointerException
if the argument
expression
is null
.
The order of adding ascending and descending ordering expressions defines
the order of instances in the result collection of an executed query
instance corresponding with this query tree.addDescendingOrdering
in interface QueryTree
expression
- the order expressionjava.lang.NullPointerException
- if expression is nullpublic void setFilter(Expression filter)
NullPointerException
if the argument
filter
is null
.setFilter
in interface QueryTree
filter
- the filter expressionjava.lang.NullPointerException
- if filter is nullJDOQueryException
- if the result type of filter is a non boolean typepublic java.lang.Class getCandidateClass()
getCandidateClass
in interface QueryTree
public java.util.Map getDeclaredVariables()
VariableDeclaration
as values.getDeclaredVariables
in interface QueryTree
public java.util.Map getDeclaredParameters()
ParameterDeclaration
as values.getDeclaredParameters
in interface QueryTree
public java.util.List getDeclaredParametersAsList()
declareParameter
.
This list contains instances of
ParametersDeclaration
as entries.getDeclaredParametersAsList
in interface QueryTree
public Expression getFilter()
public java.util.List getOrderingExpressions()
addAscendingOrdering
and addDescendingOrdering
.
This list contains instances of
OrderingExpression
as entries.getOrderingExpressions
in interface QueryTree
public IdentifierExpression newIdentifier(java.lang.String identifier)
ThisExpression
or
VariableAccessExpression
or
ParameterAccessExpression
or FieldAccessExpression
depending on the fact which of the classes the argument
identifier
maps to.
This method throws NullPointerException
if the argument
identifier
is null
or the candidate class is not set.
Note: If you pass "this"
as an identifier name, then
an instance of ThisExpression
is returned. If you pass any
other java key word as an identifier name, then an instance of
JDOQueryException
is thrown.newIdentifier
in interface ExpressionFactory
identifier
- the name of the identifier access expressionjava.lang.NullPointerException
- if identifier is nullJDOQueryException
- if identifier is a java key word.public FieldAccessExpression newFieldAccess(Expression target, java.lang.String fieldName)
FieldAccessExpression
.
This method throws NullPointerException
if one of the arguments
target
or fieldName
are null
.newFieldAccess
in interface ExpressionFactory
target
- the target expression of the field access expressionfieldName
- the name of the field to accessjava.lang.NullPointerException
- if target or fieldName are nullpublic StaticFieldAccessExpression newFieldAccess(java.lang.Class clazz, java.lang.String fieldName)
StaticFieldAccessExpression
.
This method throws NullPointerException
if one of the arguments
clazz
or fieldName
are null
.newFieldAccess
in interface ExpressionFactory
clazz
- the class instance defining the fieldfieldName
- the name of the field to accessjava.lang.NullPointerException
- if clazz or fieldName are nullpublic MethodCallExpression newMethodCall(Expression target, java.lang.String methodName, Expression[] arguments)
MethodCallExpression
.
Note: If the method corresponding with methodName does not have any
arguments, then the argument arguments
is ignored.
This method throws NullPointerException
if one of the arguments
target
or methodName
are null
.newMethodCall
in interface ExpressionFactory
target
- the target expression of the method call expressionmethodName
- the name of the methodarguments
- the array of argumentsjava.lang.NullPointerException
- if target or methodName are nullJDOQueryException
- if methodName is not one of
"contains"
, "endsWith"
, "isEmpty"
or "startsWith"
.public CastExpression newCast(java.lang.Class clazz, Expression expression)
CastExpression
.
This method throws NullPointerException
if one of the arguments
clazz
or expression
are null
.newCast
in interface ExpressionFactory
clazz
- the Java class to cast the argument expression
toexpression
- the expression to castjava.lang.NullPointerException
- if expression is nullpublic ConstantExpression newConstant(java.lang.Object value)
ConstantExpression
.
This method handles null
as a constant expression.newConstant
in interface ExpressionFactory
value
- the object wrapped by the constant expressionpublic ConstantExpression newConstant(boolean b)
BooleanLiteralExpression
.newConstant
in interface ExpressionFactory
b
- the value wrapped by the boolean expressionpublic ConstantExpression newConstant(byte b)
ByteLiteralExpression
.newConstant
in interface ExpressionFactory
b
- the value wrapped by the byte expressionpublic ConstantExpression newConstant(char c)
CharLiteralExpression
.newConstant
in interface ExpressionFactory
c
- the value wrapped by the char expressionpublic ConstantExpression newConstant(double d)
DoubleLiteralExpression
.newConstant
in interface ExpressionFactory
d
- the value wrapped by the double expressionpublic ConstantExpression newConstant(float f)
FloatLiteralExpression
.newConstant
in interface ExpressionFactory
f
- the value wrapped by the float expressionpublic ConstantExpression newConstant(int i)
IntLiteralExpression
.newConstant
in interface ExpressionFactory
i
- the value wrapped by the int expressionpublic ConstantExpression newConstant(long l)
LongLiteralExpression
.newConstant
in interface ExpressionFactory
l
- the value wrapped by the long expressionpublic ConstantExpression newConstant(short s)
ShortLiteralExpression
.newConstant
in interface ExpressionFactory
s
- the value wrapped by the short expressionpublic ComplementExpression newComplement(Expression expr)
expr
.
This method throws NullPointerException
if the argument
expr
is null
.newComplement
in interface ExpressionFactory
expr
- the expression argument for the operationjava.lang.NullPointerException
- if expr is nullpublic UnaryMinusExpression newMinus(Expression expr)
expr
.
This method throws NullPointerException
if the argument
expr
is null
.newMinus
in interface ExpressionFactory
expr
- the expression argument for the operationjava.lang.NullPointerException
- if expr is nullpublic NotExpression newNot(Expression expr)
expr
.
This method throws NullPointerException
if the argument
expr
is null
.newNot
in interface ExpressionFactory
expr
- the expression argument for the operationjava.lang.NullPointerException
- if expr is nullpublic UnaryPlusExpression newPlus(Expression expr)
expr
.
This method throws NullPointerException
if the argument
expr
is null
.newPlus
in interface ExpressionFactory
expr
- the expression argument for the operationjava.lang.NullPointerException
- if expr is nullpublic AndExpression newAnd(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newAnd
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic ConditionalAndExpression newConditionalAnd(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newConditionalAnd
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic ConditionalOrExpression newConditionalOr(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newConditionalOr
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic DivideExpression newDivide(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newDivide
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic EqualsExpression newEquals(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newEquals
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic GreaterThanExpression newGreaterThan(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newGreaterThan
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic GreaterThanEqualsExpression newGreaterThanEquals(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newGreaterThanEquals
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic LessThanExpression newLessThan(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newLessThan
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic LessThanEqualsExpression newLessThanEquals(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newLessThanEquals
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic MinusExpression newMinus(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newMinus
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic NotEqualsExpression newNotEquals(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newNotEquals
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic PlusExpression newPlus(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newPlus
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic OrExpression newOr(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newOr
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic TimesExpression newTimes(Expression left, Expression right)
left
and right
.
This method throws NullPointerException
if one of the arguments
left
or right
are null
.newTimes
in interface ExpressionFactory
left
- the left expression argument for the operationright
- the right expression argument for the operationjava.lang.NullPointerException
- if left or right are nullpublic Node[] getChildren()
getChildren
in interface Node
getChildren
in class NodeImpl
JDOQueryException
- if the candidate class is not setpublic void arrive(NodeVisitor visitor)
visitor
.public java.lang.Object leave(NodeVisitor visitor, java.lang.Object[] results)
visitor
.public boolean walkNextChild(NodeVisitor visitor, java.lang.Object resultOfPreviousChild, int indexOfNextChild)
visitor
.walkNextChild
in interface Node
walkNextChild
in class NodeImpl
visitor
- the node visitorresultOfPreviousChild
- the result computed by leaving the
previous child node.indexOfNextChild
- the index of the next child nodepublic void initANTLRAST()
JDOQueryException
- if the candidate class is not setpublic java.lang.String getSerializedCandidateClassName()
Copyright © 2005-2012 Apache Software Foundation. All Rights Reserved.