Search in sources :

Example 1 with Thing

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)));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Ball(org.apache.cayenne.testdo.things.Ball) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Box(org.apache.cayenne.testdo.things.Box) ArrayList(java.util.ArrayList) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Thing(org.apache.cayenne.testdo.things.Thing) Test(org.junit.Test)

Example 2 with Thing

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)));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Box(org.apache.cayenne.testdo.things.Box) ArrayList(java.util.ArrayList) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Thing(org.apache.cayenne.testdo.things.Thing) Test(org.junit.Test)

Example 3 with Thing

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)));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Bag(org.apache.cayenne.testdo.things.Bag) ArrayList(java.util.ArrayList) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Thing(org.apache.cayenne.testdo.things.Thing) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 ValueHolder (org.apache.cayenne.ValueHolder)3 SelectQuery (org.apache.cayenne.query.SelectQuery)3 Thing (org.apache.cayenne.testdo.things.Thing)3 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)3 Test (org.junit.Test)3 Box (org.apache.cayenne.testdo.things.Box)2 Bag (org.apache.cayenne.testdo.things.Bag)1 Ball (org.apache.cayenne.testdo.things.Ball)1