Search in sources :

Example 56 with Expression

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);
}
Also used : Expression(org.apache.cayenne.exp.Expression) Date(java.util.Date) Test(org.junit.Test)

Example 57 with Expression

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));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 58 with Expression

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));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 59 with Expression

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
    }
}
Also used : Expression(org.apache.cayenne.exp.Expression) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) Test(org.junit.Test)

Example 60 with Expression

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
    }
}
Also used : Expression(org.apache.cayenne.exp.Expression) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) Test(org.junit.Test)

Aggregations

Expression (org.apache.cayenne.exp.Expression)298 Test (org.junit.Test)265 Artist (org.apache.cayenne.testdo.testmap.Artist)69 SelectQuery (org.apache.cayenne.query.SelectQuery)47 Painting (org.apache.cayenne.testdo.testmap.Painting)29 BigDecimal (java.math.BigDecimal)23 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)16 ObjEntity (org.apache.cayenne.map.ObjEntity)13 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 DbEntity (org.apache.cayenne.map.DbEntity)10 List (java.util.List)9 HashMap (java.util.HashMap)8 DataRow (org.apache.cayenne.DataRow)8 DbAttribute (org.apache.cayenne.map.DbAttribute)8 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)7 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ObjAttribute (org.apache.cayenne.map.ObjAttribute)6 ObjRelationship (org.apache.cayenne.map.ObjRelationship)6 Gallery (org.apache.cayenne.testdo.testmap.Gallery)6