Package org.apache.cayenne.testdo.testmap

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


        if (!accessStackAdapter.supportsTrimChar()) {
            return;
        }

        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("XXXA");

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

        EJBQLQuery query = new EJBQLQuery(
                "SELECT a FROM Artist a WHERE TRIM('X' FROM a.artistName) = 'A'");
        List<?> objects = context.performQuery(query);
View Full Code Here


            }
        };

        // make sure we have a fully resolved copy of an artist object
        // in the second context
        Artist altArtist = (Artist) altContext.localObject(artist.getObjectId(), null);
        assertNotNull(altArtist);
        assertNotSame(altArtist, artist);
        assertEquals(artist.getArtistName(), altArtist.getArtistName());
        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());

        altContext.setDelegate(delegate);

        // Update and save artist in peer context
        artist.setArtistName("version2");
View Full Code Here

        };
        altContext.setDelegate(delegate);

        // make sure we have a fully resolved copy of an artist object
        // in the second context
        Artist altArtist = (Artist) altContext.getObjectStore().getNode(
                artist.getObjectId());
        assertNotNull(altArtist);
        assertFalse(altArtist == artist);
        assertEquals(oldName, altArtist.getArtistName());
        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());

        // Update and save artist in peer context
        artist.setArtistName("version2");
        context.commitChanges();

        // assert that delegate was able to block the merge
        assertEquals(oldName, altArtist.getArtistName());
    }
View Full Code Here

        };
        altContext.setDelegate(delegate);

        // make sure we have a fully resolved copy of an artist object
        // in the second context
        Artist altArtist = (Artist) altContext.getGraphManager().getNode(
                artist.getObjectId());
        assertNotNull(altArtist);
        assertFalse(altArtist == artist);
        assertEquals(artist.getArtistName(), altArtist.getArtistName());
        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());

        // Update and save artist in peer context
        context.deleteObject(artist);
        context.commitChanges();
View Full Code Here

        };
        altContext.setDelegate(delegate);

        // make sure we have a fully resolved copy of an artist object
        // in the second context
        Artist altArtist = (Artist) altContext.getObjectStore().getNode(
                artist.getObjectId());
        assertNotNull(altArtist);
        assertFalse(altArtist == artist);
        assertEquals(artist.getArtistName(), altArtist.getArtistName());
        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());

        // Update and save artist in peer context
        context.deleteObject(artist);
        context.commitChanges();

        // assert that delegate was consulted when an object store
        // was refreshed, and actually blocked object expulsion
        ThreadedTestHelper helper = new ThreadedTestHelper() {

            @Override
            protected void assertResult() throws Exception {
                assertTrue("Delegate was not consulted", methodInvoked[0]);
            }
        };
        helper.assertWithTimeout(3000);
        assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
        assertNotNull(altArtist.getObjectContext());
    }
View Full Code Here

        createTestData("testDeleteNew");

        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);
        a.removeFromPaintingArray(p);

        childContext.commitChangesToParent();
    }
View Full Code Here

        query.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
        List objects = childContext.performQuery(query);

        assertEquals(4, objects.size());

        Artist childNew = childContext.newObject(Artist.class);
        childNew.setArtistName("NNN");

        Artist childModified = (Artist) objects.get(0);
        childModified.setArtistName("MMM");

        Artist childCommitted = (Artist) objects.get(1);

        Artist childHollow = (Artist) objects.get(3);
        childContext.invalidateObjects(Collections.singleton(childHollow));

        blockQueries();

        try {
            childContext.commitChangesToParent();

            // * all modified child objects must be in committed state now
            // * all modifications should be propagated to the parent
            // * no actual commit should occur.

            assertEquals(PersistenceState.COMMITTED, childNew.getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childModified.getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childCommitted.getPersistenceState());
            assertEquals(PersistenceState.HOLLOW, childHollow.getPersistenceState());

            Artist parentNew = (Artist) context.getGraphManager().getNode(
                    childNew.getObjectId());
            Artist parentModified = (Artist) context.getGraphManager().getNode(
                    childModified.getObjectId());
            Artist parentCommitted = (Artist) context.getGraphManager().getNode(
                    childCommitted.getObjectId());
            Artist parentHollow = (Artist) context.getGraphManager().getNode(
                    childHollow.getObjectId());

            assertNotNull(parentNew);
            assertEquals(PersistenceState.NEW, parentNew.getPersistenceState());
            assertEquals("NNN", parentNew.getArtistName());
View Full Code Here

        List objects = childContext.performQuery(query);

        assertEquals(4, objects.size());

        // delete AND modify
        Artist childDeleted = (Artist) objects.get(2);
        childContext.deleteObject(childDeleted);
        childDeleted.setArtistName("DDD");

        // don't block queries - on delete Cayenne may need to resolve delete rules via
        // fetch
        childContext.commitChangesToParent();

        // * all modified child objects must be in committed state now
        // * all modifications should be propagated to the parent
        // * no actual commit should occur.

        assertEquals(PersistenceState.TRANSIENT, childDeleted.getPersistenceState());

        Artist parentDeleted = (Artist) context.getGraphManager().getNode(
                childDeleted.getObjectId());

        assertNotNull(parentDeleted);
        assertEquals(PersistenceState.DELETED, parentDeleted.getPersistenceState());
        assertEquals("DDD", parentDeleted.getArtistName());
    }
View Full Code Here

        query.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.ASCENDING);
        List objects = childContext.performQuery(query);

        assertEquals(4, objects.size());

        Artist childNew = childContext.newObject(Artist.class);
        childNew.setArtistName("NNN");

        Artist childModified = (Artist) objects.get(0);
        childModified.setArtistName("MMM");

        Artist childCommitted = (Artist) objects.get(1);

        // delete AND modify
        Artist childDeleted = (Artist) objects.get(2);
        childContext.deleteObject(childDeleted);
        childDeleted.setArtistName("DDD");

        Artist childHollow = (Artist) objects.get(3);
        childContext.invalidateObjects(Collections.singleton(childHollow));

        childContext.commitChanges();

        assertEquals(PersistenceState.COMMITTED, childNew.getPersistenceState());
        assertEquals(PersistenceState.COMMITTED, childModified.getPersistenceState());
        assertEquals(PersistenceState.COMMITTED, childCommitted.getPersistenceState());
        assertEquals(PersistenceState.TRANSIENT, childDeleted.getPersistenceState());
        assertEquals(PersistenceState.HOLLOW, childHollow.getPersistenceState());

        Artist parentNew = (Artist) context.getGraphManager().getNode(
                childNew.getObjectId());
        Artist parentModified = (Artist) context.getGraphManager().getNode(
                childModified.getObjectId());
        Artist parentCommitted = (Artist) context.getGraphManager().getNode(
                childCommitted.getObjectId());
        Artist parentDeleted = (Artist) context.getGraphManager().getNode(
                childDeleted.getObjectId());
        Artist parentHollow = (Artist) context.getGraphManager().getNode(
                childHollow.getObjectId());

        assertNotNull(parentNew);
        assertEquals(PersistenceState.COMMITTED, parentNew.getPersistenceState());
        assertEquals("NNN", parentNew.getArtistName());
View Full Code Here

        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());
        }
        finally {
            unblockQueries();
        }

        // here query is expected, as the parent was hollow and its to-many relationship
        // is unresolved
        List paintings = parentModifiedToMany.getPaintingArray();
        assertEquals(2, paintings.size());
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.testdo.testmap.Artist

Copyright © 2018 www.massapicom. 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.