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());
}
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);
}
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);
}
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());
}
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));
}
}
}
Aggregations