use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLOrderByIT method testOrderByQualified.
@Test
public void testOrderByQualified() throws Exception {
createThreePaintings();
String ejbql1 = "SELECT p FROM Painting p WHERE p.estimatedPrice > 1000 ORDER BY p.paintingTitle ASC";
EJBQLQuery query1 = new EJBQLQuery(ejbql1);
List<?> results1 = context.performQuery(query1);
assertEquals(2, results1.size());
assertEquals(33001, Cayenne.intPKForObject((Persistent) results1.get(0)));
assertEquals(33002, Cayenne.intPKForObject((Persistent) results1.get(1)));
String ejbql2 = "SELECT p FROM Painting p WHERE p.estimatedPrice > 1000 ORDER BY p.estimatedPrice ASC";
EJBQLQuery query2 = new EJBQLQuery(ejbql2);
List<?> results2 = context.performQuery(query2);
assertEquals(2, results2.size());
assertEquals(33002, Cayenne.intPKForObject((Persistent) results2.get(0)));
assertEquals(33001, Cayenne.intPKForObject((Persistent) results2.get(1)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLOrderByIT method testOrderByDefault.
@Test
public void testOrderByDefault() throws Exception {
createThreePaintings();
String ejbql1 = "SELECT p FROM Painting p ORDER BY p.paintingTitle";
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";
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 DataContextEJBQLQueryCompoundIT method testSelectFromWhereMatchOnMultiColumnObjectReverse.
@Test
public void testSelectFromWhereMatchOnMultiColumnObjectReverse() throws Exception {
if (!accessStackAdapter.supportsReverseComparison()) {
return;
}
createTwoCompoundPKTwoFK();
Map<String, String> key1 = new HashMap<>();
key1.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "b1");
key1.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "b2");
CompoundPkTestEntity a = Cayenne.objectForPK(context, CompoundPkTestEntity.class, key1);
String ejbql = "select e from CompoundFkTestEntity e WHERE :param = e.toCompoundPk";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("param", a);
List<?> ps = context.performQuery(query);
assertEquals(1, ps.size());
CompoundFkTestEntity o1 = (CompoundFkTestEntity) ps.get(0);
assertEquals(33002, Cayenne.intPKForObject(o1));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLQueryCompoundIT method testSelectFromWhereNoMatchOnMultiColumnObject.
@Test
public void testSelectFromWhereNoMatchOnMultiColumnObject() throws Exception {
createTwoCompoundPKTwoFK();
Map<String, String> key1 = new HashMap<>();
key1.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "b1");
key1.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "b2");
CompoundPkTestEntity a = Cayenne.objectForPK(context, CompoundPkTestEntity.class, key1);
String ejbql = "select e from CompoundFkTestEntity e WHERE e.toCompoundPk <> :param";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("param", a);
List<?> ps = context.performQuery(query);
assertEquals(1, ps.size());
CompoundFkTestEntity o1 = (CompoundFkTestEntity) ps.get(0);
assertEquals(33001, Cayenne.intPKForObject(o1));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class CayenneIT method testEjbql.
@Test
public void testEjbql() throws Exception {
createOneArtist();
List<?> objects = context.performQuery(new EJBQLQuery("select a from Artist a"));
assertEquals(1, objects.size());
Artist object = (Artist) objects.get(0);
assertEquals(new Long(33002), Cayenne.pkForObject(object));
}
Aggregations