Search in sources :

Example 61 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTExtractIT method testSecond.

@Test
public void testSecond() {
    Expression exp = ExpressionFactory.exp("second(timestampColumn) = 39");
    try {
        long res = ObjectSelect.query(DateTestEntity.class, exp).selectCount(context);
        assertEquals(1, res);
    } catch (CayenneRuntimeException e) {
        if (unitDbAdapter.supportsExtractPart(ASTExtract.DateTimePart.SECOND)) {
            throw e;
        }
    }
}
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 62 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTExtractIT method testWeek.

@Test
public void testWeek() {
    // 13 or 14 depends of first day in week in current db
    Expression exp = ExpressionFactory.exp("week(dateColumn) in (13, 14)");
    try {
        long res = ObjectSelect.query(DateTestEntity.class, exp).selectCount(context);
        assertEquals(1, res);
    } catch (CayenneRuntimeException e) {
        if (unitDbAdapter.supportsExtractPart(ASTExtract.DateTimePart.WEEK)) {
            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 63 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTExtractTest method testSecond.

@Test
public void testSecond() {
    String expStr = "second(dateColumn)";
    Expression expParsed = ExpressionFactory.exp(expStr);
    Expression expFromFactory = FunctionExpressionFactory.secondExp("dateColumn");
    assertTrue(expParsed instanceof ASTExtract);
    assertTrue(expFromFactory instanceof ASTExtract);
    assertEquals(expStr, expParsed.toString());
    assertEquals(expStr, expFromFactory.toString());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 64 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTExtractTest method testDayOfYear.

@Test
public void testDayOfYear() {
    String expStr = "dayOfYear(dateColumn)";
    Expression expParsed = ExpressionFactory.exp(expStr);
    Expression expFromFactory = FunctionExpressionFactory.dayOfYearExp("dateColumn");
    assertTrue(expParsed instanceof ASTExtract);
    assertTrue(expFromFactory instanceof ASTExtract);
    assertEquals(expStr, expParsed.toString());
    assertEquals(expStr, expFromFactory.toString());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 65 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTExtractTest method testMonth.

@Test
public void testMonth() {
    String expStr = "month(dateColumn)";
    Expression expParsed = ExpressionFactory.exp(expStr);
    Expression expFromFactory = FunctionExpressionFactory.monthExp("dateColumn");
    assertTrue(expParsed instanceof ASTExtract);
    assertTrue(expFromFactory instanceof ASTExtract);
    assertEquals(expStr, expParsed.toString());
    assertEquals(expStr, expFromFactory.toString());
}
Also used : Expression(org.apache.cayenne.exp.Expression) 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