use of org.apache.cayenne.testdo.things.Ball 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.testdo.things.Ball 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.Ball in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testMultiColumnRelationship.
@Test
public void testMultiColumnRelationship() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery query = new SelectQuery(Ball.class);
query.orQualifier(Ball.THING_VOLUME.eq(40).andExp(Ball.THING_WEIGHT.eq(30)));
query.orQualifier(Ball.THING_VOLUME.eq(20).andExp(Ball.THING_WEIGHT.eq(10)));
query.addPrefetch(Ball.THING.disjointById());
final List<Ball> balls = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, balls.size());
balls.get(0).getThing().getVolume();
balls.get(1).getThing().getVolume();
}
});
}
use of org.apache.cayenne.testdo.things.Ball in project cayenne by apache.
the class DataContextDisjointByIdPrefetch_ExtrasIT method testFlattenedRelationship.
@Test
public void testFlattenedRelationship() throws Exception {
createBagWithTwoBoxesAndPlentyOfBallsDataSet();
SelectQuery query = new SelectQuery(Bag.class);
query.addPrefetch(Bag.BALLS.disjointById());
final List<Bag> result = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertFalse(result.isEmpty());
Bag b1 = result.get(0);
List<Ball> balls = (List<Ball>) b1.readPropertyDirectly(Bag.BALLS.getName());
assertNotNull(balls);
assertFalse(((ValueHolder) balls).isFault());
assertEquals(6, balls.size());
List<Integer> volumes = new ArrayList<Integer>();
for (Ball b : balls) {
assertEquals(PersistenceState.COMMITTED, b.getPersistenceState());
volumes.add(b.getThingVolume());
}
assertTrue(volumes.containsAll(Arrays.asList(10, 20, 30, 40, 20, 40)));
}
});
}
Aggregations