use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testLikeEscape.
@Test
public void testLikeEscape() throws Exception {
createLikeDataSet();
String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'X_DDDD' ESCAPE 'X'";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(new Integer(33005)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testCollectionNotMemberOfParameter.
@Test
public void testCollectionNotMemberOfParameter() throws Exception {
createCollectionDataSet();
String ejbql = "SELECT a FROM Artist a WHERE :x NOT MEMBER a.paintingArray";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("x", Cayenne.objectForPK(context, Painting.class, 33010));
List<?> objects = context.performQuery(query);
assertEquals(2, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(33002l));
assertTrue(ids.contains(33003l));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testCollectionEmpty.
@Test
public void testCollectionEmpty() throws Exception {
createCollectionDataSet();
String ejbql = "SELECT a FROM Artist a WHERE a.paintingArray IS EMPTY";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(new Long(33003)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testInSubquery.
@Test
public void testInSubquery() throws Exception {
createInSubqueryDataSet();
String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle IN (" + "SELECT p1.paintingTitle FROM Painting p1 WHERE p1.paintingTitle = 'C'" + ")";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(2, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(new Integer(33012)));
assertTrue(ids.contains(new Integer(33014)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsPeopleIT method testCollectionNotMemberOfToOne.
@Test
public void testCollectionNotMemberOfToOne() throws Exception {
// need a better test ... this query returns zero rows by definition
String ejbql = "SELECT a" + " FROM Address a JOIN a.toEmployee m JOIN m.toDepartment d" + " WHERE m NOT MEMBER d.employees";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(0, objects.size());
}
Aggregations