use of org.apache.cayenne.testdo.things.Thing 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.testdo.things.Thing in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testFlattenedMultiColumnRelationship.
@Test
public void testFlattenedMultiColumnRelationship() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery query = new SelectQuery(Box.class);
query.addPrefetch(Box.THINGS.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<Thing> things = (List<Thing>) box.readPropertyDirectly(Box.THINGS.getName());
assertNotNull(things);
assertFalse(((ValueHolder) things).isFault());
for (Thing t : things) {
assertEquals(PersistenceState.COMMITTED, t.getPersistenceState());
volumes.add(t.getVolume());
}
}
assertEquals(6, volumes.size());
assertTrue(volumes.containsAll(Arrays.asList(10, 20, 30, 40)));
}
});
}
use of org.apache.cayenne.testdo.things.Thing in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testLongFlattenedRelationship.
@Test
public void testLongFlattenedRelationship() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery query = new SelectQuery(Bag.class);
query.addPrefetch(Bag.THINGS.disjointById());
final List<Bag> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
Bag b1 = result.get(0);
List<Thing> things = (List<Thing>) b1.readPropertyDirectly(Bag.THINGS.getName());
assertNotNull(things);
assertFalse(((ValueHolder) things).isFault());
assertEquals(6, things.size());
List<Integer> volumes = new ArrayList<Integer>();
for (Thing t : things) {
assertEquals(PersistenceState.COMMITTED, t.getPersistenceState());
volumes.add(t.getVolume());
}
assertTrue(volumes.containsAll(Arrays.asList(10, 20, 20, 30, 40, 40)));
}
});
}
Aggregations