Package org.datanucleus.query.node

Examples of org.datanucleus.query.node.Node


     * executing a function, on the literal or the identifier found.
     */
    protected void processPrimary()
    {
        String subqueryKeyword = null;
        Node subqueryNode = null;

        if (p.parseStringIgnoreCase("SOME "))
        {
            subqueryKeyword = "SOME";
            processExpression(); // subquery variable
            subqueryNode = stack.pop();
        }
        else if (p.parseStringIgnoreCase("ALL "))
        {
            subqueryKeyword = "ALL";
            processExpression(); // subquery variable
            subqueryNode = stack.pop();
        }
        else if (p.parseStringIgnoreCase("ANY "))
        {
            subqueryKeyword = "ANY";
            processExpression(); // subquery variable
            subqueryNode = stack.pop();
        }
        else if (p.parseStringIgnoreCase("EXISTS "))
        {
            subqueryKeyword = "EXISTS";
            processExpression(); // subquery variable
            subqueryNode = stack.pop();
        }
        if (subqueryKeyword != null && subqueryNode != null)
        {
            Node subNode = new Node(NodeType.SUBQUERY, subqueryKeyword);
            subNode.appendChildNode(subqueryNode);
            stack.push(subNode);
            return;
        }

        if (p.parseStringIgnoreCase("CURRENT_DATE"))
        {
            // Convert to a method call
            Node node = new Node(NodeType.INVOKE, "CURRENT_DATE");
            stack.push(node);
            return;
        }
        else if (p.parseStringIgnoreCase("CURRENT_TIMESTAMP"))
        {
            // Convert to a method call
            Node node = new Node(NodeType.INVOKE, "CURRENT_TIMESTAMP");
            stack.push(node);
            return;
        }
        else if (p.parseStringIgnoreCase("CURRENT_TIME"))
        {
            // Convert to a method call
            Node node = new Node(NodeType.INVOKE, "CURRENT_TIME");
            stack.push(node);
            return;
        }
        else if (p.parseStringIgnoreCase("CASE "))
        {
            processCaseExpression();
            return;
        }
        else if (p.parseStringIgnoreCase("DISTINCT "))
        {
            // Aggregates can have "count(DISTINCT field1)"
            Node distinctNode = new Node(NodeType.OPERATOR, "DISTINCT");
            processExpression();
            Node identifierNode = stack.pop();
            distinctNode.appendChildNode(identifierNode);
            stack.push(distinctNode);
            return;
        }
        else if (processCreator() || processLiteral() || processMethod())
        {
            return;
        }

        if (p.parseChar('('))
        {
            processExpression();
            if (!p.parseChar(')'))
            {
                throw new QueryCompilerSyntaxException("expected ')'", p.getIndex(), p.getInput());
            }
            return;
        }

        // if primary == null, literal not found...
        // We will have an identifier (variable, parameter, or field of candidate class)
        if (!processIdentifier())
        {
            throw new QueryCompilerSyntaxException("Identifier expected", p.getIndex(), p.getInput());
        }
        int size = stack.size();

        // Generate Node tree, including chained operations
        // e.g identifier.methodX().methodY().methodZ()
        //     -> node (IDENTIFIER) with child (INVOKE), with child (INVOKE), with child (INVOKE)
        // e.g identifier.fieldX.fieldY.fieldZ
        //     -> node (IDENTIFIER) with child (IDENTIFIER), with child (IDENTIFIER), with child (IDENTIFIER)
        while (p.parseChar('.'))
        {
            if (processMethod())
            {
                // "a.method(...)"
            }
            else if (processIdentifier())
            {
                // "a.field"
            }
            else
            {
                throw new QueryCompilerSyntaxException("Identifier expected", p.getIndex(), p.getInput());
            }
        }

        // For all added nodes, step back and chain them so we have
        // Node[IDENTIFIER, a]
        // +--- Node[IDENTIFIER, b]
        //      +--- Node[IDENTIFIER, c]
        while (stack.size() > size)
        {
            Node top = stack.pop();
            Node peek = stack.peek();
            peek.insertChildNode(top);
        }
    }
View Full Code Here


                    }
                }
            }
            while (stack.size() - 1 > size)
            {
                Node top =  stack.pop();
                Node peek = stack.peek();
                peek.insertChildNode(top);
            }
            Node node = stack.pop();
            Node newNode = new Node(NodeType.CREATOR);
            newNode.insertChildNode(node);
            stack.push(newNode);
            return true;
        }
        return false;
    }
View Full Code Here

                return true;
            }
            else if (method.equalsIgnoreCase("MOD"))
            {
                // Convert to be {first} % {second}
                Node modNode = new Node(NodeType.OPERATOR, "%");
                processExpression(); // argument 1
                Node firstNode = stack.pop();
                if (!p.parseChar(','))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }
                processExpression(); // argument 2
                Node secondNode = stack.pop();
                modNode.appendChildNode(firstNode);
                modNode.appendChildNode(secondNode);
                stack.push(modNode);
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("')' expected", p.getIndex(), p.getInput());
                }
                return true;
            }
            else if (method.equalsIgnoreCase("TYPE"))
            {
                // Convert to a TYPE node with the primary as a child node
                Node typeNode = new Node(NodeType.TYPE);
                processExpression(); // argument
                Node typePrimaryNode = stack.pop();
                typeNode.appendChildNode(typePrimaryNode);
                stack.push(typeNode);
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("')' expected", p.getIndex(), p.getInput());
                }
                return true;
            }
            else if (method.equalsIgnoreCase("SUBSTRING"))
            {
                // SUBSTRING(string_primary, simple_arithmetic_expression[, simple_arithmetic_expression])
                // Convert to be {primary}.INVOKE(substring, {arg1[, arg2]})
                Node invokeNode = new Node(NodeType.INVOKE, "substring");
                processExpression();
                Node primaryNode = stack.pop();
                if (!p.parseChar(','))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                // First arg to substring(...) has origin 0, but JPQL has origin 1!
                processExpression();
                Node arg1 = stack.pop();
                Node oneNode = new Node(NodeType.LITERAL, 1);
                Node arg1Node = new Node(NodeType.OPERATOR, "-");
                arg1Node.insertChildNode(arg1);
                arg1Node.appendChildNode(oneNode);

                if (p.parseChar(','))
                {
                    // String.substring(arg1, arg2)
                    // Second arg to substring(...) has origin 0, but in JPQL is length of result!
                    processExpression();
                    Node arg2 = stack.pop();
                    Node arg2Node = new Node(NodeType.OPERATOR, "+");
                    arg2Node.appendChildNode(arg2);
                    arg2Node.appendChildNode(arg1Node);
                    if (!p.parseChar(')'))
                    {
                        throw new QueryCompilerSyntaxException("')' expected", p.getIndex(), p.getInput());
                    }

                    primaryNode.appendChildNode(invokeNode);
                    invokeNode.addProperty(arg1Node);
                    invokeNode.addProperty(arg2Node);
                    stack.push(primaryNode);
                    return true;
                }
                else if (p.parseChar(')'))
                {
                    // String.substring(arg1)
                    primaryNode.appendChildNode(invokeNode);
                    invokeNode.addProperty(arg1Node);
                    stack.push(primaryNode);
                    return true;
                }
                else
                {
                    throw new QueryCompilerSyntaxException("')' expected", p.getIndex(), p.getInput());
                }
            }
            else if (method.equalsIgnoreCase("UPPER"))
            {
                // UPPER(string_primary)
                // Convert to be {primary}.INVOKE(toUpper)
                Node invokeNode = new Node(NodeType.INVOKE, "toUpperCase");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop();
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("LOWER"))
            {
                // UPPER(string_primary)
                // Convert to be {primary}.INVOKE(toLower)
                Node invokeNode = new Node(NodeType.INVOKE, "toLowerCase");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop();
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("LENGTH"))
            {
                // LENGTH(string_primary)
                // Convert to be {primary}.INVOKE(length)
                Node invokeNode = new Node(NodeType.INVOKE, "length");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop();
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("CONCAT"))
            {
                // CONCAT(string_primary, string_primary[, string_primary])
                // Convert to be {primary1}+{primary2}[+primary3]
                processExpression();
                Node prevNode = stack.pop();

                while (true)
                {
                    if (!p.parseChar(','))
                    {
                        throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                    }

                    processExpression();
                    Node thisNode = stack.pop();

                    Node currentNode = new Node(NodeType.OPERATOR, "+");
                    currentNode.appendChildNode(prevNode);
                    currentNode.appendChildNode(thisNode);
                    if (p.parseChar(')'))
                    {
                        stack.push(currentNode);
                        return true;
                    }
                    prevNode = currentNode;
                    currentNode = null;
                }
            }
            else if (method.equalsIgnoreCase("LOCATE"))
            {
                // LOCATE(string_primary, string_primary[, simple_arithmetic_expression])
                // Convert to ({stringExpr}.indexOf(strExpr[, posExpr]) + 1)
                processExpression();
                Node searchNode = stack.pop();
                Node invokeNode = new Node(NodeType.INVOKE, "indexOf");
                invokeNode.addProperty(searchNode);
                if (!p.parseChar(','))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                processExpression();
                Node primaryNode = stack.pop();
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);

                Node oneNode = new Node(NodeType.LITERAL, 1);
                if (p.parseChar(','))
                {
                    processExpression();
                    Node fromPosNode = stack.pop();
                    Node positionNode = new Node(NodeType.OPERATOR, "-");
                    positionNode.appendChildNode(fromPosNode);
                    positionNode.appendChildNode(oneNode);
                    invokeNode.addProperty(positionNode);
                }
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("')' expected", p.getIndex(), p.getInput());
                }

                Node locateNode = new Node(NodeType.OPERATOR, "+");
                locateNode.appendChildNode(primaryRootNode);
                locateNode.appendChildNode(oneNode);
                stack.push(locateNode);
                return true;
            }
            else if (method.equalsIgnoreCase("TRIM"))
            {
                // TRIM([[LEADING | TRAILING | BOTH] [trim_character] FROM] string_primary)
                // Convert to be {primary}.INVOKE(trim|trimLeft|trimRight, [{trimChar}])
                String methodName = "trim";
                if (p.parseStringIgnoreCase("LEADING"))
                {
                    methodName = "trimLeft";
                }
                else if (p.parseStringIgnoreCase("TRAILING"))
                {
                    methodName = "trimRight";
                }
                else if (p.parseStringIgnoreCase("BOTH"))
                {
                    // Default
                }
                Node invokeNode = new Node(NodeType.INVOKE, methodName);

                Node trimCharNode = null;
                processExpression();
                Node next = stack.pop();
                if (p.parseChar(')'))
                {
                    // TRIM(string_primary)
                    next.appendChildNode(invokeNode);
                    stack.push(next);
                    return true;
                }
                else
                {
                    if (next.getNodeType() == NodeType.LITERAL)
                    {
                        // TRIM(dir trimChar FROM string_primary)
                        trimCharNode = next;
                        if (p.parseStringIgnoreCase("FROM "))
                        {
                            // Ignore the FROM
                        }
                        processExpression();
                        next = stack.pop();
                    }
                    else if (next.getNodeType() == NodeType.IDENTIFIER)
                    {
                        // TRIM(dir FROM string_primary)
                        Object litValue = next.getNodeValue();
                        if (litValue instanceof String && ((String)litValue).equals("FROM"))
                        {
                            // FROM so ignore
                            processExpression(); // field expression that we are trimming
                            next = stack.pop();
                        }
                        else
                        {
                            throw new QueryCompilerSyntaxException("Unexpected expression", p.getIndex(), p.getInput());
                        }
                    }
                    else
                    {
                        // No "trimChar" or FROM, so "next" is the string expression node
                    }

                    if (!p.parseChar(')'))
                    {
                        throw new QueryCompilerSyntaxException("')' expected", p.getIndex(), p.getInput());
                    }

                    next.appendChildNode(invokeNode);
                    if (trimCharNode != null)
                    {
                        invokeNode.addProperty(trimCharNode);
                    }
                    stack.push(next);
                    return true;
                }
            }
            else if (method.equalsIgnoreCase("SIZE"))
            {
                // SIZE(collection_valued_path_expression)
                // Convert to be {primary}.INVOKE(size)
                Node invokeNode = new Node(NodeType.INVOKE, "size");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Collection/Map/array)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("KEY"))
            {
                // KEY(identification_variable)
                // Convert to be {primary}.INVOKE(mapKey)
                Node invokeNode = new Node(NodeType.INVOKE, "mapKey");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Map)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("VALUE"))
            {
                // VALUE(identification_variable)
                // Convert to be {primary}.INVOKE(mapValue)
                Node invokeNode = new Node(NodeType.INVOKE, "mapValue");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Map)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("ENTRY"))
            {
                // ENTRY(identification_variable)
                // Convert to be {primary}.INVOKE(mapEntry)
                Node invokeNode = new Node(NodeType.INVOKE, "mapEntry");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Map)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("YEAR"))
            {
                // Extension MONTH - Convert to be {primary}.INVOKE(getYear)
                Node invokeNode = new Node(NodeType.INVOKE, "getYear");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Date)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("MONTH"))
            {
                // Extension MONTH - Convert to be {primary}.INVOKE(getMonth)
                Node invokeNode = new Node(NodeType.INVOKE, "getMonth");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Date)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("DAY"))
            {
                // Extension DAY - Convert to be {primary}.INVOKE(getDay)
                Node invokeNode = new Node(NodeType.INVOKE, "getDay");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Date)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("HOUR"))
            {
                // Extension HOUR - Convert to be {primary}.INVOKE(getHour)
                Node invokeNode = new Node(NodeType.INVOKE, "getHour");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Date)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("MINUTE"))
            {
                // Extension MINUTE - Convert to be {primary}.INVOKE(getMinute)
                Node invokeNode = new Node(NodeType.INVOKE, "getMinute");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Date)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else if (method.equalsIgnoreCase("SECOND"))
            {
                // Extension SECOND - Convert to be {primary}.INVOKE(getSecond)
                Node invokeNode = new Node(NodeType.INVOKE, "getSecond");
                processExpression();
                if (!p.parseChar(')'))
                {
                    throw new QueryCompilerSyntaxException("',' expected", p.getIndex(), p.getInput());
                }

                Node primaryNode = stack.pop(); // Could check type ? (Date)
                Node primaryRootNode = primaryNode;
                while (primaryNode.getFirstChild() != null)
                {
                    primaryNode = primaryNode.getFirstChild();
                }
                primaryNode.appendChildNode(invokeNode);
                stack.push(primaryRootNode);
                return true;
            }
            else
            {
                // Found syntax for a method, so invoke the method
                // TODO What if the method is not supported for JPQL?
                Node node = new Node(NodeType.INVOKE, method);
                if (!p.parseChar(')'))
                {
                    do
                    {
                        // Argument for the method call, add as a node property
                        processExpression();
                        node.addProperty(stack.pop());
                    }
                    while (p.parseChar(','));

                    if (!p.parseChar(')'))
                    {
View Full Code Here

        else
        {
            return false;
        }

        stack.push(new Node(NodeType.LITERAL, litValue));
        return true;
    }
View Full Code Here

                throw new QueryInvalidParametersException("Query is using named parameters yet also has \"" + id + "\"");
            }
            String paramName = id.substring(1);
            try
            {
                Node node = new ParameterNode(NodeType.PARAMETER, Integer.valueOf(paramName), parameterPosition);
                parameterPosition++;
                stack.push(node);
                return true;
            }
            catch (NumberFormatException nfe)
            {
                throw new NucleusUserException("Numbered parameter syntax starting ? but isnt followed by numeric!");
            }
        }
        else if (first == ':')
        {
            // Named parameter - stored as String
            if (paramType == null)
            {
                paramType = ParameterType.NAMED;
            }
            else if (paramType == ParameterType.NUMBERED)
            {
                throw new QueryInvalidParametersException("Query is using numbered parameters yet also has \"" + id + "\"");
            }
            Node node = new ParameterNode(NodeType.PARAMETER, id.substring(1), parameterPosition);
            parameterPosition++;
            stack.push(node);
            return true;
        }
        else
        {
            Node node = new Node(NodeType.IDENTIFIER, id);
            stack.push(node);
            return true;
        }
    }
View Full Code Here

            }

            List children = node[i].getChildNodes();
            for (int j=0;j<children.size();j++)
            {
                Node child = (Node)children.get(j);
                if (child.getNodeType() == NodeType.NAME) // Alias - maybe should assume it is the first child
                {
                    classAlias = (String)child.getNodeValue();
                }
            }

            if (i == 0 && classAlias == null)
            {
                throw new QueryCompilerSyntaxException("FROM clause of query has class " + cls.getName() + " but no alias");
            }

            if (classAlias != null)
            {
                if (i == 0)
                {
                    // First expression so set up candidateClass/alias
                    candidateClass = cls;
                    if (parentCompiler != null && parentCompiler.candidateAlias.equals(classAlias))
                    {
                        // The defined alias is the same as the parent query, so rename
                        candidateAliasOrig = classAlias;
                        candidateAlias = "sub_" + candidateAlias;
                        classAlias = candidateAlias;
                        swapCandidateAliasNodeName(node[i].getChildNode(0));
                    }
                    else
                    {
                        candidateAlias = classAlias;
                    }
                }
                if (symtbl.getSymbol(classAlias) == null)
                {
                    // Add symbol for this candidate under its alias
                    symtbl.addSymbol(new PropertySymbol(classAlias, cls));
                }
            }

            Iterator childIter = node[i].getChildNodes().iterator();
            while (childIter.hasNext())
            {
                // Add entries in symbol table for any joined aliases
                Node childNode = (Node)childIter.next();
                if (childNode.getNodeType() == NodeType.OPERATOR)
                {
                    Node joinedNode = childNode.getFirstChild();
                    String joinedAlias = (String)joinedNode.getNodeValue();
                    Symbol joinedSym =
                        (caseSensitiveAliases ? symtbl.getSymbol(joinedAlias) : symtbl.getSymbolIgnoreCase(joinedAlias));
                    if (joinedSym == null)
                    {
                        throw new QueryCompilerSyntaxException("FROM clause has identifier " + joinedNode.getNodeValue() + " but this is unknown");
                    }
                    AbstractClassMetaData joinedCmd = metaDataManager.getMetaDataForClass(joinedSym.getValueType(), clr);
                    Class joinedCls = joinedSym.getValueType();
                    while (joinedNode.getFirstChild() != null)
                    {
                        joinedNode = joinedNode.getFirstChild();
                        String joinedMember = (String)joinedNode.getNodeValue();
                        AbstractMemberMetaData mmd = joinedCmd.getMetaDataForMember(joinedMember);
                        if (mmd == null)
                        {
                            throw new QueryCompilerSyntaxException("FROM clause has reference to " + joinedCmd.getFullClassName() + "." + joinedMember + " but it doesn't exist!");
                        }

                        int relationType = mmd.getRelationType(clr);
                        switch (relationType)
                        {
                            case Relation.ONE_TO_ONE_UNI:
                            case Relation.ONE_TO_ONE_BI:
                            case Relation.MANY_TO_ONE_BI:
                                joinedCls = mmd.getType();
                                joinedCmd = metaDataManager.getMetaDataForClass(joinedCls, clr);
                                break;
                            case Relation.ONE_TO_MANY_UNI:
                            case Relation.ONE_TO_MANY_BI:
                            case Relation.MANY_TO_MANY_BI:
                                if (mmd.hasCollection())
                                {
                                    // TODO Don't currently allow interface field navigation
                                    joinedCmd = mmd.getCollection().getElementClassMetaData(clr, metaDataManager);
                                    joinedCls = clr.classForName(joinedCmd.getFullClassName());
                                }
                                else if (mmd.hasArray())
                                {
                                    // TODO Don't currently allow interface field navigation
                                    joinedCmd = mmd.getArray().getElementClassMetaData(clr, metaDataManager);
                                    joinedCls = clr.classForName(joinedCmd.getFullClassName());
                                }
                                break;
                            default:
                                break;
                        }
                    }

                    Node aliasNode = childNode.getNextChild();
                    if (aliasNode.getNodeType() == NodeType.NAME)
                    {
                        symtbl.addSymbol(new PropertySymbol((String)aliasNode.getNodeValue(), joinedCls));
                    }
                }
            }

            boolean classIsExpression = false;
View Full Code Here

    public Expression compileFilter()
    {
        if (filter != null)
        {
            // Generate the node tree for the filter
            Node node = parser.parse(filter);
            if (candidateAliasOrig != null)
            {
                swapCandidateAliasNodeName(node);
            }
            if (parameterSubtitutionMap != null)
View Full Code Here

                }
                break;
            case OPERATOR :
                while (node.hasNextChild())
                {
                    Node childNode = node.getNextChild();
                    swapCandidateAliasNodeName(childNode);
                }
                break;
            case INVOKE :
                if (node.hasProperties())
                {
                    Iterator<Node> propIter = node.getProperties().iterator();
                    while (propIter.hasNext())
                    {
                        Node propNode = propIter.next();
                        swapCandidateAliasNodeName(propNode);
                    }
                }
                break;
            case CAST :
                Node childNode = node.getChildNode(0);
                swapCandidateAliasNodeName(childNode);
                break;
            case NAME :
                if (node.getNodeValue().equals(candidateAliasOrig))
                {
View Full Code Here

        if (node == null || parameterSubtitutionMap == null)
        {
            return null;
        }

        Node swapNode = null;
        switch (node.getNodeType())
        {
            case PARAMETER :
                // Swap the parameter for node(s) for the value
                Object paramName = node.getNodeValue();
                if (parameterSubtitutionMap.containsKey(paramName))
                {
                    String paramValue = parameterSubtitutionMap.get(paramName);
                    swapNode = parser.parse(paramValue);
                }
                else
                {
                    // Positional subquery parameters, starting at 0
                    String paramValue = parameterSubtitutionMap.get(Integer.valueOf(parameterSubstitutionNumber++));
                    swapNode = parser.parse(paramValue);
                }
                return swapNode;
            case OPERATOR :
                List childNodes = node.getChildNodes();
                for (int i=0;i<childNodes.size();i++)
                {
                    Node swappedNode = swapSubqueryParameters((Node) childNodes.get(i));
                    node.removeChildNode((Node) childNodes.get(i));
                    node.insertChildNode(swappedNode, i);
                }
                break;
            case INVOKE :
                if (node.hasProperties())
                {
                    List<Node> propNodes = node.getProperties();
                    for (int i=0;i<propNodes.size();i++)
                    {
                        Node propNode = propNodes.get(i);
                        swapNode = swapSubqueryParameters(propNode);
                        if (swapNode != propNode)
                        {
                            node.setPropertyAtPosition(i, swapNode);
                        }
View Full Code Here

            ExpressionCompiler comp = new ExpressionCompiler();
            comp.setSymbolTable(symtbl);
            comp.setMethodAliases(queryMethodAliasByPrefix);

            String alias = null;
            Node aliasNode = null;
            while (node[i].hasNextChild())
            {
                Node childNode = node[i].getNextChild();
                if (childNode.getNodeType() == NodeType.NAME)
                {
                    // Alias node
                    aliasNode = childNode;
                }
            }
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.