Search in sources :

Example 71 with Expression

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

the class ASTFunctionCallDateIT method testASTCurrentTimestampParse.

@Test
public void testASTCurrentTimestampParse() {
    Expression exp = ExpressionFactory.exp("timestampColumn > now()");
    DateTestEntity res = ObjectSelect.query(DateTestEntity.class, exp).selectOne(context);
    assertNotNull(res);
}
Also used : Expression(org.apache.cayenne.exp.Expression) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) Test(org.junit.Test)

Example 72 with Expression

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

the class ASTFunctionCallDateIT method testASTCurrentDateParse.

@Test
public void testASTCurrentDateParse() {
    Expression exp = ExpressionFactory.exp("dateColumn > currentDate()");
    DateTestEntity res = ObjectSelect.query(DateTestEntity.class, exp).selectOne(context);
    assertNotNull(res);
}
Also used : Expression(org.apache.cayenne.exp.Expression) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) Test(org.junit.Test)

Example 73 with Expression

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

the class ASTFunctionCallDateIT method testCurrentTimestamp.

@Test
public void testCurrentTimestamp() throws Exception {
    Expression exp = ExpressionFactory.greaterOrEqualExp("timestampColumn", new ASTCurrentTimestamp());
    DateTestEntity res1 = ObjectSelect.query(DateTestEntity.class, exp).selectOne(context);
    assertNotNull(res1);
    Expression exp2 = ExpressionFactory.lessExp("timestampColumn", new ASTCurrentTimestamp());
    DateTestEntity res2 = ObjectSelect.query(DateTestEntity.class, exp2).selectOne(context);
    assertNotNull(res2);
    assertNotEquals(res1, res2);
}
Also used : Expression(org.apache.cayenne.exp.Expression) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) Test(org.junit.Test)

Example 74 with Expression

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

the class ASTFunctionCallMathIT method testASTSqrtParse.

@Test
public void testASTSqrtParse() {
    Expression exp = ExpressionFactory.exp("sqrt(16)");
    assertEquals(4.0, exp.evaluate(new Object()));
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 75 with Expression

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

the class ASTFunctionCallMathIT method testComplexParse.

@Test
public void testComplexParse() {
    Expression exp = ExpressionFactory.exp("10 - mod(sqrt(abs(-9)), 2)");
    assertEquals(BigDecimal.valueOf(9L), exp.evaluate(new Object()));
}
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