Search in sources :

Example 1 with ASTScalar

use of org.apache.cayenne.exp.parser.ASTScalar 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 ASTScalar

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

the class FunctionExpressionFactoryTest method locateExp.

@Test
public void locateExp() throws Exception {
    Expression exp1 = FunctionExpressionFactory.locateExp("abc", Artist.ARTIST_NAME.getExpression());
    Expression exp2 = FunctionExpressionFactory.locateExp("abc", Artist.ARTIST_NAME.getName());
    Expression exp3 = FunctionExpressionFactory.locateExp(new ASTScalar("abc"), Artist.ARTIST_NAME.getExpression());
    assertTrue(exp1 instanceof ASTLocate);
    assertEquals(2, exp1.getOperandCount());
    assertEquals("abc", exp1.getOperand(0));
    assertEquals(Artist.ARTIST_NAME.getExpression(), exp1.getOperand(1));
    assertEquals(exp1, exp2);
    assertEquals(exp2, exp3);
}
Also used : ASTLocate(org.apache.cayenne.exp.parser.ASTLocate) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Example 3 with ASTScalar

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

the class FunctionExpressionFactoryTest method modExp.

@Test
public void modExp() throws Exception {
    Expression exp1 = FunctionExpressionFactory.modExp(Artist.ARTIST_NAME.getExpression(), 10);
    Expression exp2 = FunctionExpressionFactory.modExp(Artist.ARTIST_NAME.getName(), 10);
    Expression exp3 = FunctionExpressionFactory.modExp(Artist.ARTIST_NAME.getExpression(), new ASTScalar(10));
    assertTrue(exp1 instanceof ASTMod);
    assertEquals(2, exp1.getOperandCount());
    assertEquals(Artist.ARTIST_NAME.getExpression(), exp1.getOperand(0));
    assertEquals(10, exp1.getOperand(1));
    assertEquals(exp1, exp2);
    assertEquals(exp2, exp3);
}
Also used : ASTMod(org.apache.cayenne.exp.parser.ASTMod) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar) Test(org.junit.Test)

Example 4 with ASTScalar

use of org.apache.cayenne.exp.parser.ASTScalar 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 ASTScalar

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

the class ToCacheKeyTraversalHandler method objectNode.

@Override
public void objectNode(Object leaf, Expression parentNode) {
    if (leaf == null) {
        out.append("null");
        return;
    }
    if (leaf instanceof ASTScalar) {
        leaf = ((ASTScalar) leaf).getValue();
    } else if (leaf instanceof Object[]) {
        for (Object value : (Object[]) leaf) {
            objectNode(value, parentNode);
            out.append(',');
        }
        return;
    }
    if (leaf instanceof Persistent) {
        ObjectId id = ((Persistent) leaf).getObjectId();
        Object encode = (id != null) ? id : leaf;
        out.append(encode);
    } else if (leaf instanceof Enum<?>) {
        Enum<?> e = (Enum<?>) leaf;
        out.append("e:").append(leaf.getClass().getName()).append(':').append(e.ordinal());
    } else {
        ValueObjectType<Object, ?> valueObjectType;
        if (registry == null || (valueObjectType = registry.getValueType(leaf.getClass())) == null) {
            // Registry will be null in cayenne-client context.
            // Maybe we shouldn't create cache key at all in that case...
            out.append(leaf);
        } else {
            out.append(valueObjectType.toCacheKey(leaf));
        }
    }
}
Also used : ValueObjectType(org.apache.cayenne.access.types.ValueObjectType) ObjectId(org.apache.cayenne.ObjectId) Persistent(org.apache.cayenne.Persistent) ASTScalar(org.apache.cayenne.exp.parser.ASTScalar)

Aggregations

ASTScalar (org.apache.cayenne.exp.parser.ASTScalar)10 Test (org.junit.Test)9 Expression (org.apache.cayenne.exp.Expression)4 ASTEqual (org.apache.cayenne.exp.parser.ASTEqual)4 ASTObjPath (org.apache.cayenne.exp.parser.ASTObjPath)4 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)4 ObjectId (org.apache.cayenne.ObjectId)2 Persistent (org.apache.cayenne.Persistent)1 ValueObjectType (org.apache.cayenne.access.types.ValueObjectType)1 ASTBitwiseAnd (org.apache.cayenne.exp.parser.ASTBitwiseAnd)1 ASTBitwiseNot (org.apache.cayenne.exp.parser.ASTBitwiseNot)1 ASTBitwiseOr (org.apache.cayenne.exp.parser.ASTBitwiseOr)1 ASTBitwiseXor (org.apache.cayenne.exp.parser.ASTBitwiseXor)1 ASTConcat (org.apache.cayenne.exp.parser.ASTConcat)1 ASTDbPath (org.apache.cayenne.exp.parser.ASTDbPath)1 ASTGreater (org.apache.cayenne.exp.parser.ASTGreater)1 ASTLocate (org.apache.cayenne.exp.parser.ASTLocate)1 ASTMod (org.apache.cayenne.exp.parser.ASTMod)1 ASTSubstring (org.apache.cayenne.exp.parser.ASTSubstring)1 Artist (org.apache.cayenne.testdo.testmap.Artist)1