use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testCollectionMemberOfThetaJoin.
@Test
public void testCollectionMemberOfThetaJoin() throws Exception {
createCollectionDataSet();
String ejbql = "SELECT p FROM Painting p, Artist a " + "WHERE p MEMBER OF a.paintingArray AND a.artistName = 'B'";
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(33009)));
assertTrue(ids.contains(new Integer(33010)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testDateParameter.
@Test
public void testDateParameter() throws Exception {
createCollectionDataSet();
SelectQuery q = new SelectQuery(Artist.class);
List<Artist> allArtists = context.performQuery(q);
Date dob = new Date();
allArtists.get(0).setDateOfBirth(dob);
context.commitChanges();
String ejbql = "SELECT a FROM Artist a WHERE a.dateOfBirth = :x";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("x", dob);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
assertSame(allArtists.get(0), objects.get(0));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testLessOrEquals.
@Test
public void testLessOrEquals() throws Exception {
createGreaterThanDataSet();
String ejbql = "SELECT p FROM Painting p WHERE p.estimatedPrice <= :estimatedPrice";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("estimatedPrice", new BigDecimal(4000));
List<?> objects = context.performQuery(query);
assertEquals(2, objects.size());
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testCollectionNotEmpty.
@Test
public void testCollectionNotEmpty() throws Exception {
createCollectionDataSet();
String ejbql = "SELECT a FROM Artist a WHERE a.paintingArray IS NOT EMPTY";
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(33001l));
assertTrue(ids.contains(33002l));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testNotLike.
@Test
public void testNotLike() throws Exception {
createLikeDataSet();
String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle NOT LIKE 'A%C'";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(4, 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);
}
assertFalse(ids.contains(new Integer(33001)));
}
Aggregations