Package org.datanucleus.query.expression

Examples of org.datanucleus.query.expression.DyadicExpression


            Expression[] updateExprs = compilation.getExprUpdate();
            SQLExpression[] updateSqlExprs = new SQLExpression[updateExprs.length];
            for (int i=0;i<updateExprs.length;i++)
            {
                // "field = value"
                DyadicExpression updateExpr = (DyadicExpression)updateExprs[i];

                // Left-side has to be PrimaryExpression
                SQLExpression leftSqlExpr = null;
                if (updateExpr.getLeft() instanceof PrimaryExpression)
                {
                    processPrimaryExpression((PrimaryExpression)updateExpr.getLeft());
                    leftSqlExpr = stack.pop();
                }
                else
                {
                    throw new NucleusException("Dont currently support update clause containing left expression of type " + updateExpr.getLeft());
                }

                // Right-side can be Literal, or Parameter, or PrimaryExpression
                SQLExpression rightSqlExpr = null;
                if (updateExpr.getRight() instanceof Literal)
                {
                    processLiteral((Literal)updateExpr.getRight());
                    rightSqlExpr = stack.pop();
                }
                else if (updateExpr.getRight() instanceof ParameterExpression)
                {
                    processParameterExpression((ParameterExpression)updateExpr.getRight());
                    rightSqlExpr = stack.pop();
                }
                else if (updateExpr.getRight() instanceof PrimaryExpression)
                {
                    processPrimaryExpression((PrimaryExpression)updateExpr.getRight());
                    rightSqlExpr = stack.pop();
                }
                else if (updateExpr.getRight() instanceof DyadicExpression)
                {
                    updateExpr.getRight().evaluate(this);
                    rightSqlExpr = stack.pop();
                }
                else if (updateExpr.getRight() instanceof CaseExpression)
                {
                    updateExpr.getRight().evaluate(this);
                    rightSqlExpr = stack.pop();
                }
                else
                {
                    throw new NucleusException("Dont currently support update clause containing right expression of type " + updateExpr.getRight());
                }

                if (leftSqlExpr != null && rightSqlExpr != null)
                {
                    updateSqlExprs[i] = leftSqlExpr.eq(rightSqlExpr);
View Full Code Here


    protected Object processNegExpression(Expression expr)
    {
        Number val = null;
        if (expr instanceof DyadicExpression)
        {
            DyadicExpression dyExpr = (DyadicExpression)expr;
            if (dyExpr.getLeft() instanceof PrimaryExpression)
            {
                val = (Number)getValueForPrimaryExpression((PrimaryExpression)expr.getLeft());
            }
            else if (dyExpr.getLeft() instanceof ParameterExpression)
            {
                val = (Number)QueryUtils.getValueForParameterExpression(parameterValues, (ParameterExpression)expr.getLeft());
            }
            else
            {
                throw new NucleusException("No current support for negation of dyadic expression on type " +
                    dyExpr.getLeft().getClass().getName());
            }
        }
        else if (expr instanceof Literal)
        {
            throw new NucleusException("No current support for negation of expression of type Literal");
View Full Code Here

        if (primExpr.getLeft() != null)
        {
            // Get value of left expression
            if (primExpr.getLeft() instanceof DyadicExpression)
            {
                DyadicExpression dyExpr = (DyadicExpression)primExpr.getLeft();
                if (dyExpr.getOperator() == Expression.OP_CAST)
                {
                    Expression castLeftExpr = dyExpr.getLeft();
                    if (castLeftExpr instanceof PrimaryExpression)
                    {
                        value = getValueForPrimaryExpression((PrimaryExpression)castLeftExpr);
                        String castClassName = (String)((Literal)dyExpr.getRight()).getLiteral();
                        if (value != null)
                        {
                            // TODO Do this in the compilation stage, and check for ClassNotResolvedException
                            Class castClass = imports.resolveClassDeclaration(castClassName, clr, null);
                            if (!castClass.isAssignableFrom(value.getClass()))
                            {
                                NucleusLogger.QUERY.warn("Candidate for query results in attempt to cast " +
                                    StringUtils.toJVMIDString(value) + " to " + castClass.getName() +
                                    " which is impossible!");
                                return new InMemoryFailure();
                            }
                        }
                    }
                    else if (castLeftExpr instanceof VariableExpression)
                    {
                        value = getValueForVariableExpression((VariableExpression)castLeftExpr);
                        String castClassName = (String)((Literal)dyExpr.getRight()).getLiteral();
                        if (value != null)
                        {
                            // TODO Do this in the compilation stage, and check for ClassNotResolvedException
                            Class castClass = imports.resolveClassDeclaration(castClassName, clr, null);
                            if (!castClass.isAssignableFrom(value.getClass()))
View Full Code Here

    public static String getJDOQLForExpression(Expression expr)
    {
        if (expr instanceof DyadicExpression)
        {
            DyadicExpression dyExpr = (DyadicExpression)expr;
            Expression left = dyExpr.getLeft();
            Expression right = dyExpr.getRight();
            StringBuffer str = new StringBuffer("(");
            if (left != null)
            {
                str.append(JDOQLQueryHelper.getJDOQLForExpression(left));
            }

            // Special cases
            if (dyExpr.getOperator() == Expression.OP_AND)
            {
                str.append(" && ");
            }
            else if (dyExpr.getOperator() == Expression.OP_OR)
            {
                str.append(" || ");
            }
            else if (dyExpr.getOperator() == Expression.OP_ADD)
            {
                str.append(" + ");
            }
            else if (dyExpr.getOperator() == Expression.OP_SUB)
            {
                str.append(" - ");
            }
            else if (dyExpr.getOperator() == Expression.OP_MUL)
            {
                str.append(" * ");
            }
            else if (dyExpr.getOperator() == Expression.OP_DIV)
            {
                str.append(" / ");
            }
            else if (dyExpr.getOperator() == Expression.OP_EQ)
            {
                str.append(" = ");
            }
            else if (dyExpr.getOperator() == Expression.OP_GT)
            {
                str.append(" > ");
            }
            else if (dyExpr.getOperator() == Expression.OP_LT)
            {
                str.append(" < ");
            }
            else if (dyExpr.getOperator() == Expression.OP_GTEQ)
            {
                str.append(" >= ");
            }
            else if (dyExpr.getOperator() == Expression.OP_LTEQ)
            {
                str.append(" <= ");
            }
            else if (dyExpr.getOperator() == Expression.OP_NOTEQ)
            {
                str.append(" != ");
            }
            else
            {
                // TODO Support other operators
                throw new UnsupportedOperationException("Dont currently support operator " + dyExpr.getOperator() + " in JDOQL conversion");
            }

            if (right != null)
            {
                str.append(JDOQLQueryHelper.getJDOQLForExpression(right));
View Full Code Here

            int i = 0;
            while (expIter.hasNext())
            {
                ExpressionImpl updateExpr = expIter.next();
                ExpressionImpl updateVal  = valIter.next();
                updateExprs[i++] = new DyadicExpression(updateExpr.getQueryExpression(), Expression.OP_EQ,
                    updateVal.getQueryExpression());
            }
        }

        compilation = new QueryCompilation(candidateCls, candidateAlias, symtbl, resultExprs,
View Full Code Here

        Iterator<?> iter = coll.iterator();
        while (iter.hasNext())
        {
            PredicateImpl predSub = new PredicateImpl();
            Object obj = iter.next();
            predSub.queryExpr = new DyadicExpression(((ExpressionImpl)this).getQueryExpression(),
                org.datanucleus.query.expression.Expression.OP_EQ, new Literal(obj));
            pred.append(predSub);
        }
        return pred;
    }
View Full Code Here

        PredicateImpl pred = new PredicateImpl(BooleanOperator.OR);
        pred.queryExpr = queryExpr;
        for (int i=0;i<exprs.length;i++)
        {
            PredicateImpl predSub = new PredicateImpl();
            predSub.queryExpr = new DyadicExpression(((ExpressionImpl)this).getQueryExpression(),
                org.datanucleus.query.expression.Expression.OP_EQ,
                ((ExpressionImpl)exprs[i]).getQueryExpression());
            pred.append(predSub);
        }
        return pred;
View Full Code Here

        PredicateImpl pred = new PredicateImpl(BooleanOperator.OR);
        pred.queryExpr = queryExpr;
        for (int i=0;i<expr.length;i++)
        {
            PredicateImpl predSub = new PredicateImpl();
            predSub.queryExpr = new DyadicExpression(((ExpressionImpl)this).getQueryExpression(),
                org.datanucleus.query.expression.Expression.OP_EQ, new Literal(expr[i]));
            pred.append(predSub);
        }
        return pred;
    }
View Full Code Here

    public Predicate isNotNull()
    {
        PredicateImpl pred = new PredicateImpl();
        Literal lit = new Literal(null);
        org.datanucleus.query.expression.Expression queryExpr =
            new DyadicExpression(getQueryExpression(),
                org.datanucleus.query.expression.Expression.OP_NOTEQ,
                lit);
        pred.queryExpr = queryExpr;
        return pred;
    }
View Full Code Here

    public Predicate isNull()
    {
        PredicateImpl pred = new PredicateImpl();
        Literal lit = new Literal(null);
        org.datanucleus.query.expression.Expression queryExpr =
            new DyadicExpression(this.getQueryExpression(),
                org.datanucleus.query.expression.Expression.OP_EQ,
                lit);
        pred.queryExpr = queryExpr;
        return pred;
    }
View Full Code Here

TOP

Related Classes of org.datanucleus.query.expression.DyadicExpression

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.