Search in sources :

Example 41 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class MapExpressionImpl method containsEntry.

/* (non-Javadoc)
     * @see org.datanucleus.query.typesafe.MapExpression#containsEntry(java.util.Map.Entry)
     */
public BooleanExpression containsEntry(Entry<K, V> entry) {
    List<org.datanucleus.query.expression.Expression> args = new ArrayList();
    args.add(new Literal(entry));
    org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "containsEntry", args);
    return new BooleanExpressionImpl(invokeExpr);
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) NumericExpression(javax.jdo.query.NumericExpression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) PersistableExpression(javax.jdo.query.PersistableExpression) MapExpression(javax.jdo.query.MapExpression) BooleanExpression(javax.jdo.query.BooleanExpression) Expression(javax.jdo.query.Expression) Literal(org.datanucleus.query.expression.Literal) ArrayList(java.util.ArrayList)

Example 42 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class MapExpressionImpl method containsValue.

/* (non-Javadoc)
     * @see org.datanucleus.query.typesafe.MapExpression#containsValue(java.lang.Object)
     */
public BooleanExpression containsValue(V value) {
    List<org.datanucleus.query.expression.Expression> args = new ArrayList();
    args.add(new Literal(value));
    org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "containsValue", args);
    return new BooleanExpressionImpl(invokeExpr);
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) NumericExpression(javax.jdo.query.NumericExpression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) PersistableExpression(javax.jdo.query.PersistableExpression) MapExpression(javax.jdo.query.MapExpression) BooleanExpression(javax.jdo.query.BooleanExpression) Expression(javax.jdo.query.Expression) Literal(org.datanucleus.query.expression.Literal) ArrayList(java.util.ArrayList)

Example 43 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class MapExpressionImpl method containsKey.

/* (non-Javadoc)
     * @see org.datanucleus.query.typesafe.MapExpression#containsKey(java.lang.Object)
     */
public BooleanExpression containsKey(K key) {
    List<org.datanucleus.query.expression.Expression> args = new ArrayList();
    args.add(new Literal(key));
    org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "containsKey", args);
    return new BooleanExpressionImpl(invokeExpr);
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) NumericExpression(javax.jdo.query.NumericExpression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) PersistableExpression(javax.jdo.query.PersistableExpression) MapExpression(javax.jdo.query.MapExpression) BooleanExpression(javax.jdo.query.BooleanExpression) Expression(javax.jdo.query.Expression) Literal(org.datanucleus.query.expression.Literal) ArrayList(java.util.ArrayList)

Example 44 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class AbstractJDOQLTypedQuery method getJDOQLForExpression.

public String getJDOQLForExpression(Expression expr) {
    if (expr instanceof DyadicExpression) {
        DyadicExpression dyExpr = (DyadicExpression) expr;
        Expression left = dyExpr.getLeft();
        Expression right = dyExpr.getRight();
        StringBuilder str = new StringBuilder("(");
        if (dyExpr.getOperator() == Expression.OP_DISTINCT) {
            // Distinct goes in front of the left expression
            str.append("DISTINCT ");
        }
        if (left != null) {
            str.append(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 if (dyExpr.getOperator() == Expression.OP_DISTINCT) {
        // Processed above
        } else {
            // TODO Support other operators
            throw new UnsupportedOperationException("Dont currently support operator " + dyExpr.getOperator() + " in JDOQL conversion");
        }
        if (right != null) {
            str.append(getJDOQLForExpression(right));
        }
        str.append(")");
        return str.toString();
    } else if (expr instanceof PrimaryExpression) {
        PrimaryExpression primExpr = (PrimaryExpression) expr;
        if (primExpr.getLeft() != null) {
            return getJDOQLForExpression(primExpr.getLeft()) + "." + primExpr.getId();
        }
        return primExpr.getId();
    } else if (expr instanceof ParameterExpression) {
        ParameterExpression paramExpr = (ParameterExpression) expr;
        if (paramExpr.getId() != null) {
            return ":" + paramExpr.getId();
        }
        return "?" + paramExpr.getPosition();
    } else if (expr instanceof VariableExpression) {
        VariableExpression varExpr = (VariableExpression) expr;
        return varExpr.getId();
    } else if (expr instanceof InvokeExpression) {
        InvokeExpression invExpr = (InvokeExpression) expr;
        StringBuilder str = new StringBuilder();
        if (invExpr.getLeft() != null) {
            str.append(getJDOQLForExpression(invExpr.getLeft())).append(".");
        }
        str.append(invExpr.getOperation());
        str.append("(");
        List<Expression> args = invExpr.getArguments();
        if (args != null) {
            Iterator<Expression> iter = args.iterator();
            while (iter.hasNext()) {
                str.append(getJDOQLForExpression(iter.next()));
                if (iter.hasNext()) {
                    str.append(",");
                }
            }
        }
        str.append(")");
        return str.toString();
    } else if (expr instanceof Literal) {
        Literal litExpr = (Literal) expr;
        Object value = litExpr.getLiteral();
        if (value instanceof String || value instanceof Character) {
            return "'" + value.toString() + "'";
        } else if (value instanceof Boolean) {
            return ((Boolean) value ? "TRUE" : "FALSE");
        } else {
            if (litExpr.getLiteral() == null) {
                return "null";
            }
            return litExpr.getLiteral().toString();
        }
    } else {
        throw new UnsupportedOperationException("Dont currently support " + expr.getClass().getName() + " in JDOQLHelper");
    }
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) Expression(org.datanucleus.query.expression.Expression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) VariableExpression(org.datanucleus.query.expression.VariableExpression) PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) Literal(org.datanucleus.query.expression.Literal)

Example 45 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class StringExpressionImpl method substring.

/* (non-Javadoc)
     * @see org.datanucleus.query.typesafe.StringExpression#substring(int)
     */
public StringExpression substring(int pos) {
    List<org.datanucleus.query.expression.Expression> args = new ArrayList();
    args.add(new Literal(pos));
    org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "substring", args);
    return new StringExpressionImpl(invokeExpr);
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) NumericExpression(javax.jdo.query.NumericExpression) CharacterExpression(javax.jdo.query.CharacterExpression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) StringExpression(javax.jdo.query.StringExpression) PersistableExpression(javax.jdo.query.PersistableExpression) BooleanExpression(javax.jdo.query.BooleanExpression) Expression(javax.jdo.query.Expression) Literal(org.datanucleus.query.expression.Literal) ArrayList(java.util.ArrayList)

Aggregations

InvokeExpression (org.datanucleus.query.expression.InvokeExpression)65 Literal (org.datanucleus.query.expression.Literal)42 DyadicExpression (org.datanucleus.query.expression.DyadicExpression)40 Expression (org.datanucleus.query.expression.Expression)39 PrimaryExpression (org.datanucleus.query.expression.PrimaryExpression)38 ParameterExpression (org.datanucleus.query.expression.ParameterExpression)37 NucleusException (org.datanucleus.exceptions.NucleusException)32 ArrayList (java.util.ArrayList)25 VariableExpression (org.datanucleus.query.expression.VariableExpression)21 BooleanExpression (javax.jdo.query.BooleanExpression)17 NumericExpression (javax.jdo.query.NumericExpression)17 PersistableExpression (javax.jdo.query.PersistableExpression)17 Expression (javax.jdo.query.Expression)15 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)13 OrderExpression (org.datanucleus.query.expression.OrderExpression)12 List (java.util.List)10 CharacterExpression (javax.jdo.query.CharacterExpression)10 StringExpression (javax.jdo.query.StringExpression)10 LocalDateTime (java.time.LocalDateTime)7 Calendar (java.util.Calendar)7