Search in sources :

Example 1 with Operator

use of org.datanucleus.query.expression.Expression.Operator in project tests by datanucleus.

the class JPQLCompilerTest method testUpdateSimple.

/**
 * Test for use of update clause.
 */
public void testUpdateSimple() {
    // Test use of UPDATE clause
    try {
        JPQLCompiler compiler = new JPQLCompiler(nucCtx, nucCtx.getClassLoaderResolver(null), null, Project.class, null, null, null, null, null, null, null, null, "name = \"Sample Name\"");
        QueryCompilation compilation = compiler.compile(null, null);
        Expression[] updateExprs = compilation.getExprUpdate();
        assertNotNull("Update clause is null but shouldnt be", updateExprs);
        assertEquals("Number of update expressions is incorrect", 1, updateExprs.length);
        assertTrue("Update expression is of incorrect type " + updateExprs[0].getClass().getName(), updateExprs[0] instanceof DyadicExpression);
        DyadicExpression updateExpr = (DyadicExpression) updateExprs[0];
        Expression left = updateExpr.getLeft();
        Expression right = updateExpr.getRight();
        Operator op = updateExpr.getOperator();
        assertEquals("Operator in update expression is wrong", op, Expression.OP_EQ);
        assertTrue("Left hand side in update is wrong", left instanceof PrimaryExpression);
        assertTrue("Right hand side in update is wrong", right instanceof Literal);
        PrimaryExpression primExpr = (PrimaryExpression) left;
        assertEquals("Left hand side primary is wrong", "name", primExpr.getId());
        Literal lit = (Literal) right;
        assertEquals("Right hand side literal is wrong", "Sample Name", lit.getLiteral());
    } catch (NucleusUserException ne) {
        fail("Exception thrown in compile of update clause : " + ne.getMessage());
    }
}
Also used : Operator(org.datanucleus.query.expression.Expression.Operator) PrimaryExpression(org.datanucleus.query.expression.PrimaryExpression) SubqueryExpression(org.datanucleus.query.expression.SubqueryExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) JoinExpression(org.datanucleus.query.expression.JoinExpression) ClassExpression(org.datanucleus.query.expression.ClassExpression) 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) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) Literal(org.datanucleus.query.expression.Literal) QueryCompilation(org.datanucleus.query.compiler.QueryCompilation) JPQLCompiler(org.datanucleus.query.compiler.JPQLCompiler) DyadicExpression(org.datanucleus.query.expression.DyadicExpression)

Aggregations

NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 JPQLCompiler (org.datanucleus.query.compiler.JPQLCompiler)1 QueryCompilation (org.datanucleus.query.compiler.QueryCompilation)1 ClassExpression (org.datanucleus.query.expression.ClassExpression)1 DyadicExpression (org.datanucleus.query.expression.DyadicExpression)1 Expression (org.datanucleus.query.expression.Expression)1 Operator (org.datanucleus.query.expression.Expression.Operator)1 InvokeExpression (org.datanucleus.query.expression.InvokeExpression)1 JoinExpression (org.datanucleus.query.expression.JoinExpression)1 Literal (org.datanucleus.query.expression.Literal)1 ParameterExpression (org.datanucleus.query.expression.ParameterExpression)1 PrimaryExpression (org.datanucleus.query.expression.PrimaryExpression)1 SubqueryExpression (org.datanucleus.query.expression.SubqueryExpression)1 VariableExpression (org.datanucleus.query.expression.VariableExpression)1