use of org.apache.cayenne.testdo.date_time.DateTestEntity in project cayenne by apache.
the class DateTimeTypesIT method testTimestamp.
@Test
public void testTimestamp() throws Exception {
DateTestEntity test = context.newObject(DateTestEntity.class);
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2003, 1, 1, 1, 20, 30);
// most databases fail millisecond accuracy
// cal.set(Calendar.MILLISECOND, 55);
Date now = cal.getTime();
test.setTimestampColumn(now);
context.commitChanges();
SelectQuery q = new SelectQuery(DateTestEntity.class);
DateTestEntity testRead = (DateTestEntity) context.performQuery(q).get(0);
assertNotNull(testRead.getTimestampColumn());
assertEquals(now, testRead.getTimestampColumn());
}
use of org.apache.cayenne.testdo.date_time.DateTestEntity in project cayenne by apache.
the class DateTimeTypesIT method testSQLTemplateTime.
@Test
public void testSQLTemplateTime() throws Exception {
DateTestEntity test = (DateTestEntity) context.newObject("DateTestEntity");
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2003, 1, 1, 1, 20, 30);
// most databases fail millisecond accuracy
// cal.set(Calendar.MILLISECOND, 55);
Time now = new Time(cal.getTime().getTime());
test.setTimeColumn(now);
context.commitChanges();
DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectDateTest")).get(0);
Date columnValue = (Date) testRead.get("TIME_COLUMN");
assertNotNull(testRead.toString(), columnValue);
assertNotNull(columnValue);
assertEquals(now.toString(), new Time(columnValue.getTime()).toString());
}
use of org.apache.cayenne.testdo.date_time.DateTestEntity in project cayenne by apache.
the class DateTimeTypesIT method testTime.
@Test
public void testTime() throws Exception {
DateTestEntity test = context.newObject(DateTestEntity.class);
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(1970, 0, 1, 1, 20, 30);
Date nowTime = cal.getTime();
test.setTimeColumn(nowTime);
context.commitChanges();
SelectQuery q = new SelectQuery(DateTestEntity.class);
DateTestEntity testRead = (DateTestEntity) context.performQuery(q).get(0);
assertNotNull(testRead.getTimeColumn());
assertEquals(Date.class, testRead.getTimeColumn().getClass());
// OpenBase fails to store seconds for the time
// FrontBase returns time with 1 hour offset (I guess "TIME WITH TIMEZONE" may
// need to be used as a default FB type?)
// so this test is approximate...
long delta = nowTime.getTime() - testRead.getTimeColumn().getTime();
assertTrue("" + delta, Math.abs(delta) <= 1000 * 60 * 60);
}
use of org.apache.cayenne.testdo.date_time.DateTestEntity in project cayenne by apache.
the class DateTimeTypesIT method testSQLTemplateDate.
@Test
public void testSQLTemplateDate() throws Exception {
DateTestEntity test = (DateTestEntity) context.newObject("DateTestEntity");
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2003, 1, 1, 1, 20, 30);
// most databases fail millisecond accuracy
// cal.set(Calendar.MILLISECOND, 55);
java.sql.Date now = new java.sql.Date(cal.getTime().getTime());
test.setDateColumn(now);
context.commitChanges();
DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectDateTest")).get(0);
Date columnValue = (Date) testRead.get("DATE_COLUMN");
assertNotNull(columnValue);
assertEquals(now.toString(), new java.sql.Date(columnValue.getTime()).toString());
}
use of org.apache.cayenne.testdo.date_time.DateTestEntity in project cayenne by apache.
the class ASTFunctionCallDateIT method testASTCurrentTimeParse.
@Test
public void testASTCurrentTimeParse() {
Expression exp = ExpressionFactory.exp("timeColumn > currentTime()");
DateTestEntity res = ObjectSelect.query(DateTestEntity.class, exp).selectOne(context);
if (!unitDbAdapter.supportsTimeSqlType()) {
return;
}
assertNotNull(res);
}
Aggregations