use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLGroupByHavingIT method testGroupByHavingOnColumn.
@Test
public void testGroupByHavingOnColumn() throws Exception {
createFivePaintings();
String ejbql = "SELECT p.estimatedPrice, count(p) FROM Painting p" + " GROUP BY p.estimatedPrice" + " HAVING p.estimatedPrice > 1";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> data = context.performQuery(query);
assertEquals(1, data.size());
assertTrue(data.get(0) instanceof Object[]);
Object[] row0 = (Object[]) data.get(0);
assertEquals(2d, ((BigDecimal) row0[0]).doubleValue(), 0.00001d);
assertEquals(new Long(2), row0[1]);
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLGroupByHavingIT method testGroupByHavingOnAggregateMultipleConditions.
@Test
public void testGroupByHavingOnAggregateMultipleConditions() throws Exception {
createFivePaintings();
String ejbql = "SELECT p.estimatedPrice, count(p) FROM Painting p" + " GROUP BY p.estimatedPrice" + " HAVING count(p) > 2 AND p.estimatedPrice < 10";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> data = context.performQuery(query);
assertEquals(1, data.size());
assertTrue(data.get(0) instanceof Object[]);
Object[] row0 = (Object[]) data.get(0);
assertEquals(1d, ((BigDecimal) row0[0]).doubleValue(), 0.00001d);
assertEquals(new Long(3l), row0[1]);
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLGroupByHavingIT method testGroupByJoinedEntities.
@Test
public void testGroupByJoinedEntities() throws Exception {
createArtistsPaintingGalleries();
EJBQLQuery query = new EJBQLQuery("SELECT COUNT(p), p.toArtist, p.toGallery FROM Painting p " + "GROUP BY p.toGallery, p.toArtist ");
List<Object[]> data = context.performQuery(query);
assertNotNull(data);
assertEquals(2, data.size());
HashSet<List<?>> expectedResults = new HashSet<List<?>>();
expectedResults.add(Arrays.asList(1L, "AA2", "gallery1"));
expectedResults.add(Arrays.asList(1L, "AA1", "gallery2"));
for (Object[] row : data) {
assertFalse(expectedResults.add(Arrays.asList(row[0], row[1] == null ? null : ((Artist) row[1]).getArtistName(), row[2] == null ? null : ((Gallery) row[2]).getGalleryName())));
}
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLGroupByHavingIT method testGroupByJoinedEntityInCount.
@Test
public void testGroupByJoinedEntityInCount() throws Exception {
createArtistsPaintingGalleries();
EJBQLQuery query = new EJBQLQuery("SELECT COUNT(p.toArtist), p.paintingTitle FROM Painting p " + "GROUP BY p.paintingTitle " + "HAVING p.paintingTitle LIKE 'P1%'");
List<Object[]> data = context.performQuery(query);
assertNotNull(data);
assertEquals(3, data.size());
HashSet<List<?>> expectedResults = new HashSet<List<?>>();
expectedResults.add(Arrays.asList(1L, "P1"));
expectedResults.add(Arrays.asList(1L, "P111"));
expectedResults.add(Arrays.asList(1L, "P112"));
for (Object[] row : data) {
assertFalse(expectedResults.add(Arrays.asList(row[0], row[1])));
}
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLInheritanceIT method testSelect.
@Test
public void testSelect() throws Exception {
EJBQLQuery superclass = new EJBQLQuery("select p from AbstractPerson p ORDER BY p.name");
List<?> superclassResult = context.performQuery(superclass);
assertEquals(5, superclassResult.size());
assertEquals(Employee.class.getName(), superclassResult.get(0).getClass().getName());
assertEquals(Employee.class.getName(), superclassResult.get(1).getClass().getName());
assertEquals(Manager.class.getName(), superclassResult.get(2).getClass().getName());
assertEquals(Manager.class.getName(), superclassResult.get(3).getClass().getName());
assertEquals(CustomerRepresentative.class.getName(), superclassResult.get(4).getClass().getName());
EJBQLQuery subclass = new EJBQLQuery("select e from Employee e ORDER BY e.name");
List<?> subclassResult = context.performQuery(subclass);
assertEquals(4, subclassResult.size());
assertEquals(Employee.class.getName(), subclassResult.get(0).getClass().getName());
assertEquals(Employee.class.getName(), subclassResult.get(1).getClass().getName());
assertEquals(Manager.class.getName(), subclassResult.get(2).getClass().getName());
assertEquals(Manager.class.getName(), subclassResult.get(3).getClass().getName());
}
Aggregations