Class JPQLParser

  • All Implemented Interfaces:
    Parser

    public class JPQLParser
    extends AbstractParser
    Implementation of a parser for JPQL query language. Generates Node tree(s) by use of the various parseXXX() methods.
    • Field Detail

      • paramPrefixes

        private static java.lang.String paramPrefixes
        Characters that parameters can be prefixed by.
      • parameterPosition

        int parameterPosition
    • Constructor Detail

      • JPQLParser

        public JPQLParser()
        Constructor for a JPQL Parser.
    • Method Detail

      • parse

        public Node parse​(java.lang.String expression)
      • parseVariable

        public Node parseVariable​(java.lang.String expression)
      • parseFrom

        public Node[] parseFrom​(java.lang.String 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)
      • parseTuple

        public Node[] parseTuple​(java.lang.String expression)
      • parseVariables

        public Node[][] parseVariables​(java.lang.String expression)
      • parseParameters

        public Node[][] parseParameters​(java.lang.String expression)
      • processFromExpression

        private Node[] processFromExpression()
        The FROM expression in JPQL is a comma-separated list of expressions. Each expression can be
        • "IN {expression} [AS] alias [JOIN ... AS ...]"
        • mydomain.MyClass [AS] alias [JOIN ... AS ...]"
        Returns:
        Node tree(s) for the FROM expression
      • processFromJoinExpression

        private void processFromJoinExpression()
        Convenience method to process what remains of a component of the FROM clause, processing the JOIN conditions. The leading part (candidate, or "IN") was processed just before. This will append a child to the candidate node for each join condition encountered. For example, "org.datanucleus.MyClass p INNER JOIN p.myField AS f" will translate to
         Node(CLASS, "org.datanucleus.MyClass)
         +--- Node(NAME, "p")
         +--- Node(OPERATOR, "JOIN_INNER")
            +--- Node(IDENTIFIER, "p.myField")
            +--- Node(NAME, "f")
            +--- Node(OPERATOR, "==")       <====== ON condition
               +--- Node(IDENTIFIER, "f.someField")
               +--- Node(NAME, "value")
         
        When we enter this method we expect the candidate node to be at the top of the stack, and when we leave this method we leave the candidate node at the top of the stack.
      • processOrderExpression

        private Node[] processOrderExpression()
      • processExpression

        private Node processExpression()
      • processOrExpression

        private void processOrExpression()
        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
      • processAndExpression

        private void processAndExpression()
        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.
      • processRelationalExpression

        private void processRelationalExpression()
        Parse of an expression that is a relation between expressions.
      • processLikeExpression

        private void processLikeExpression()
        Convenience handler to parse a LIKE expression. Expression is of the form "{expression} LIKE {pattern_value} [ESCAPE {escape_char}]". Requires that the node at the top of the stack is the field expression node. Returns "{primaryNode}.INVOKE("matches", (likeExprNode))"
      • processInExpression

        private void processInExpression​(boolean not)
        Convenience handler to parse an IN expression. Expression is typically of the form "{expression} IN (expr1 [,expr2 [,expr3]] | subquery)". Can generate a node tree like
        ({expression} == expr1) || ({expression} == expr2) || ({expression} == expr3)
        depending on the precise situation.
        Parameters:
        not - Whether this is an expression "NOT IN"
      • processMemberExpression

        private void processMemberExpression​(boolean not)
        Convenience handler to parse an MEMBER expression. Expression is of the form "{expr1} MEMBER [OF] expr2".
        Parameters:
        not - Whether this is an expression "NOT MEMBER"
      • processCaseExpression

        private void processCaseExpression()
        Method to parse the query syntax for a CASE expression. Creates a Node of type "CASE" with children in the order
        whenNode, actionNode [, whenNode, actionNode]*, elseNode
      • 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.
      • 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.
      • processEntry

        protected boolean processEntry()
        Process an ENTRY construct. Puts the ENTRY Node on the stack.
        Returns:
        Whether a ENTRY construct was found by the lexer.
      • processKey

        protected boolean processKey()
        Process for a KEY construct. Puts the KEY Node on the stack if one is found.
        Returns:
        Whether a KEY construct was found by the lexer.
      • processValue

        protected boolean processValue()
        Process for a VALUE construct. Puts the VALUE Node on the stack if one is found.
        Returns:
        Whether a VALUE construct was found by the lexer.
      • 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.
      • processTreat

        protected boolean processTreat()
        Process a TREAT construct, and put the node on the stack.
        Returns:
        Whether TREAT was found by the lexer.
      • 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. Also supports JDBC "escape syntax" for literals.
        Returns:
        The compiled 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 compiled identifier