use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class DataContextDisjointByIdPrefetchIT method testOneToMany.
@Test
public void testOneToMany() throws Exception {
createArtistWithTwoPaintingsDataSet();
SelectQuery query = new SelectQuery(Artist.class);
query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
final List<Artist> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
Artist b1 = result.get(0);
List<Painting> toMany = (List<Painting>) b1.readPropertyDirectly(Artist.PAINTING_ARRAY.getName());
assertNotNull(toMany);
assertFalse(((ValueHolder) toMany).isFault());
assertEquals(2, toMany.size());
List<String> names = new ArrayList<String>();
for (Painting b : toMany) {
assertEquals(PersistenceState.COMMITTED, b.getPersistenceState());
names.add(b.getPaintingTitle());
}
assertTrue(names.contains("Y1"));
assertTrue(names.contains("Y2"));
}
});
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testJointPrefetchInChild.
@Test
public void testJointPrefetchInChild() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery<Bag> query = new SelectQuery<Bag>(Bag.class);
query.addPrefetch(Bag.BOXES.disjointById());
query.addPrefetch(Bag.BOXES.dot(Box.BALLS).joint());
final List<Bag> result = context.select(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
assertFalse(result.isEmpty());
Bag bag = result.get(0);
List<Box> boxes = (List<Box>) bag.readPropertyDirectly(Bag.BOXES.getName());
assertNotNull(boxes);
assertFalse(((ValueHolder) boxes).isFault());
assertEquals(2, boxes.size());
Box big = null;
List<String> names = new ArrayList<String>();
for (Box box : boxes) {
assertEquals(PersistenceState.COMMITTED, box.getPersistenceState());
names.add(box.getName());
if (box.getName().equals("big")) {
big = box;
}
}
assertTrue(names.contains("big"));
assertTrue(names.contains("small"));
List<Ball> balls = (List<Ball>) big.readPropertyDirectly(Box.BALLS.getName());
assertNotNull(balls);
assertFalse(((ValueHolder) balls).isFault());
assertEquals(2, balls.size());
List<Integer> volumes = new ArrayList<Integer>();
for (Ball ball : balls) {
assertEquals(PersistenceState.COMMITTED, ball.getPersistenceState());
volumes.add(ball.getThingVolume());
}
assertTrue(volumes.containsAll(Arrays.asList(10, 20)));
}
});
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testJointPrefetchInParent.
@Test
public void testJointPrefetchInParent() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery query = new SelectQuery(Box.class);
query.addPrefetch(Box.BALLS.disjointById());
query.addPrefetch(Box.BALLS.dot(Ball.THING).disjointById());
final List<Box> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
List<Integer> volumes = new ArrayList<Integer>();
for (Box box : result) {
List<Ball> balls = (List<Ball>) box.readPropertyDirectly(Box.BALLS.getName());
assertNotNull(balls);
assertFalse(((ValueHolder) balls).isFault());
for (Ball ball : balls) {
Thing thing = (Thing) ball.readPropertyDirectly(Ball.THING.getName());
assertNotNull(thing);
assertEquals(PersistenceState.COMMITTED, thing.getPersistenceState());
volumes.add(thing.getVolume());
}
}
assertEquals(6, volumes.size());
assertTrue(volumes.containsAll(Arrays.asList(10, 20, 30, 40)));
}
});
}
use of org.apache.cayenne.ValueHolder 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.ValueHolder 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());
}
}
}
});
}
Aggregations