Search in sources :

Example 51 with DyadicExpression

use of org.datanucleus.query.expression.DyadicExpression in project tests by datanucleus.

the class JDOQLCompilerTest method testFilterImplicitParameter.

/**
 * Test for use of an implicit parameter in the filter.
 */
public void testFilterImplicitParameter() {
    // Test use of implicit variable in filter
    JavaQueryCompiler compiler = null;
    QueryCompilation compilation = null;
    try {
        compiler = new JDOQLCompiler(nucCtx, nucCtx.getClassLoaderResolver(null), null, Product.class, null, "name == :param1", null, null, null, null, null, null, null, null);
        compilation = compiler.compile(null, null);
    } catch (NucleusUserException ne) {
        // TODO Debatable if this should throw a JDOUserException since the "notaField" is not bound, nor typed
        NucleusLogger.QUERY.error("Exception thrown during compilation", ne);
        fail("compilation of filter with valid field threw exception : " + ne.getMessage());
    }
    Expression expr = compilation.getExprFilter();
    assertTrue("Compiled expression should have been DyadicExpression but wasnt", expr instanceof DyadicExpression);
    DyadicExpression dyExpr = (DyadicExpression) expr;
    assertTrue("Compiled left expression should be PrimaryExpression but isnt", dyExpr.getLeft() instanceof PrimaryExpression);
    assertTrue("Compiled right expression should be ParameterExpression but isnt", dyExpr.getRight() instanceof ParameterExpression);
    PrimaryExpression left = (PrimaryExpression) dyExpr.getLeft();
    assertEquals("Primary expression name is wrong", left.getId(), "name");
    ParameterExpression right = (ParameterExpression) dyExpr.getRight();
    assertEquals("ParameterExpression has wrong value", "param1", right.getId());
}
Also used : JDOQLCompiler(org.datanucleus.query.compiler.JDOQLCompiler) JavaQueryCompiler(org.datanucleus.query.compiler.JavaQueryCompiler) PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) 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) OrderExpression(org.datanucleus.query.expression.OrderExpression) PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ParameterExpression(org.datanucleus.query.expression.ParameterExpression) Product(org.datanucleus.samples.store.Product) QueryCompilation(org.datanucleus.query.compiler.QueryCompilation) DyadicExpression(org.datanucleus.query.expression.DyadicExpression)

Aggregations

DyadicExpression (org.datanucleus.query.expression.DyadicExpression)51 InvokeExpression (org.datanucleus.query.expression.InvokeExpression)43 Expression (org.datanucleus.query.expression.Expression)42 PrimaryExpression (org.datanucleus.query.expression.PrimaryExpression)36 ParameterExpression (org.datanucleus.query.expression.ParameterExpression)34 Literal (org.datanucleus.query.expression.Literal)32 VariableExpression (org.datanucleus.query.expression.VariableExpression)30 NucleusException (org.datanucleus.exceptions.NucleusException)21 QueryCompilation (org.datanucleus.query.compiler.QueryCompilation)20 JavaQueryCompiler (org.datanucleus.query.compiler.JavaQueryCompiler)18 OrderExpression (org.datanucleus.query.expression.OrderExpression)13 BooleanExpression (javax.jdo.query.BooleanExpression)12 PersistableExpression (javax.jdo.query.PersistableExpression)12 JDOQLCompiler (org.datanucleus.query.compiler.JDOQLCompiler)12 Product (org.datanucleus.samples.store.Product)12 HashMap (java.util.HashMap)11 NumericExpression (javax.jdo.query.NumericExpression)9 ComparableExpression (javax.jdo.query.ComparableExpression)8 OrderExpression (javax.jdo.query.OrderExpression)8 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)7