Examples of Painting


Examples of org.apache.cayenne.testdo.testmap.Painting

        DataContext context = createDataContext();

        Artist a = context.newObject(Artist.class);
        Artist altA = context.newObject(Artist.class);

        Painting p = context.newObject(Painting.class);
        p.setToArtist(a);
        p.setPaintingTitle("PPP");
        a.setArtistName("X");
        altA.setArtistName("Y");
        context.commitChanges();

        ObjectContext peer1 = context.createChildContext();
        Painting p1 = (Painting) peer1.localObject(p.getObjectId(), p);
        Artist altA1 = (Artist) peer1.localObject(altA.getObjectId(), altA);

        ObjectContext peer2 = context.createChildContext();
        Painting p2 = (Painting) peer2.localObject(p.getObjectId(), p);
        Artist altA2 = (Artist) peer2.localObject(altA.getObjectId(), altA);
        Artist a2 = (Artist) peer2.localObject(a.getObjectId(), a);

        p1.setToArtist(altA1);
        assertSame(a2, p2.getToArtist());
        peer1.commitChangesToParent();
        assertEquals(altA2, p2.getToArtist());

        assertFalse("Peer data context became dirty on event processing", peer2
                .hasChanges());
    }
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

        DataContext context = createDataContext();

        Artist a = context.newObject(Artist.class);
        a.setArtistName("X");

        Painting px = context.newObject(Painting.class);
        px.setToArtist(a);
        px.setPaintingTitle("PX");

        Painting py = context.newObject(Painting.class);
        py.setPaintingTitle("PY");

        context.commitChanges();

        ObjectContext peer1 = context.createChildContext();
        Painting py1 = (Painting) peer1.localObject(py.getObjectId(), py);
        Artist a1 = (Artist) peer1.localObject(a.getObjectId(), a);

        ObjectContext peer2 = context.createChildContext();
        Painting py2 = (Painting) peer2.localObject(py.getObjectId(), py);
        Artist a2 = (Artist) peer2.localObject(a.getObjectId(), a);

        a1.addToPaintingArray(py1);
        assertEquals(1, a2.getPaintingArray().size());
        assertFalse(a2.getPaintingArray().contains(py2));
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

        // Create an artist in the same context.
        Artist a = context.newObject(Artist.class);
        a.setArtistName("Test Artist");

        // Create a painting in the same context.
        Painting p = context.newObject(Painting.class);
        p.setPaintingTitle("Test Painting");

        // Set the painting's gallery.
        p.setToGallery(g);
        assertEquals(g, p.getToGallery());

        // Unregister the painting from the context.
        context.unregisterObjects(Collections.singletonList(p));

        // Make sure that even though the painting has been removed from the context's
        // object graph that the reference to the gallery is the same.
        assertEquals(g, p.getToGallery());

        // Now, set the relationship between "p" & "a." Since "p" is not registered with a
        // context, but "a" is, "p" should be auto-registered with the context of "a."
        p.setToArtist(a);

        // Now commit the gallery, artist, & painting.
        context.commitChanges();

        // Check one last time that the painting's gallery is set to what we expect.
        assertEquals(g, p.getToGallery());

        // Now, retrieve the same painting from the DB. Note that the gallery relationship
        // is null even though according to our painting, that should not be the case; a
        // NULL
        // value has been recorded to the DB for the painting's gallery_id field.
        //
        // The full object graph is not being re-registered during auto-registration
        // with the context.
        Painting newP = (Painting) Cayenne.objectForPK(createDataContext(), p
                .getObjectId());
        assertNotNull(newP.getToGallery());
    }
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

        a1.setArtistName("a1");

        Artist a2 = context.newObject(Artist.class);
        a2.setArtistName("a2");

        Painting p12 = context.newObject(Painting.class);
        p12.setPaintingTitle("p12");
        a2.addToPaintingArray(p12);
        Painting p22 = context.newObject(Painting.class);
        p22.setPaintingTitle("p22");
        a2.addToPaintingArray(p22);

        context.commitChanges();

        // this fails:
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

                Artist.ARTIST_NAME_PROPERTY,
                "artist1"));
        Artist artist = (Artist) context.performQuery(query).get(0);

        // test FK relationship snapshotting
        Painting p1 = new Painting();
        context.registerNewObject(p1);
        p1.setToArtist(artist);

        DataRow s1 = context.currentSnapshot(p1);
        Map<String, Object> idMap = artist.getObjectId().getIdSnapshot();
        assertEquals(idMap.get("ARTIST_ID"), s1.get("ARTIST_ID"));
    }
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

        SelectQuery query = new SelectQuery(ROArtist.class, ExpressionFactory.matchExp(
                Artist.ARTIST_NAME_PROPERTY,
                "artist1"));
        ROArtist a1 = (ROArtist) context.performQuery(query).get(0);

        Painting painting = context.newObject(Painting.class);
        painting.setPaintingTitle("paint");
        a1.addToPaintingArray(painting);

        assertEquals(PersistenceState.MODIFIED, a1.getPersistenceState());
        try {
            context.commitChanges();
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

        DataContext context = createDataContext();
        ObjectContext childContext = context.createChildContext();

        Artist a = Cayenne.objectForPK(childContext, Artist.class, 33001);
        Painting p = childContext.newObject(Painting.class);
        p.setPaintingTitle("X");
        a.addToPaintingArray(p);

        childContext.commitChangesToParent();

        childContext.deleteObject(p);
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

        DataContext context = createDataContext();
        ObjectContext childContext = context.createChildContext();
        ObjectContext childContextPeer = context.createChildContext();

        Painting childP1 = Cayenne.objectForPK(
                childContext,
                Painting.class,
                33001);

        // trigger object creation in the peer nested DC
        Cayenne.objectForPK(childContextPeer, Painting.class, 33001);
        childP1.setToArtist(null);

        blockQueries();

        try {
            childContext.commitChangesToParent();
            assertEquals(PersistenceState.COMMITTED, childP1.getPersistenceState());

            Painting parentP1 = (Painting) context.getGraphManager().getNode(
                    childP1.getObjectId());

            assertNotNull(parentP1);
            assertEquals(PersistenceState.MODIFIED, parentP1.getPersistenceState());
            assertNull(parentP1.getToArtist());
        }
        finally {
            unblockQueries();
        }
    }
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

        query.addOrdering(Painting.PAINTING_TITLE_PROPERTY, SortOrder.ASCENDING);
        List objects = childContext.performQuery(query);

        assertEquals(6, objects.size());

        Painting childModifiedSimple = (Painting) objects.get(0);
        childModifiedSimple.setPaintingTitle("C_PT");

        Painting childModifiedToOne = (Painting) objects.get(1);
        childModifiedToOne.setToArtist(childModifiedSimple.getToArtist());

        Artist childModifiedToMany = ((Painting) objects.get(2)).getToArtist();

        // ensure painting array is fully resolved...
        childModifiedToMany.getPaintingArray().size();
        childModifiedToMany.addToPaintingArray((Painting) objects.get(3));

        blockQueries();

        Painting parentModifiedSimple = null;
        Artist parentModifiedToMany = null;
        try {

            childContext.commitChangesToParent();

            assertEquals(PersistenceState.COMMITTED, childModifiedSimple
                    .getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childModifiedToOne
                    .getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childModifiedToMany
                    .getPersistenceState());

            parentModifiedSimple = (Painting) context.getGraphManager().getNode(
                    childModifiedSimple.getObjectId());

            Painting parentModifiedToOne = (Painting) context.getGraphManager().getNode(
                    childModifiedToOne.getObjectId());

            parentModifiedToMany = (Artist) context.getGraphManager().getNode(
                    childModifiedToMany.getObjectId());

            assertNotNull(parentModifiedSimple);
            assertEquals(PersistenceState.MODIFIED, parentModifiedSimple
                    .getPersistenceState());
            assertEquals("C_PT", parentModifiedSimple.getPaintingTitle());
            assertNotNull(context.getObjectStore().getChangesByObjectId().get(
                    parentModifiedSimple.getObjectId()));

            assertNotNull(parentModifiedToOne);
            assertEquals(PersistenceState.MODIFIED, parentModifiedToOne
                    .getPersistenceState());
            assertNotNull(parentModifiedToOne.getToArtist());
            assertEquals(33001, Cayenne.intPKForObject(parentModifiedToOne
                    .getToArtist()));
            assertNotNull(context.getObjectStore().getChangesByObjectId().get(
                    parentModifiedToOne.getObjectId()));

            // indirectly modified....
            assertNotNull(parentModifiedToMany);
            assertEquals(PersistenceState.MODIFIED, parentModifiedToMany
                    .getPersistenceState());
View Full Code Here

Examples of org.apache.cayenne.testdo.testmap.Painting

        deleteTestData();

        DataContext context = createDataContext();
        ObjectContext childContext = context.createChildContext();

        Painting childMaster = childContext.newObject(Painting.class);
        childMaster.setPaintingTitle("Master");

        PaintingInfo childDetail1 = childContext.newObject(PaintingInfo.class);
        childDetail1.setTextReview("Detail1");
        childDetail1.setPainting(childMaster);

        try {
            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());
        }
        finally {
            unblockQueries();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.