use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLFetchJoinIT method testSeveralEntitiesFetchJoins.
@Test
public void testSeveralEntitiesFetchJoins() throws Exception {
createMultipleFetchJoinsDataSet();
String ejbql = "SELECT DISTINCT a , g " + "FROM Artist a JOIN FETCH a.paintingArray , Gallery g JOIN FETCH g.exhibitArray " + "WHERE a.artistName='A1' AND g.galleryName='gallery1'";
EJBQLQuery query = new EJBQLQuery(ejbql);
final List<?> objects = context.performQuery(query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertNotNull(objects);
assertFalse(objects.isEmpty());
assertEquals(1, objects.size());
}
});
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLFetchJoinIT method testSeveralEntitiesAndScalarFetchInnerJoins.
@Test
public void testSeveralEntitiesAndScalarFetchInnerJoins() throws Exception {
createMultipleFetchJoinsDataSet();
String ejbql = "SELECT DISTINCT a, a.artistName , g " + "FROM Artist a JOIN FETCH a.paintingArray, Gallery g JOIN FETCH g.exhibitArray " + "ORDER BY a.artistName";
EJBQLQuery query = new EJBQLQuery(ejbql);
final List<?> objects = context.performQuery(query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, objects.size());
Object[] firstRow = (Object[]) objects.get(0);
Artist a = (Artist) firstRow[0];
assertEquals("A1", a.getArtistName());
List<Painting> paintings = a.getPaintingArray();
assertNotNull(paintings);
assertFalse(((ValueHolder) paintings).isFault());
assertEquals(2, paintings.size());
List<String> expectedPaintingsNames = new ArrayList<String>();
expectedPaintingsNames.add("P11");
expectedPaintingsNames.add("P12");
Iterator<Painting> paintingsIterator = paintings.iterator();
while (paintingsIterator.hasNext()) {
Painting p = paintingsIterator.next();
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
}
String artistName = (String) firstRow[1];
assertEquals("A1", artistName);
Gallery g1 = (Gallery) firstRow[2];
assertEquals("gallery1", g1.getGalleryName());
List<Exhibit> exibits = g1.getExhibitArray();
assertNotNull(exibits);
assertFalse(((ValueHolder) exibits).isFault());
assertEquals(2, exibits.size());
Object[] secondRow = (Object[]) objects.get(1);
a = (Artist) secondRow[0];
assertEquals("A2", a.getArtistName());
paintings = a.getPaintingArray();
assertNotNull(paintings);
assertFalse(((ValueHolder) paintings).isFault());
assertEquals(1, paintings.size());
expectedPaintingsNames = new ArrayList<String>();
expectedPaintingsNames.add("P2");
paintingsIterator = paintings.iterator();
while (paintingsIterator.hasNext()) {
Painting p = paintingsIterator.next();
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
}
artistName = (String) secondRow[1];
assertEquals("A2", artistName);
Gallery g2 = (Gallery) secondRow[2];
assertEquals(g1, g2);
}
});
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLFetchJoinIT method testFetchJoinForOneEntity.
@Test
public void testFetchJoinForOneEntity() throws Exception {
createOneFetchJoinDataSet();
String ejbql = "SELECT a FROM Artist a JOIN FETCH a.paintingArray ";
EJBQLQuery query = new EJBQLQuery(ejbql);
final List<?> objects = context.performQuery(query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, objects.size());
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Artist a = (Artist) it.next();
List<Painting> list = a.getPaintingArray();
assertNotNull(list);
assertFalse(((ValueHolder) list).isFault());
for (Painting p : list) {
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
// make sure properties are not null..
assertNotNull(p.getPaintingTitle());
}
}
}
});
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLFlattenedRelationshipsIT method testCollectionSubquery.
@Test
public void testCollectionSubquery() throws Exception {
createFt123();
String ejbql = "SELECT ft FROM FlattenedTest1 ft " + "WHERE (SELECT COUNT(f) FROM ft.ft3Array f) = 1";
EJBQLQuery query = new EJBQLQuery(ejbql);
// TODO fails but not because of flattened relationship,
// the reason is that property "ft3Array" inside the subquery
// parses as unmapped
/*
* List<?> objects = context.performQuery(query); assertNotNull(objects);
* assertFalse(objects.isEmpty()); 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(2)));
*/
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLFlattenedRelationshipsIT method testCollectionMemberOfThetaJoinLongRelationshipSequence.
@Test
public void testCollectionMemberOfThetaJoinLongRelationshipSequence() throws Exception {
createFt1234();
String ejbql = "SELECT f FROM FlattenedTest4 f, FlattenedTest1 ft " + "WHERE f MEMBER OF ft.ft4ArrayFor1 AND ft = :ft";
FlattenedTest1 ft = Cayenne.objectForPK(context, FlattenedTest1.class, 1);
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("ft", ft);
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(1)));
ft = Cayenne.objectForPK(context, FlattenedTest1.class, 2);
query = new EJBQLQuery(ejbql);
query.setParameter("ft", ft);
objects = context.performQuery(query);
assertEquals(0, objects.size());
}
Aggregations