Search in sources :

Example 1 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class NestedDataContextWriteIT method testCommitChangesToParentPropagatedKey.

@Test
public void testCommitChangesToParentPropagatedKey() throws Exception {
    final DataContext context = createDataContext();
    final ObjectContext childContext = runtime.newContext(context);
    final Painting childMaster = childContext.newObject(Painting.class);
    childMaster.setPaintingTitle("Master");
    final PaintingInfo childDetail1 = childContext.newObject(PaintingInfo.class);
    childDetail1.setTextReview("Detail1");
    childDetail1.setPainting(childMaster);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            childContext.commitChangesToParent();
            assertEquals(PersistenceState.COMMITTED, childMaster.getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childDetail1.getPersistenceState());
            Painting parentMaster = (Painting) context.getGraphManager().getNode(childMaster.getObjectId());
            assertNotNull(parentMaster);
            assertEquals(PersistenceState.NEW, parentMaster.getPersistenceState());
            PaintingInfo parentDetail1 = (PaintingInfo) context.getGraphManager().getNode(childDetail1.getObjectId());
            assertNotNull(parentDetail1);
            assertEquals(PersistenceState.NEW, parentDetail1.getPersistenceState());
            assertSame(parentMaster, parentDetail1.getPainting());
            assertSame(parentDetail1, parentMaster.getToPaintingInfo());
        }
    });
}
Also used : UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectContext(org.apache.cayenne.ObjectContext) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 2 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo 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 3 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class DataContextPrefetchIT method testPrefetchJointAndDisjointByIdTogether.

@Test
public void testPrefetchJointAndDisjointByIdTogether() throws Exception {
    createArtistWithTwoPaintingsAndTwoInfosDataSet();
    SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
    query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
    query.addPrefetch(Painting.TO_ARTIST.joint());
    query.addPrefetch(Painting.TO_PAINTING_INFO.disjointById());
    final List<Painting> results = context.select(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(1, results.size());
            Painting p0 = results.get(0);
            Artist a0 = (Artist) p0.readPropertyDirectly(Painting.TO_ARTIST.getName());
            assertNotNull(a0);
            PaintingInfo info = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
            assertNotNull(info);
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) 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 4 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class DataContextPrefetchIT method testPrefetch_OneToOneWithQualifier.

@Test
public void testPrefetch_OneToOneWithQualifier() throws Exception {
    createArtistWithTwoPaintingsAndTwoInfosDataSet();
    Expression e = ExpressionFactory.likeExp("toArtist.artistName", "a%");
    SelectQuery q = new SelectQuery(Painting.class, e);
    q.addPrefetch(Painting.TO_PAINTING_INFO.disjoint());
    q.addOrdering(Painting.PAINTING_TITLE.asc());
    final List<Painting> results = context.performQuery(q);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(2, results.size());
            // testing non-null to-one target
            Painting p0 = results.get(0);
            Object o2 = p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
            assertTrue(o2 instanceof PaintingInfo);
            PaintingInfo pi2 = (PaintingInfo) o2;
            assertEquals(PersistenceState.COMMITTED, pi2.getPersistenceState());
            assertEquals(Cayenne.intPKForObject(p0), Cayenne.intPKForObject(pi2));
            // testing null to-one target
            Painting p1 = results.get(1);
            assertNull(p1.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName()));
            // there was a bug marking an object as dirty when clearing the
            // relationships
            assertEquals(PersistenceState.COMMITTED, p1.getPersistenceState());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Expression(org.apache.cayenne.exp.Expression) 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 5 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class CayenneDataObjectRelationshipsIT method testReadToOneRel2.

@Test
public void testReadToOneRel2() throws Exception {
    // test chained calls to read relationships
    createArtistWithPaintingAndInfoDataSet();
    PaintingInfo pi1 = Cayenne.objectForPK(context, PaintingInfo.class, 6);
    Painting p1 = pi1.getPainting();
    p1.getPaintingTitle();
    Artist a1 = p1.getToArtist();
    assertNotNull(a1);
    assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());
    assertEquals("aX", a1.getArtistName());
    assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

PaintingInfo (org.apache.cayenne.testdo.testmap.PaintingInfo)15 Painting (org.apache.cayenne.testdo.testmap.Painting)14 Test (org.junit.Test)14 SelectQuery (org.apache.cayenne.query.SelectQuery)6 Artist (org.apache.cayenne.testdo.testmap.Artist)6 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)6 ByteArrayTypeTest (org.apache.cayenne.access.types.ByteArrayTypeTest)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ObjectContext (org.apache.cayenne.ObjectContext)1 DataContext (org.apache.cayenne.access.DataContext)1 Expression (org.apache.cayenne.exp.Expression)1