use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLNumericalFunctionalIT method testSQRT.
@Test
public void testSQRT() {
BigDecimalEntity o1 = context.newObject(BigDecimalEntity.class);
o1.setBigDecimalField(new BigDecimal("9"));
BigDecimalEntity o2 = context.newObject(BigDecimalEntity.class);
o2.setBigDecimalField(new BigDecimal("16"));
context.commitChanges();
EJBQLQuery query = new EJBQLQuery("SELECT d FROM BigDecimalEntity d WHERE SQRT(d.bigDecimalField) > 3.1");
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 DataContextEJBQLNumericalFunctionalIT method testMOD.
@Test
public void testMOD() {
BigIntegerEntity o1 = context.newObject(BigIntegerEntity.class);
o1.setBigIntegerField(new BigInteger("9"));
BigIntegerEntity o2 = context.newObject(BigIntegerEntity.class);
o2.setBigIntegerField(new BigInteger("10"));
context.commitChanges();
EJBQLQuery query = new EJBQLQuery("SELECT d FROM BigIntegerEntity d WHERE MOD(d.bigIntegerField, 4) = 2");
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 DataContextEJBQLOrderByIT method testOrderByAsc.
@Test
public void testOrderByAsc() throws Exception {
createThreePaintings();
String ejbql1 = "SELECT p FROM Painting p ORDER BY p.paintingTitle ASC";
EJBQLQuery query1 = new EJBQLQuery(ejbql1);
List<?> results1 = context.performQuery(query1);
assertEquals(3, results1.size());
assertEquals(33001, Cayenne.intPKForObject((Persistent) results1.get(0)));
assertEquals(33002, Cayenne.intPKForObject((Persistent) results1.get(1)));
assertEquals(33003, Cayenne.intPKForObject((Persistent) results1.get(2)));
String ejbql2 = "SELECT p FROM Painting p ORDER BY p.estimatedPrice ASC";
EJBQLQuery query2 = new EJBQLQuery(ejbql2);
List<?> results2 = context.performQuery(query2);
assertEquals(3, results2.size());
assertEquals(33003, Cayenne.intPKForObject((Persistent) results2.get(0)));
assertEquals(33002, Cayenne.intPKForObject((Persistent) results2.get(1)));
assertEquals(33001, Cayenne.intPKForObject((Persistent) results2.get(2)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLOrderByIT method testOrderByMultiple.
@Test
public void testOrderByMultiple() throws Exception {
createFourPaintings();
String ejbql1 = "SELECT p FROM Painting p ORDER BY p.paintingTitle DESC, p.estimatedPrice DESC";
EJBQLQuery query1 = new EJBQLQuery(ejbql1);
List<?> results1 = context.performQuery(query1);
assertEquals(4, results1.size());
assertEquals(33003, Cayenne.intPKForObject((Persistent) results1.get(0)));
assertEquals(33004, Cayenne.intPKForObject((Persistent) results1.get(1)));
assertEquals(33002, Cayenne.intPKForObject((Persistent) results1.get(2)));
assertEquals(33001, Cayenne.intPKForObject((Persistent) results1.get(3)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLOrderByIT method testOrderByDesc.
@Test
public void testOrderByDesc() throws Exception {
createThreePaintings();
String ejbql1 = "SELECT p FROM Painting p ORDER BY p.paintingTitle DESC";
EJBQLQuery query1 = new EJBQLQuery(ejbql1);
List<?> results1 = context.performQuery(query1);
assertEquals(3, results1.size());
assertEquals(33003, Cayenne.intPKForObject((Persistent) results1.get(0)));
assertEquals(33002, Cayenne.intPKForObject((Persistent) results1.get(1)));
assertEquals(33001, Cayenne.intPKForObject((Persistent) results1.get(2)));
String ejbql2 = "SELECT p FROM Painting p ORDER BY p.estimatedPrice DESC";
EJBQLQuery query2 = new EJBQLQuery(ejbql2);
List<?> results2 = context.performQuery(query2);
assertEquals(3, results2.size());
assertEquals(33001, Cayenne.intPKForObject((Persistent) results2.get(0)));
assertEquals(33002, Cayenne.intPKForObject((Persistent) results2.get(1)));
assertEquals(33003, Cayenne.intPKForObject((Persistent) results2.get(2)));
}
Aggregations