Package org.apache.cayenne.testdo.testmap

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


        ObjectContext childContext = context.createChildContext();

        Artist childO1 = childContext.newObject(Artist.class);
        childO1.setArtistName("Master");

        ArtGroup childO2 = childContext.newObject(ArtGroup.class);
        childO2.setName("Detail1");
        childO2.addToArtistArray(childO1);

        assertEquals(1, childO1.getGroupArray().size());
        assertEquals(1, childO2.getArtistArray().size());

        try {
            childContext.commitChangesToParent();

            assertEquals(PersistenceState.COMMITTED, childO1.getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childO2.getPersistenceState());

            Artist parentO1 = (Artist) context.getGraphManager().getNode(
                    childO1.getObjectId());

            assertNotNull(parentO1);
            assertEquals(PersistenceState.NEW, parentO1.getPersistenceState());

            ArtGroup parentO2 = (ArtGroup) context.getGraphManager().getNode(
                    childO2.getObjectId());

            assertNotNull(parentO2);
            assertEquals(PersistenceState.NEW, parentO2.getPersistenceState());

            assertEquals(1, parentO1.getGroupArray().size());
            assertEquals(1, parentO2.getArtistArray().size());
            assertTrue(parentO2.getArtistArray().contains(parentO1));
            assertTrue(parentO1.getGroupArray().contains(parentO2));
        }
        finally {
            unblockQueries();
        }
View Full Code Here


        ObjectContext childContext = context.createChildContext();

        Artist childO1 = childContext.newObject(Artist.class);
        childO1.setArtistName("o1");

        ArtGroup childO2 = childContext.newObject(ArtGroup.class);
        childO2.setName("o2");
        childO2.addToArtistArray(childO1);

        childContext.commitChangesToParent();

        ArtGroup childO3 = childContext.newObject(ArtGroup.class);
        childO3.setName("o3");
        childO1.addToGroupArray(childO3);

        assertEquals(2, childO1.getGroupArray().size());
        assertEquals(1, childO2.getArtistArray().size());
        assertEquals(1, childO3.getArtistArray().size());

        try {
            childContext.commitChangesToParent();

            assertEquals(PersistenceState.COMMITTED, childO1.getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childO2.getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childO3.getPersistenceState());

            Artist parentO1 = (Artist) context.getGraphManager().getNode(
                    childO1.getObjectId());

            assertNotNull(parentO1);
            assertEquals(PersistenceState.NEW, parentO1.getPersistenceState());

            ArtGroup parentO2 = (ArtGroup) context.getGraphManager().getNode(
                    childO2.getObjectId());

            assertNotNull(parentO2);
            assertEquals(PersistenceState.NEW, parentO2.getPersistenceState());

            ArtGroup parentO3 = (ArtGroup) context.getGraphManager().getNode(
                    childO3.getObjectId());

            assertNotNull(parentO3);
            assertEquals(PersistenceState.NEW, parentO3.getPersistenceState());

            assertEquals(2, parentO1.getGroupArray().size());
            assertEquals(1, parentO2.getArtistArray().size());
            assertEquals(1, parentO3.getArtistArray().size());
            assertTrue(parentO2.getArtistArray().contains(parentO1));
            assertTrue(parentO3.getArtistArray().contains(parentO1));
            assertTrue(parentO1.getGroupArray().contains(parentO2));
            assertTrue(parentO1.getGroupArray().contains(parentO3));
        }
        finally {
            unblockQueries();
        }

        childO1.removeFromGroupArray(childO2);

        try {
            childContext.commitChangesToParent();

            assertEquals(PersistenceState.COMMITTED, childO1.getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childO2.getPersistenceState());
            assertEquals(PersistenceState.COMMITTED, childO3.getPersistenceState());

            Artist parentO1 = (Artist) context.getGraphManager().getNode(
                    childO1.getObjectId());

            assertNotNull(parentO1);
            assertEquals(PersistenceState.NEW, parentO1.getPersistenceState());

            ArtGroup parentO2 = (ArtGroup) context.getGraphManager().getNode(
                    childO2.getObjectId());

            assertNotNull(parentO2);
            assertEquals(PersistenceState.NEW, parentO2.getPersistenceState());

            ArtGroup parentO3 = (ArtGroup) context.getGraphManager().getNode(
                    childO3.getObjectId());

            assertNotNull(parentO3);
            assertEquals(PersistenceState.NEW, parentO3.getPersistenceState());

            assertEquals(1, parentO1.getGroupArray().size());
            assertEquals(0, parentO2.getArtistArray().size());
            assertEquals(1, parentO3.getArtistArray().size());

            assertTrue(parentO3.getArtistArray().contains(parentO1));
            assertTrue(parentO1.getGroupArray().contains(parentO3));
        }
        finally {
            unblockQueries();
        }
View Full Code Here

        List<Painting> results = context.performQuery(q);
        assertEquals(1, results.size());
    }

    public void testPrefetch_ReflexiveRelationship() throws Exception {
        ArtGroup parent = (ArtGroup) context.newObject("ArtGroup");
        parent.setName("parent");
        ArtGroup child = (ArtGroup) context.newObject("ArtGroup");
        child.setName("child");
        child.setToParentGroup(parent);
        context.commitChanges();

        SelectQuery q = new SelectQuery("ArtGroup");
        q.setQualifier(ExpressionFactory.matchExp("name", "child"));
        q.addPrefetch("toParentGroup");

        final List<ArtGroup> results = context.performQuery(q);

        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

            public void execute() {
                assertEquals(1, results.size());

                ArtGroup fetchedChild = results.get(0);
                // The parent must be fully fetched, not just HOLLOW (a fault)
                assertEquals(PersistenceState.COMMITTED, fetchedChild
                        .getToParentGroup()
                        .getPersistenceState());
            }
        });
    }
View Full Code Here

                assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
                assertTrue(list.size() > 0);

                Iterator children = list.iterator();
                while (children.hasNext()) {
                    ArtGroup g = (ArtGroup) children.next();
                    assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
                }

                // assert no duplicates
                Set s = new HashSet(list);
                assertEquals(s.size(), list.size());
View Full Code Here

                assertFalse("artist's groups not resolved: " + a, ((ValueHolder)list).isFault());
                assertTrue(list.size() > 0);

                Iterator children = list.iterator();
                while (children.hasNext()) {
                    ArtGroup g = (ArtGroup) children.next();
                    assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
                }

                // assert no duplicates
                Set s = new HashSet(list);
                assertEquals(s.size(), list.size());
View Full Code Here

                assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
                assertTrue(list.size() > 0);

                Iterator children = list.iterator();
                while (children.hasNext()) {
                    ArtGroup g = (ArtGroup) children.next();
                    assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
                }

                // assert no duplicates
                Set s = new HashSet(list);
                assertEquals(s.size(), list.size());
View Full Code Here

                assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
                assertTrue(list.size() > 0);

                Iterator children = list.iterator();
                while (children.hasNext()) {
                    ArtGroup g = (ArtGroup) children.next();
                    assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
                }

                // assert no duplicates

                Set s = new HashSet(list);
View Full Code Here

        assertEquals(0, plist.size());
    }

    public void testReflexiveRelationshipInsertOrder1() {

        ArtGroup parentGroup = context.newObject(ArtGroup.class);
        parentGroup.setName("parent");

        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
        childGroup1.setName("child1");
        childGroup1.setToParentGroup(parentGroup);
        context.commitChanges();
    }
View Full Code Here

        context.commitChanges();
    }

    public void testReflexiveRelationshipInsertOrder2() {

        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
        childGroup1.setName("child1");

        ArtGroup parentGroup = context.newObject(ArtGroup.class);
        parentGroup.setName("parent");

        childGroup1.setToParentGroup(parentGroup);

        context.commitChanges();
    }
View Full Code Here

    }

    public void testReflexiveRelationshipInsertOrder3() {
        // multiple children, one created before parent, one after

        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
        childGroup1.setName("child1");

        ArtGroup parentGroup = context.newObject(ArtGroup.class);
        parentGroup.setName("parent");

        childGroup1.setToParentGroup(parentGroup);

        ArtGroup childGroup2 = context.newObject(ArtGroup.class);
        childGroup2.setName("child2");
        childGroup2.setToParentGroup(parentGroup);

        context.commitChanges();
    }
View Full Code Here

TOP

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

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.