Search in sources :

Example 6 with DateTestEntity

use of org.apache.cayenne.testdo.date_time.DateTestEntity 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 7 with DateTestEntity

use of org.apache.cayenne.testdo.date_time.DateTestEntity 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 8 with DateTestEntity

use of org.apache.cayenne.testdo.date_time.DateTestEntity 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 9 with DateTestEntity

use of org.apache.cayenne.testdo.date_time.DateTestEntity in project cayenne by apache.

the class ASTFunctionCallDateIT method createDataSet.

@Before
public void createDataSet() throws Exception {
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH);
    int day = cal.get(Calendar.DAY_OF_MONTH);
    DateTestEntity o1 = context.newObject(DateTestEntity.class);
    cal.set(year - 1, month, day, 0, 0, 0);
    o1.setDateColumn(cal.getTime());
    cal.set(year, month, day, 0, 0, 0);
    o1.setTimeColumn(cal.getTime());
    cal.set(Calendar.DAY_OF_MONTH, day - 1);
    o1.setTimestampColumn(cal.getTime());
    DateTestEntity o2 = context.newObject(DateTestEntity.class);
    cal.set(year + 1, month, day, 0, 0, 0);
    o2.setDateColumn(cal.getTime());
    cal.set(year, month, day, 23, 59, 59);
    o2.setTimeColumn(cal.getTime());
    cal.set(Calendar.DAY_OF_MONTH, day + 1);
    o2.setTimestampColumn(cal.getTime());
    context.commitChanges();
}
Also used : Calendar(java.util.Calendar) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) Before(org.junit.Before)

Example 10 with DateTestEntity

use of org.apache.cayenne.testdo.date_time.DateTestEntity in project cayenne by apache.

the class DataContextEJBQLDateTimeFunctionalExpressionsIT method testCURRENT_DATE.

@Test
public void testCURRENT_DATE() {
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    DateTestEntity o1 = context.newObject(DateTestEntity.class);
    cal.set(year - 3, 1, 1);
    o1.setDateColumn(cal.getTime());
    DateTestEntity o2 = context.newObject(DateTestEntity.class);
    cal.set(year + 3, 1, 1);
    o2.setDateColumn(cal.getTime());
    context.commitChanges();
    EJBQLQuery query = new EJBQLQuery("SELECT d FROM DateTestEntity d WHERE d.dateColumn > CURRENT_DATE");
    List<?> objects = context.performQuery(query);
    assertEquals(1, objects.size());
    assertTrue(objects.contains(o2));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Calendar(java.util.Calendar) DateTestEntity(org.apache.cayenne.testdo.date_time.DateTestEntity) Test(org.junit.Test)

Aggregations

DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)17 Test (org.junit.Test)15 Calendar (java.util.Calendar)11 Date (java.util.Date)6 Expression (org.apache.cayenne.exp.Expression)6 DataRow (org.apache.cayenne.DataRow)3 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)3 SelectQuery (org.apache.cayenne.query.SelectQuery)3 Before (org.junit.Before)2 Time (java.sql.Time)1