use of org.apache.cayenne.query.EJBQLQuery 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));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLDateTimeFunctionalExpressionsIT method testCURRENT_TIME.
@Test
public void testCURRENT_TIME() {
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, month, day, 0, 0, 0);
o1.setTimeColumn(cal.getTime());
DateTestEntity o2 = context.newObject(DateTestEntity.class);
cal.set(year, month, day, 23, 59, 59);
o2.setTimeColumn(cal.getTime());
context.commitChanges();
EJBQLQuery query = new EJBQLQuery("SELECT d FROM DateTestEntity d WHERE d.timeColumn < CURRENT_TIME");
List<?> objects = context.performQuery(query);
if (!unitDbAdapter.supportsTimeSqlType()) {
// result will be invalid most likely as DB doesn't support TIME data type
return;
}
assertEquals(1, objects.size());
assertTrue(objects.contains(o1));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLDateTimeFunctionalExpressionsIT method testCURRENT_TIMESTAMP.
@Test
public void testCURRENT_TIMESTAMP() {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int date = cal.get(Calendar.DATE);
DateTestEntity o1 = context.newObject(DateTestEntity.class);
cal.set(year, month, date, 0, 0, 0);
o1.setTimestampColumn(cal.getTime());
DateTestEntity o2 = context.newObject(DateTestEntity.class);
cal.set(year, month, date, 23, 59, 59);
o2.setTimestampColumn(cal.getTime());
context.commitChanges();
EJBQLQuery query = new EJBQLQuery("SELECT d FROM DateTestEntity d WHERE d.timestampColumn < CURRENT_TIMESTAMP");
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
assertTrue(objects.contains(o1));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLDeleteIT method testDeleteNoIdVar.
@Test
public void testDeleteNoIdVar() throws Exception {
createPaintingsDataSet();
String ejbql = "delete from Painting";
EJBQLQuery query = new EJBQLQuery(ejbql);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(2, count[0]);
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLDeleteIT method testDeleteSameEntityQualifier.
@Test
public void testDeleteSameEntityQualifier() throws Exception {
createPaintingsDataSet();
String ejbql = "delete from Painting AS p WHERE p.paintingTitle = 'P2'";
EJBQLQuery query = new EJBQLQuery(ejbql);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(1, count[0]);
ObjectContext freshContext = runtime.newContext();
assertNotNull(Cayenne.objectForPK(freshContext, Painting.class, 33001));
assertNull(Cayenne.objectForPK(freshContext, Painting.class, 33002));
}
Aggregations