use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTCurrentTimestampTest method testEvaluate.
@Test
public void testEvaluate() {
Expression exp = new ASTCurrentTimestamp();
Object result = exp.evaluate(new Object());
assertTrue(result instanceof Date);
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTDbPathIT method testEvaluate_DataObject.
@Test
public void testEvaluate_DataObject() {
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("a1");
context.commitChanges();
Expression idExp = ExpressionFactory.exp("db:ARTIST_ID");
assertEquals(Cayenne.longPKForObject(a1), idExp.evaluate(a1));
Expression columnExp = ExpressionFactory.exp("db:ARTIST_NAME");
assertEquals("a1", columnExp.evaluate(a1));
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTEqualIT method testEvaluate_TempId.
@Test
public void testEvaluate_TempId() {
Artist a1 = context.newObject(Artist.class);
Artist a2 = context.newObject(Artist.class);
Painting p1 = context.newObject(Painting.class);
Painting p2 = context.newObject(Painting.class);
Painting p3 = context.newObject(Painting.class);
p1.setToArtist(a1);
p2.setToArtist(a2);
Expression e = new ASTEqual(new ASTObjPath("toArtist"), a1.getObjectId());
assertTrue(e.match(p1));
assertFalse(e.match(p2));
assertFalse(e.match(p3));
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTExtractIT method testMonth.
@Test
public void testMonth() {
Expression exp = ExpressionFactory.exp("month(dateColumn) = 3");
try {
long res = ObjectSelect.query(DateTestEntity.class, exp).selectCount(context);
assertEquals(1, res);
} catch (CayenneRuntimeException e) {
if (unitDbAdapter.supportsExtractPart(ASTExtract.DateTimePart.MONTH)) {
throw e;
}
// else ok
}
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTExtractIT method testHour.
@Test
public void testHour() {
Expression exp = ExpressionFactory.exp("hour(timestampColumn) = 23");
try {
long res = ObjectSelect.query(DateTestEntity.class, exp).selectCount(context);
assertEquals(1, res);
} catch (CayenneRuntimeException e) {
if (unitDbAdapter.supportsExtractPart(ASTExtract.DateTimePart.HOUR)) {
throw e;
}
// else ok
}
}
Aggregations