Package org.datanucleus.query.node

Examples of org.datanucleus.query.node.Node


        if (having == null)
        {
            return null;
        }

        Node node = parser.parse(having);
        if (candidateAliasOrig != null)
        {
            swapCandidateAliasNodeName(node);
        }
        if (parameterSubtitutionMap != null)
View Full Code Here


     */
    public Node parse(String expression)
    {
        p = new Lexer(expression, paramPrefixes, false);
        stack = new Stack();
        Node result = processExpression();

        if (p.ci.getIndex() != p.ci.getEndIndex())
        {
            // Error occurred in the JDOQL processing due to syntax error(s)
            String unparsed = p.getInput().substring(p.ci.getIndex());
View Full Code Here

        }
        if (!processIdentifier())
        {
            throw new QueryCompilerSyntaxException("expected identifier", p.getIndex(), p.getInput());
        }
        Node nodeVariable = stack.pop();
        Node nodeType = stack.pop();
        nodeType.appendChildNode(nodeVariable);
        return nodeType;
    }
View Full Code Here

        stack = new Stack();
        List nodes = new ArrayList();
        do
        {
            processExpression();
            Node node = stack.pop();

            String alias = p.parseIdentifier();
            if (alias != null && alias.equalsIgnoreCase("AS"))
            {
                alias = p.parseIdentifier();
            }
            if (alias != null)
            {
                Node aliasNode = new Node(NodeType.NAME, alias.toLowerCase()); // Save all aliases in lowercase
                node.appendChildNode(aliasNode);
            }

            nodes.add(node);
        }
View Full Code Here

        stack = new Stack();
        List nodes = new ArrayList();
        do
        {
            processExpression();
            Node node = stack.pop();
            nodes.add(node);
        }
        while (p.parseString(","));
        return (Node[])nodes.toArray(new Node[nodes.size()]);
    }
View Full Code Here

            }
            if (!processIdentifier())
            {
                throw new QueryCompilerSyntaxException("expected identifier", p.getIndex(), p.getInput());
            }
            Node nodeVariable = stack.pop();
            Node nodeType = stack.pop();
            nodes.add(new Node[]{nodeType, nodeVariable});
        }
        while (p.parseString(";"));
        return (Node[][]) nodes.toArray(new Node[nodes.size()][2]);
    }
View Full Code Here

            }
            if (!processIdentifier())
            {
                throw new QueryCompilerSyntaxException("expected identifier", p.getIndex(), p.getInput());
            }
            Node nodeVariable = stack.pop();
            Node nodeType = stack.pop();
            nodes.add(new Node[]{nodeType, nodeVariable});
        }
        while (p.parseString(","));
        return (Node[][]) nodes.toArray(new Node[nodes.size()][2]);
    }
View Full Code Here

                        p.getIndex(), p.getInput());
                }

                // Find what we are joining to
                String name = p.parseIdentifier();
                Node joinedNode = new Node(NodeType.IDENTIFIER, name);
                Node parentNode = joinedNode;
                while (p.nextIsDot())
                {
                    p.parseChar('.');
                    String subName = p.parseIdentifier();
                    Node subNode = new Node(NodeType.IDENTIFIER, subName);
                    parentNode.appendChildNode(subNode);
                    parentNode = subNode;
                }

                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("Expected: ')' but got " + p.remaining(),
                        p.getIndex(), p.getInput());
                }
                p.parseStringIgnoreCase("AS"); // Optional
                String alias = p.parseIdentifier();

                // Create candidate class node with alias, and put at top of stack
                Node classNode = new Node(NodeType.CLASS, candidateClassName);
                Node classAliasNode = new Node(NodeType.NAME, candidateAlias);
                classNode.insertChildNode(classAliasNode);
                stack.push(classNode);

                // Translate the "IN(...) alias" into the equivalent JOIN syntax nodes
                Node joinNode = new Node(NodeType.OPERATOR, "JOIN_INNER");
                joinNode.appendChildNode(joinedNode);
                Node joinAliasNode = new Node(NodeType.NAME, alias);
                joinNode.appendChildNode(joinAliasNode);
                classNode.appendChildNode(joinNode);

                // Include any joins for this expression
                processFromJoinExpression();

                nodes.add(classNode);
            }
            else
            {
                // "candidate [AS] alias"
                // This will create a node of type "Node.CLASS" and child of type "Node.NAME" (alias)
                // Any JOINs will be child nodes of type "Node.OPERATOR"
                processExpression();
                Node id = stack.pop();
                StringBuilder className = new StringBuilder(id.getNodeValue().toString());
                while (id.getChildNodes().size() > 0)
                {
                    id = id.getFirstChild();
                    className.append(".").append(id.getNodeValue().toString());
                }

                String alias = p.parseIdentifier();
                if (alias != null && alias.equalsIgnoreCase("AS"))
                {
                    alias = p.parseIdentifier();
                }
                if (candidateClassName == null)
                {
                    candidateClassName = className.toString();
                    candidateAlias = alias;
                }

                // Create candidate class node with alias, and put at top of stack
                Node classNode = new Node(NodeType.CLASS, className.toString());
                Node aliasNode = new Node(NodeType.NAME, alias);
                classNode.insertChildNode(aliasNode);
                stack.push(classNode);

                // Include any joins for this expression
                processFromJoinExpression();
View Full Code Here

     * 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.
     */
    private void processFromJoinExpression()
    {
        Node candidateNode = stack.pop();
        boolean moreJoins = true;
        while (moreJoins)
        {
            // Check for JOIN syntax "[LEFT [OUTER] | INNER] JOIN ..."  (EJB3 syntax)
            boolean leftJoin = false;
            boolean innerJoin = false;
            if (p.parseStringIgnoreCase("INNER "))
            {
                innerJoin = true;
            }
            else if (p.parseStringIgnoreCase("LEFT "))
            {
                //optional and useless (for parser) outer keyword
                p.parseStringIgnoreCase("OUTER");
                leftJoin = true;
            }

            if (p.parseStringIgnoreCase("JOIN "))
            {
                if (!innerJoin && !leftJoin)
                {
                    innerJoin = true;
                }
                // Process the join
                boolean fetch = false;
                if (p.parseStringIgnoreCase("FETCH"))
                {
                    fetch = true;
                }

                // Find what we are joining to
                String id = p.parseIdentifier();
                Node joinedNode = new Node(NodeType.IDENTIFIER, id);
                Node parentNode = joinedNode;
                while (p.nextIsDot())
                {
                    p.parseChar('.');
                    Node subNode = new Node(NodeType.IDENTIFIER, p.parseName());
                    parentNode.appendChildNode(subNode);
                    parentNode = subNode;
                }

                // And the alias we know this joined field by
                p.parseStringIgnoreCase("AS "); // Optional
                String alias = p.parseName();

                String joinType = "JOIN_INNER";
                if (innerJoin)
                {
                    joinType = (fetch ? "JOIN_INNER_FETCH" : "JOIN_INNER");
                }
                else if (leftJoin)
                {
                    joinType = (fetch ? "JOIN_OUTER_FETCH" : "JOIN_OUTER");
                }
                Node joinNode = new Node(NodeType.OPERATOR, joinType);
                joinNode.appendChildNode(joinedNode);
                Node joinedAliasNode = new Node(NodeType.NAME, alias);
                joinNode.appendChildNode(joinedAliasNode);
                candidateNode.appendChildNode(joinNode);
            }
            else
            {
View Full Code Here

        do
        {
            processExpression();
            if (p.parseStringIgnoreCase("asc"))
            {
                Node expr = new Node(NodeType.OPERATOR, "ascending");
                stack.push(expr);
            }
            else if (p.parseStringIgnoreCase("desc"))
            {
                Node expr = new Node(NodeType.OPERATOR, "descending");
                stack.push(expr);
            }
            else
            {
                // Default to ascending
                Node expr = new Node(NodeType.OPERATOR, "ascending");
                stack.push(expr);
            }

            Node expr = new Node(NodeType.OPERATOR, "order");
            expr.insertChildNode(stack.pop());
            if (!stack.empty())
            {
                expr.insertChildNode(stack.pop());
            }
            nodes.add(expr);
        }
        while (p.parseString(","));
        return (Node[]) nodes.toArray(new Node[nodes.size()]);
View Full Code Here

TOP

Related Classes of org.datanucleus.query.node.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.