Search in sources :

Example 31 with UnitTestClosure

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

the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicSharedCache.

@Test
public void testPolymorphicSharedCache() throws SQLException {
    tPerson.insert(1, "P1", "EM");
    final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", 1), false, ObjectIdQuery.CACHE);
    AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
    assertTrue(ap1 instanceof Manager);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        @Override
        public void execute() {
            // use different context to ensure we hit shared cache
            AbstractPerson ap2 = (AbstractPerson) Cayenne.objectForQuery(context2, q1);
            assertTrue(ap2 instanceof Manager);
        }
    });
}
Also used : ObjectId(org.apache.cayenne.ObjectId) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Example 32 with UnitTestClosure

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

the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicLocalCache.

@Test
public void testPolymorphicLocalCache() throws SQLException {
    tPerson.insert(1, "P1", "EM");
    final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", 1), false, ObjectIdQuery.CACHE);
    AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
    assertTrue(ap1 instanceof Manager);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        @Override
        public void execute() {
            // use same context to ensure we hit local cache
            // note that this does not guarantee test correctness. If local
            // cache polymorphic ID lookup is broken, shared cache will pick
            // it up
            AbstractPerson ap2 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
            assertTrue(ap2 instanceof Manager);
        }
    });
}
Also used : ObjectId(org.apache.cayenne.ObjectId) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) AbstractPerson(org.apache.cayenne.testdo.inheritance_people.AbstractPerson) Test(org.junit.Test)

Example 33 with UnitTestClosure

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

the class DataContextPerformQueryAPIIT method testObjectQueryWithLocalCache.

@Test
public void testObjectQueryWithLocalCache() throws Exception {
    createTwoArtists();
    List<?> artists = context.performQuery("QueryWithLocalCache", true);
    assertEquals(2, artists.size());
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> artists1 = context.performQuery("QueryWithLocalCache", false);
            assertEquals(2, artists1.size());
        }
    });
}
Also used : UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) Test(org.junit.Test)

Example 34 with UnitTestClosure

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

the class DataContextPrefetchIT method testPrefetchToOneWithBackRelationship.

@Test
public void testPrefetchToOneWithBackRelationship() throws Exception {
    createArtistWithTwoPaintingsAndTwoInfosDataSet();
    SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
    query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
    query.addPrefetch(Painting.TO_PAINTING_INFO.disjoint());
    query.addPrefetch(Painting.TO_PAINTING_INFO.dot(PaintingInfo.PAINTING).disjoint());
    final List<Painting> results = context.select(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(1, results.size());
            Painting p0 = results.get(0);
            PaintingInfo pi0 = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
            assertNotNull(pi0);
            assertNotNull(pi0.readPropertyDirectly(PaintingInfo.PAINTING.getName()));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 35 with UnitTestClosure

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

the class DataContextPrefetchIT method testPrefetch_ToManyNoReverseWithQualifier.

@Test
public void testPrefetch_ToManyNoReverseWithQualifier() throws Exception {
    createTwoArtistsAndTwoPaintingsDataSet();
    ObjEntity paintingEntity = context.getEntityResolver().getObjEntity(Painting.class);
    ObjRelationship relationship = paintingEntity.getRelationship("toArtist");
    paintingEntity.removeRelationship("toArtist");
    try {
        SelectQuery q = new SelectQuery(Artist.class);
        q.setQualifier(ExpressionFactory.matchExp("artistName", "artist2"));
        q.addPrefetch(Artist.PAINTING_ARRAY.disjoint());
        final List<Artist> result = context.performQuery(q);
        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

            public void execute() {
                assertFalse(result.isEmpty());
                Artist a1 = result.get(0);
                List<?> toMany = (List<?>) a1.readPropertyDirectly("paintingArray");
                assertNotNull(toMany);
                assertFalse(((ValueHolder) toMany).isFault());
            }
        });
    } finally {
        paintingEntity.addRelationship(relationship);
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) 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