Search in sources :

Example 81 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextMaxIdQualifierIT method testDisjointByIdPrefetch.

@Test
public void testDisjointByIdPrefetch() throws Exception {
    insertData();
    runtime.getDataDomain().setMaxIdQualifierSize(10);
    final SelectQuery query = new SelectQuery(Artist.class);
    query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
    int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            context.performQuery(query);
        }
    });
    assertEquals(11, queriesCount);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 82 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextMaxIdQualifierIT method testDisjointByIdPrefetch_Zero.

@Test
public void testDisjointByIdPrefetch_Zero() throws Exception {
    insertData();
    runtime.getDataDomain().setMaxIdQualifierSize(0);
    final SelectQuery query = new SelectQuery(Artist.class);
    query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
    int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            context.performQuery(query);
        }
    });
    assertEquals(2, queriesCount);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 83 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextDisjointByIdPrefetchIT method testFetchLimit.

@Test
public void testFetchLimit() throws Exception {
    createThreeArtistsWithPlentyOfPaintingsDataSet();
    final SelectQuery query = new SelectQuery(Artist.class);
    query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
    query.addOrdering("db:" + Artist.ARTIST_ID_PK_COLUMN, SortOrder.ASCENDING);
    query.setFetchLimit(2);
    // There will be only 2 bags in a result. The first bag has 5 boxes and
    // the second has 2. So we are expecting exactly 9 snapshots in the data
    // row store after performing the query.
    final List<Artist> bags = context.performQuery(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(2, bags.size());
            assertEquals(5, bags.get(0).getPaintingArray().size());
            assertEquals(2, bags.get(1).getPaintingArray().size());
            for (Artist b : bags) {
                b.getArtistName();
                for (Painting bx : b.getPaintingArray()) {
                    bx.getPaintingTitle();
                }
            }
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 84 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextDisjointByIdPrefetchIT method testOneToOneRelationship.

@Test
public void testOneToOneRelationship() throws Exception {
    createTwoPaintingsWithInfosDataSet();
    SelectQuery query = new SelectQuery(Painting.class);
    query.addPrefetch(Painting.TO_PAINTING_INFO.disjointById());
    final List<Painting> result = context.performQuery(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertFalse(result.isEmpty());
            List<String> boxColors = new ArrayList<String>();
            for (Painting box : result) {
                PaintingInfo info = (PaintingInfo) box.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
                assertNotNull(info);
                boxColors.add(info.getTextReview());
                assertEquals(PersistenceState.COMMITTED, info.getPersistenceState());
            }
            assertTrue(boxColors.containsAll(Arrays.asList("red", "green")));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) List(java.util.List) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 85 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextDisjointByIdPrefetchIT method testManyToOne.

@Test
public void testManyToOne() throws Exception {
    createArtistWithTwoPaintingsDataSet();
    SelectQuery query = new SelectQuery(Painting.class);
    query.addPrefetch(Painting.TO_ARTIST.disjointById());
    final List<Painting> result = context.performQuery(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertFalse(result.isEmpty());
            Painting b1 = result.get(0);
            assertNotNull(b1.getToArtist());
            assertEquals(PersistenceState.COMMITTED, b1.getToArtist().getPersistenceState());
            assertEquals("X", b1.getToArtist().getArtistName());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)107 Test (org.junit.Test)107 SelectQuery (org.apache.cayenne.query.SelectQuery)64 List (java.util.List)48 Artist (org.apache.cayenne.testdo.testmap.Artist)47 Painting (org.apache.cayenne.testdo.testmap.Painting)35 ValueHolder (org.apache.cayenne.ValueHolder)23 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)19 ArrayList (java.util.ArrayList)15 ObjectContext (org.apache.cayenne.ObjectContext)14 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)9 ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)8 Iterator (java.util.Iterator)7 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)7 Expression (org.apache.cayenne.exp.Expression)6 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 PaintingInfo (org.apache.cayenne.testdo.testmap.PaintingInfo)6 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)5 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)5 PersonNotes (org.apache.cayenne.testdo.inheritance_people.PersonNotes)5