Search in sources :

Example 1 with ASTEqual

use of org.apache.cayenne.exp.parser.ASTEqual in project cayenne by apache.

the class CAY2541IT method testCay2541.

@Test
public void testCay2541() {
    ObjectId id = ObjectId.of("ARTIST", "ARTIST_ID", 1);
    ASTDbPath astDbPath = new ASTDbPath("ARTIST_ID");
    ASTScalar astScalar = new ASTScalar(id);
    ASTEqual astEqual = new ASTEqual();
    astEqual.setOperand(0, astDbPath);
    astEqual.setOperand(1, astScalar);
    List<Artist> artistList = ObjectSelect.query(Artist.class).where(astEqual).select(context);
    assertEquals(1, artistList.size());
    assertEquals("artist1", artistList.get(0).getArtistName());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ASTDbPath(org.apache.cayenne.exp.parser.ASTDbPath) ObjectId(org.apache.cayenne.ObjectId) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Example 2 with ASTEqual

use of org.apache.cayenne.exp.parser.ASTEqual in project cayenne by apache.

the class Cay2666IT method testExpObjPathWithDollarSign.

@Test
public void testExpObjPathWithDollarSign() throws IOException {
    Expression exp = ExpressionFactory.exp("obj:x$ = 'A'");
    Expression expression = new ASTEqual(new ASTObjPath("x$"), "A");
    assertEquals(exp, expression);
    exp = ExpressionFactory.exp("x$ = 'A'");
    expression = new ASTEqual(new ASTObjPath("x$"), "A");
    assertEquals(exp, expression);
    exp = ExpressionFactory.exp("obj:x$ = $name", "A");
    expression = new ASTEqual(new ASTObjPath("x$"), "A");
    assertEquals(exp, expression);
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) Expression(org.apache.cayenne.exp.Expression) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) Test(org.junit.Test)

Example 3 with ASTEqual

use of org.apache.cayenne.exp.parser.ASTEqual in project cayenne by apache.

the class PathAliasesIT method testAliasForPathExp.

@Test
public void testAliasForPathExp() {
    ASTPath astPath = new ASTObjPath("paintingArray.p1.galleryName");
    astPath.setPathAliases(Collections.singletonMap("a", "toGallery"));
    ASTEqual astEqual = new ASTEqual(astPath, "test gallery");
    Expression e1 = ExpressionFactory.exp("paintingArray.toGallery#p1.galleryName");
    List<Object[]> artists = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME, PropertyFactory.createBase(e1, String.class)).where(astEqual).select(context);
    assertEquals(1, artists.size());
    assertEquals("artist4", artists.get(0)[0]);
    assertEquals("test gallery", artists.get(0)[1]);
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) Expression(org.apache.cayenne.exp.Expression) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTPath(org.apache.cayenne.exp.parser.ASTPath) Test(org.junit.Test)

Example 4 with ASTEqual

use of org.apache.cayenne.exp.parser.ASTEqual in project cayenne by apache.

the class SelectQueryReturnTypesIT method testSelectBitwiseXor.

@Test
public void testSelectBitwiseXor() throws Exception {
    if (!accessStackAdapter.supportsBitwiseOps()) {
        return;
    }
    createNumericsDataSet();
    // to simplify result checking, do double NOT
    Expression left = new ASTBitwiseXor(new Object[] { new ASTObjPath(ReturnTypesMap1.INTEGER_COLUMN.getName()), new ASTScalar(1) });
    Expression right = new ASTScalar(5);
    Expression equal = new ASTEqual();
    equal.setOperand(0, left);
    equal.setOperand(1, right);
    List<ReturnTypesMap1> objects = ObjectSelect.query(ReturnTypesMap1.class, equal).select(context);
    assertEquals(1, objects.size());
    assertEquals(4, objects.get(0).getIntegerColumn().intValue());
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ReturnTypesMap1(org.apache.cayenne.testdo.return_types.ReturnTypesMap1) Expression(org.apache.cayenne.exp.Expression) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTBitwiseXor(org.apache.cayenne.exp.parser.ASTBitwiseXor) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Example 5 with ASTEqual

use of org.apache.cayenne.exp.parser.ASTEqual in project cayenne by apache.

the class DB2QualifierTranslator method processColumnWithQuoteSqlIdentifiers.

@Override
protected void processColumnWithQuoteSqlIdentifiers(DbAttribute dbAttr, Expression pathExp) {
    SimpleNode parent = null;
    if (pathExp instanceof SimpleNode) {
        parent = (SimpleNode) ((SimpleNode) pathExp).jjtGetParent();
    }
    // we need do it by casting the Clob to VARCHAR.
    if (parent != null && (parent instanceof ASTEqual || parent instanceof ASTNotEqual) && dbAttr.getType() == Types.CLOB && parent.getOperandCount() == 2 && parent.getOperand(1) instanceof String) {
        Integer size = parent.getOperand(1).toString().length() + 1;
        out.append("CAST(");
        super.processColumnWithQuoteSqlIdentifiers(dbAttr, pathExp);
        out.append(" AS VARCHAR(" + size + "))");
    } else {
        super.processColumnWithQuoteSqlIdentifiers(dbAttr, pathExp);
    }
}
Also used : ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTNotEqual(org.apache.cayenne.exp.parser.ASTNotEqual) SimpleNode(org.apache.cayenne.exp.parser.SimpleNode)

Aggregations

ASTEqual (org.apache.cayenne.exp.parser.ASTEqual)11 Test (org.junit.Test)8 ASTObjPath (org.apache.cayenne.exp.parser.ASTObjPath)7 Expression (org.apache.cayenne.exp.Expression)6 ASTScalar (org.apache.cayenne.exp.parser.ASTScalar)4 ASTPath (org.apache.cayenne.exp.parser.ASTPath)3 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)3 ASTDbPath (org.apache.cayenne.exp.parser.ASTDbPath)2 ASTNotEqual (org.apache.cayenne.exp.parser.ASTNotEqual)2 SimpleNode (org.apache.cayenne.exp.parser.SimpleNode)2 Artist (org.apache.cayenne.testdo.testmap.Artist)2 ArrayList (java.util.ArrayList)1 ObjectId (org.apache.cayenne.ObjectId)1 ASTBitwiseAnd (org.apache.cayenne.exp.parser.ASTBitwiseAnd)1 ASTBitwiseOr (org.apache.cayenne.exp.parser.ASTBitwiseOr)1 ASTBitwiseXor (org.apache.cayenne.exp.parser.ASTBitwiseXor)1 ASTEnclosingObject (org.apache.cayenne.exp.parser.ASTEnclosingObject)1 ASTFullObject (org.apache.cayenne.exp.parser.ASTFullObject)1 ASTTrue (org.apache.cayenne.exp.parser.ASTTrue)1