Class JDOQLParser
- java.lang.Object
-
- org.datanucleus.store.query.compiler.AbstractParser
-
- org.datanucleus.store.query.compiler.JDOQLParser
-
- All Implemented Interfaces:
Parser
public class JDOQLParser extends AbstractParser
Implementation of a parser for JDOQL query language. Generates Node tree(s) by use of the various parseXXX() methods.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowSingleEqualsprivate booleanexplicitParamsprivate static java.lang.String[]jdoqlMethodNamesprivate java.util.List<java.lang.Object>parameterNameListprivate static java.lang.StringparamPrefixesCharacters that parameters can be prefixed by.-
Fields inherited from class org.datanucleus.store.query.compiler.AbstractParser
lexer, stack, strict
-
-
Constructor Summary
Constructors Constructor Description JDOQLParser()Constructor for a JDOQL Parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallowSingleEquals(boolean flag)Method to set whether "=" is allowed.private intgetPositionFromParameterName(java.lang.Object name)Nodeparse(java.lang.String expression)Node[]parseFrom(java.lang.String expression)Node[]parseOrder(java.lang.String expression)Node[][]parseParameters(java.lang.String expression)Node[]parseResult(java.lang.String expression)The RESULT expression in JDOQL can include aggregates, fields, as well as aliases myfield [AS] alias, myfield2" The Node tree for this would beNode[]parseTuple(java.lang.String expression)Node[]parseUpdate(java.lang.String expression)NodeparseVariable(java.lang.String expression)Node[][]parseVariables(java.lang.String expression)protected voidprocessAdditiveExpression()private voidprocessAndExpression()private booleanprocessArray()Method to parse an array expression ("{a,b,c}"), creating an ARRAY node with the node value being a Listof the elements. private booleanprocessCast()Parse any cast expression.private voidprocessConditionalAndExpression()This method deals with the AND condition.private voidprocessConditionalOrExpression()This method deals with the OR condition.private booleanprocessCreator()Method to parse "new a.b.c(param1[,param2], ...)" and create a Node of type CREATOR.private voidprocessExclusiveOrExpression()private NodeprocessExpression()private Node[]processFromExpression()The FROM expression in JDOQL (subquery) is a "candidate alias" expression, like mydomain.MyClass [AS] alias"private booleanprocessIdentifier()An identifier always designates a reference to a single value.private voidprocessIfElseExpression()Method to parse the query syntax for an "IF ...private voidprocessInclusiveOrExpression()protected booleanprocessLiteral()A literal is one value of any type.private booleanprocessMethod()Method to parse "methodName(param1[,param2], ...)" and create a Node of type INVOKE.protected voidprocessMultiplicativeExpression()private Node[]processOrderExpression()protected voidprocessPrimary()Parses the primary.private voidprocessRelationalExpression()Parse of an expression that is a relation between expressions.protected voidprocessUnaryExpression()voidsetExplicitParameters(boolean flag)-
Methods inherited from class org.datanucleus.store.query.compiler.AbstractParser
getLastDescendantNodeForNode, setStrict
-
-
-
-
Field Detail
-
jdoqlMethodNames
private static java.lang.String[] jdoqlMethodNames
-
explicitParams
private boolean explicitParams
-
paramPrefixes
private static java.lang.String paramPrefixes
Characters that parameters can be prefixed by.
-
allowSingleEquals
private boolean allowSingleEquals
-
parameterNameList
private java.util.List<java.lang.Object> parameterNameList
-
-
Method Detail
-
setExplicitParameters
public void setExplicitParameters(boolean flag)
- Specified by:
setExplicitParametersin interfaceParser- Overrides:
setExplicitParametersin classAbstractParser
-
allowSingleEquals
public void allowSingleEquals(boolean flag)
Method to set whether "=" is allowed. It is valid in an UPDATE clause, but not in a WHERE clause, for example.- Parameters:
flag- Whether to allow it
-
parse
public Node parse(java.lang.String expression)
-
parseVariable
public Node parseVariable(java.lang.String expression)
-
parseFrom
public Node[] parseFrom(java.lang.String expression)
-
processFromExpression
private Node[] processFromExpression()
The FROM expression in JDOQL (subquery) is a "candidate alias" expression, like- mydomain.MyClass [AS] alias"
- Returns:
- Node tree(s) for the FROM expression
-
parseUpdate
public Node[] parseUpdate(java.lang.String expression)
-
parseOrder
public Node[] parseOrder(java.lang.String expression)
-
parseResult
public Node[] parseResult(java.lang.String expression)
The RESULT expression in JDOQL can include aggregates, fields, as well as aliases- myfield [AS] alias, myfield2"
[ [IDENTIFIER : myfield. [NAME : alias]], [IDENTIFIER : myfield2] ]- Returns:
- Node tree(s) for the RESULT expression
-
parseTuple
public Node[] parseTuple(java.lang.String expression)
-
parseVariables
public Node[][] parseVariables(java.lang.String expression)
-
parseParameters
public Node[][] parseParameters(java.lang.String expression)
-
processOrderExpression
private Node[] processOrderExpression()
-
processExpression
private Node processExpression()
-
processConditionalOrExpression
private void processConditionalOrExpression()
This method deals with the OR condition. A condition specifies a combination of one or more expressions and logical (Boolean) operators and returns a value of TRUE, FALSE, or unknown
-
processConditionalAndExpression
private void processConditionalAndExpression()
This method deals with the AND condition. A condition specifies a combination of one or more expressions and logical (Boolean) operators and returns a value of TRUE, FALSE, or unknown
-
processInclusiveOrExpression
private void processInclusiveOrExpression()
-
processExclusiveOrExpression
private void processExclusiveOrExpression()
-
processAndExpression
private void processAndExpression()
-
processRelationalExpression
private void processRelationalExpression()
Parse of an expression that is a relation between expressions.
-
processAdditiveExpression
protected void processAdditiveExpression()
-
processMultiplicativeExpression
protected void processMultiplicativeExpression()
-
processUnaryExpression
protected void processUnaryExpression()
-
processPrimary
protected void processPrimary()
Parses the primary. First look for a literal (e.g. "text"), then an identifier(e.g. variable) In the next step, call a function, if executing a function, on the literal or the identifier found.
-
processIfElseExpression
private void processIfElseExpression()
Method to parse the query syntax for an "IF ... ELSE ..." expression. Creates a Node of type "CASE" with children in the orderifNode, ifActionNode [, ifNode, ifActionNode]*, elseActionNode
-
processCast
private boolean processCast()
Parse any cast expression. If a cast is found will create a Node of type CAST with the value being the class to cast to.- Returns:
- Whether a cast was processed
-
processCreator
private boolean processCreator()
Method to parse "new a.b.c(param1[,param2], ...)" and create a Node of type CREATOR. The Node at the top of the stack after this call will have any arguments defined in its "properties".- Returns:
- whether method syntax was found.
-
processMethod
private boolean processMethod()
Method to parse "methodName(param1[,param2], ...)" and create a Node of type INVOKE. The Node at the top of the stack after this call will have any arguments defined in its "properties".- Returns:
- whether method syntax was found.
-
processArray
private boolean processArray()
Method to parse an array expression ("{a,b,c}"), creating an ARRAY node with the node value being a Listof the elements. Also handles processing of subsequent "length" 'method' which is special case for arrays and not caught by processMethod() since it doesn't have "()". - Returns:
- Whether an array was parsed from the current position
-
processLiteral
protected boolean processLiteral()
A literal is one value of any type. Supported literals are of types String, Floating Point, Integer, Character, Boolean and null e.g. 'J', "String", 1, 1.8, true, false, null.- Returns:
- The parsed literal
-
processIdentifier
private boolean processIdentifier()
An identifier always designates a reference to a single value. A single value can be one collection, one field.- Returns:
- The parsed identifier
-
getPositionFromParameterName
private int getPositionFromParameterName(java.lang.Object name)
-
-