use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLArrayResultIT method testSQLResultSetMappingScalar.
@Test
public void testSQLResultSetMappingScalar() throws Exception {
String ejbql = "SELECT count(p) FROM Painting p JOIN p.toArtist a";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Object o1 = objects.get(0);
assertEquals(new Long(2), o1);
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLArrayResultIT method testSQLResultSetMappingMixed.
@Test
public void testSQLResultSetMappingMixed() throws Exception {
String ejbql = "SELECT count(p), a, sum(p.estimatedPrice) " + "FROM Artist a LEFT JOIN a.paintingArray p " + "GROUP BY a ORDER BY a.artistName";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(4, objects.size());
Object o1 = objects.get(0);
assertTrue("Expected Object[]: " + o1, o1 instanceof Object[]);
Object[] array1 = (Object[]) o1;
assertEquals(3, array1.length);
assertEquals(new Long(1), array1[0]);
assertTrue("Expected Artist, got: " + array1[1], array1[1] instanceof Artist);
assertEquals(0, new BigDecimal(3000).compareTo((BigDecimal) array1[2]));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testLike1.
@Test
public void testLike1() throws Exception {
createLikeDataSet();
String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'A%C'";
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(33001)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testNotIn.
@Test
public void testNotIn() throws Exception {
createInDataSet();
String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle NOT IN ('A', 'B')";
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(33008)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLConditionsIT method testLikeEscape_LikeParameter.
@Test
public void testLikeEscape_LikeParameter() throws Exception {
createLikeDataSet();
// test for CAY-1426
String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE ?1 ESCAPE 'X'";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter(1, "X_DDDD");
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)));
}
Aggregations