Package org.datanucleus.query.symbol

Examples of org.datanucleus.query.symbol.Symbol


                {
                    if (currentExpr == null && tupple.size() > 1)
                    {
                        // Check for starting with parameter/variable
                        String first = (String)tupple.get(0);
                        Symbol firstSym = symtbl.getSymbol(first);
                        if (firstSym != null)
                        {
                            if (firstSym.getType() == Symbol.PARAMETER)
                            {
                                currentExpr = new ParameterExpression(symtbl, first, -1);
                                if (tupple.size() > 2)
                                {
                                    currentExpr = new PrimaryExpression(symtbl, currentExpr, tupple.subList(1, tupple.size()-1));
                                }
                            }
                            else if (firstSym.getType() == Symbol.VARIABLE)
                            {
                                currentExpr = new VariableExpression(symtbl, first);
                                if (tupple.size() > 2)
                                {
                                    currentExpr = new PrimaryExpression(symtbl, currentExpr, tupple.subList(1, tupple.size()-1));
                                }
                            }
                        }
                        if (currentExpr == null)
                        {
                            currentExpr = new PrimaryExpression(symtbl, tupple.subList(0, tupple.size()-1));
                        }
                    }

                    String methodName = (String)tupple.get(tupple.size()-1);
                    if (currentExpr instanceof PrimaryExpression)
                    {
                        // TODO Add plugin point to define aliases for methods for the query language
                        // ExpressionCompiler would need to know the query language name
                        String id = ((PrimaryExpression)currentExpr).getId();
                        if (id.equals("Math") || id.equals("java.lang.Math"))
                        {
                            methodName = "Math." + methodName;
                            currentExpr = null;
                        }
                        else if (id.equals("JDOHelper") || id.equals("javax.jdo.JDOHelper"))
                        {
                            methodName = "JDOHelper." + methodName;
                            currentExpr = null;
                        }
                    }
                    List parameterExprs = getExpressionsForPropertiesOfNode(currentNode);
                    currentExpr = new InvokeExpression(symtbl, currentExpr, methodName, parameterExprs);

                    currentNode = currentNode.getFirstChild();
                    tupple = new ArrayList();
                }
                else if (currentNode.getNodeType() == Node.CAST)
                {
                    if (currentExpr == null && tupple.size() > 1)
                    {
                        // Start from PrimaryExpression and invoke on that
                        currentExpr = new PrimaryExpression(symtbl, tupple.subList(0, tupple.size()-1));
                        PrimaryExpression primExpr = (PrimaryExpression)currentExpr;
                        if (primExpr.tuples.size() == 1)
                        {
                            Symbol sym = symtbl.getSymbol(primExpr.getId());
                            if (sym != null)
                            {
                                if (sym.getType() == Symbol.PARAMETER)
                                {
                                    // Parameter symbol registered for this identifier so use ParameterExpression
                                    currentExpr = new ParameterExpression(symtbl, primExpr.getId(), -1);
                                }
                                else if (sym.getType() == Symbol.VARIABLE)
                                {
                                    // Variable symbol registered for this identifier so use VariableExpression
                                    currentExpr = new VariableExpression(symtbl, primExpr.getId());
                                }
                            }
                        }
                    }

                    String className = (String)tupple.get(tupple.size()-1);
                    currentExpr = new CastExpression(symtbl, currentExpr, className);

                    currentNode = currentNode.getFirstChild();
                    tupple = new ArrayList();
                }
                else
                {
                    // Part of identifier chain
                    currentNode = currentNode.getFirstChild();
                }
            }

            if (currentExpr != null && tupple.size() > 0)
            {
                // We have a trailing identifier expression
                // e.g "((B)a).c" where we have a CastExpression and trailing "c"
                currentExpr = new PrimaryExpression(symtbl, currentExpr, tupple);
            }

            if (currentExpr == null)
            {
                // Find type of first of tupples
                String first = (String)tupple.get(0);
                Symbol firstSym = symtbl.getSymbol(first);
                if (firstSym != null)
                {
                    if (firstSym.getType() == Symbol.PARAMETER)
                    {
                        ParameterExpression paramExpr = new ParameterExpression(symtbl, first, -1);
                        if (tupple.size() > 1)
                        {
                            currentExpr = new PrimaryExpression(symtbl, paramExpr, tupple.subList(1, tupple.size()));
                        }
                        else
                        {
                            currentExpr = paramExpr;
                        }
                    }
                    else if (firstSym.getType() == Symbol.VARIABLE)
                    {
                        VariableExpression varExpr = new VariableExpression(symtbl, first);
                        if (tupple.size() > 1)
                        {
                            currentExpr = new PrimaryExpression(symtbl, varExpr, tupple.subList(1, tupple.size()));
View Full Code Here


            }
        }

        if (left != null && left instanceof VariableExpression)
        {
            Symbol leftSym = left.getSymbol();
            if (leftSym != null && leftSym.getValueType() == null)
            {
                // Set type of implicit variable
                if (right instanceof Literal && ((Literal)right).getLiteral() != null)
                {
                    leftSym.setValueType(((Literal)right).getLiteral().getClass());
                }
            }
        }
        if (right != null)
        {
            Symbol rightSym = right.getSymbol();
            if (rightSym != null && rightSym.getValueType() == null)
            {
                // Set type of implicit variable
                if (left instanceof Literal && ((Literal)left).getLiteral() != null)
                {
                    rightSym.setValueType(((Literal)left).getLiteral().getClass());
                }
            }
        }

        // Interpret types of parameters etc when used in comparison operator
View Full Code Here

    protected void applyImplicitParameterValueToCompilation(String name, Object value)
    {
        if (compilation != null)
        {
            // Check parameter existence in query, and throw exception if not in SymbolTable
            Symbol sym = compilation.getSymbolTable().getSymbol(name);
            if (sym == null)
            {
                // No parameter with this number in the query
                throw new QueryInvalidParametersException(LOCALISER.msg("021116", name));
            }
            else if (sym.getValueType() == null && value != null)
            {
                // Update the compilation providing the type of this parameter
                sym.setValueType(value.getClass());
            }
            else if (sym.getValueType() != null && value != null)
            {
                if (!QueryUtils.queryParameterTypesAreCompatible(sym.getValueType(), value.getClass()))
//                if (!sym.getValueType().isAssignableFrom(value.getClass()))
                {
                    // Parameter value supplied is not consistent with what the query compilation expects
                    throw new QueryInvalidParametersException("Parameter " + name +
                        " needs to be assignable from " + sym.getValueType().getName() +
                        " yet the value is of type " + value.getClass().getName());
                }
            }
        }
    }
View Full Code Here

                Iterator it = parameterValues.entrySet().iterator();
                while (it.hasNext())
                {
                    Map.Entry entry = (Map.Entry)it.next();
                    Object paramKey = entry.getKey();
                    Symbol sym = null;
                    if (paramKey instanceof Integer)
                    {
                        ParameterExpression expr = compilation.getParameterExpressionForPosition((Integer)paramKey);
                        if (expr != null)
                        {
                            sym = expr.getSymbol();
                        }
                    }
                    else
                    {
                        String paramName = (String)paramKey;
                        sym = symtbl.getSymbol(paramName);
                    }

                    if (sym != null)
                    {
                        Class expectedValueType = sym.getValueType();
                        if (entry.getValue() != null && expectedValueType != null &&
                            !QueryUtils.queryParameterTypesAreCompatible(expectedValueType,
                                entry.getValue().getClass()))
                        {
                            // Supplied parameter value is of inconsistent type
View Full Code Here

                // Add entries in symbol table for any joined aliases
                Node childNode = (Node)childIter.next();
                if (childNode.getNodeType() == Node.OPERATOR)
                {
                    Node joinedNode = childNode.getFirstChild();
                    Symbol joinedSym = symtbl.getSymbol((String)joinedNode.getNodeValue());
                    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);
View Full Code Here

        Node[][] node = parser.parseVariables(variables);
        for (int i = 0; i < node.length; i++)
        {
            String varName = (String) node[i][1].getNodeValue();
            Symbol varSym = symtbl.getSymbol(varName);
            if (varSym != null)
            {
                NucleusLogger.QUERY.warn(">> compileVariables param=" + varName + " but symbol already exists in table");
                varSym.setValueType(resolveClass(node[i][0].getNodeChildId()));
            }
            else
            {
                PropertySymbol sym = new PropertySymbol(varName, resolveClass(node[i][0].getNodeChildId()));
                sym.setType(Symbol.VARIABLE);
View Full Code Here

    }

    public Class getType(List tuples)
    {
        Class type = null;
        Symbol symbol = null;
        String firstTuple = (String)tuples.get(0);
        if (caseSensitiveSymbolNames())
        {
            symbol = symtbl.getSymbol(firstTuple);
        }
        else
        {
            symbol = symtbl.getSymbol(firstTuple);
            if (symbol == null)
            {
                symbol = symtbl.getSymbol(firstTuple.toUpperCase());
            }
            if (symbol == null)
            {
                symbol = symtbl.getSymbol(firstTuple.toLowerCase());
            }
        }
        if (symbol != null)
        {
            type = symbol.getValueType();
            if (type == null)
            {
                // Implicit variables don't have their type defined
                throw new NucleusUserException("Cannot find type of " + tuples.get(0) +
                    " since symbol has no type; implicit variable?");
            }

            for (int i=1; i<tuples.size(); i++)
            {
                type = getType(type, (String)tuples.get(i));
            }
        }
        else
        {
            symbol = symtbl.getSymbol(candidateAlias);
            type = symbol.getValueType();
            for (int i=0; i<tuples.size(); i++)
            {
                type = getType(type, (String)tuples.get(i));
            }
        }
View Full Code Here

            // Load subqueries into symbol table so the compilation knows about them
            Iterator<String> subqueryIter = subqueryMap.keySet().iterator();
            while (subqueryIter.hasNext())
            {
                String subqueryName = subqueryIter.next();
                Symbol sym = new PropertySymbol(subqueryName);
                sym.setType(Symbol.VARIABLE);
                symtbl.addSymbol(sym);
            }
        }

        Expression[] exprFrom = compileFrom();
View Full Code Here

            + qd.joinVariableExpression.getId() + ")");
      }
      Class<?> joinedClass = getSymbolTable().getSymbol(qd.joinVariableExpression.getId()).getValueType();
      return getMetaDataManager().getMetaDataForClass(joinedClass, getClassLoaderResolver());
    }
    Symbol sym = getSymbolTable().getSymbol(tuples.get(0));
    tuples.remove(0);
    return getMetaDataManager().getMetaDataForClass(sym.getValueType(), getClassLoaderResolver());
  }
View Full Code Here

            // Load subqueries into symbol table so the compilation knows about them
            Iterator<String> subqueryIter = subqueryMap.keySet().iterator();
            while (subqueryIter.hasNext())
            {
                String subqueryName = subqueryIter.next();
                Symbol sym = new PropertySymbol(subqueryName);
                sym.setType(Symbol.VARIABLE);
                symtbl.addSymbol(sym);
            }
        }

        compileCandidatesParametersVariables(parameters);
View Full Code Here

TOP

Related Classes of org.datanucleus.query.symbol.Symbol

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.