Examples of ArtGroup


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

        context = createDataContext();
    }

    public void testNullifyToOne() {
        // ArtGroup toParentGroup
        ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
        parentGroup.setName("Parent");

        ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
        childGroup.setName("Child");
        parentGroup.addToChildGroupsArray(childGroup);

        // Check to make sure that the relationships are both exactly correct
        // before starting. We're not really testing this, but it is imperative
        // that it is correct before testing the real details.
        assertEquals(parentGroup, childGroup.getToParentGroup());
        assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));

        // Always good to commit before deleting... bad things happen otherwise
        context.commitChanges();
View Full Code Here

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

     * Tests that deleting a source of a flattened relationship with CASCADE rule results
     * in deleting a join and a target.
     */
    public void testCascadeToManyFlattened() {
        // testing Artist.groupArray relationship
        ArtGroup aGroup = context.newObject(ArtGroup.class);
        aGroup.setName("Group Name");
        Artist anArtist = context.newObject(Artist.class);
        anArtist.setArtistName("A Name");
        anArtist.addToGroupArray(aGroup);
        assertTrue(anArtist.getGroupArray().contains(aGroup));

        context.commitChanges();

        SQLTemplate checkQuery = new SQLTemplate(
                Artist.class,
                "SELECT * FROM ARTIST_GROUP");
        checkQuery.setFetchingDataRows(true);
        List<?> joins1 = context.performQuery(checkQuery);
        assertEquals(1, joins1.size());

        context.deleteObject(anArtist);

        assertEquals(PersistenceState.DELETED, aGroup.getPersistenceState());
        assertFalse(anArtist.getGroupArray().contains(aGroup));
        context.commitChanges();

        List<?> joins2 = context.performQuery(checkQuery);
        assertEquals(0, joins2.size());
View Full Code Here

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

     * Tests that deleting a source of a flattened relationship with NULLIFY rule results
     * in deleting a join together with the object deleted.
     */
    public void testNullifyToManyFlattened() {
        // testing ArtGroup.artistArray relationship
        ArtGroup aGroup = context.newObject(ArtGroup.class);
        aGroup.setName("Group Name");
        Artist anArtist = context.newObject(Artist.class);
        anArtist.setArtistName("A Name");
        aGroup.addToArtistArray(anArtist);

        context.commitChanges();

        // Preconditions
        assertTrue(aGroup.getArtistArray().contains(anArtist));
        assertTrue(anArtist.getGroupArray().contains(aGroup));

        SQLTemplate checkQuery = new SQLTemplate(
                Artist.class,
                "SELECT * FROM ARTIST_GROUP");
View Full Code Here

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

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

    public void testNullifyToMany() {
        // ArtGroup childGroupsArray
        ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
        parentGroup.setName("Parent");

        ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
        childGroup.setName("Child");
        parentGroup.addToChildGroupsArray(childGroup);

        // Preconditions - good to check to be sure
        assertEquals(parentGroup, childGroup.getToParentGroup());
        assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));

        context.commitChanges();

        context.deleteObject(parentGroup);

        // The things we are testing.
        assertNull(childGroup.getToParentGroup());

        // Although deleted, the property should be null (good cleanup policy)
        // assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
        context.commitChanges();
    }
View Full Code Here

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

        final ObjectContext childContext = context.createChildContext();

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

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

        ObjEntity ent = childContext.getEntityResolver().getObjEntity("ArtGroup");
        Collection<ObjRelationship> rels = ent.getDeclaredRelationships();
        for (ObjRelationship rel : rels) {
            System.out.println(rel.getName());
        }

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

        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

            public void execute() {
                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));
            }
        });
    }
View Full Code Here

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

        final ObjectContext childContext = context.createChildContext();

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

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

        childContext.commitChangesToParent();

        final 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());

        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

            public void execute() {
                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));
            }
        });

        childO1.removeFromGroupArray(childO2);

        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

            public void execute() {
                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));
            }
        });
    }
View Full Code Here

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

        dbHelper.deleteAll("GALLERY");
    }

    public void testNullifyToOne() {
        // ArtGroup toParentGroup
        ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
        parentGroup.setName("Parent");

        ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
        childGroup.setName("Child");
        parentGroup.addToChildGroupsArray(childGroup);

        // Check to make sure that the relationships are both exactly correct
        // before starting. We're not really testing this, but it is imperative
        // that it is correct before testing the real details.
        assertEquals(parentGroup, childGroup.getToParentGroup());
        assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));

        // Always good to commit before deleting... bad things happen otherwise
        context.commitChanges();
View Full Code Here

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

     * Tests that deleting a source of a flattened relationship with CASCADE rule results
     * in deleting a join and a target.
     */
    public void testCascadeToManyFlattened() {
        // testing Artist.groupArray relationship
        ArtGroup aGroup = context.newObject(ArtGroup.class);
        aGroup.setName("Group Name");
        Artist anArtist = context.newObject(Artist.class);
        anArtist.setArtistName("A Name");
        anArtist.addToGroupArray(aGroup);
        assertTrue(anArtist.getGroupArray().contains(aGroup));

        context.commitChanges();

        SQLTemplate checkQuery = new SQLTemplate(
                Artist.class,
                "SELECT * FROM ARTIST_GROUP");
        checkQuery.setFetchingDataRows(true);
        List<?> joins1 = context.performQuery(checkQuery);
        assertEquals(1, joins1.size());

        context.deleteObjects(anArtist);

        assertEquals(PersistenceState.DELETED, aGroup.getPersistenceState());
        assertFalse(anArtist.getGroupArray().contains(aGroup));
        context.commitChanges();

        List<?> joins2 = context.performQuery(checkQuery);
        assertEquals(0, joins2.size());
View Full Code Here

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

     * Tests that deleting a source of a flattened relationship with NULLIFY rule results
     * in deleting a join together with the object deleted.
     */
    public void testNullifyToManyFlattened() {
        // testing ArtGroup.artistArray relationship
        ArtGroup aGroup = context.newObject(ArtGroup.class);
        aGroup.setName("Group Name");
        Artist anArtist = context.newObject(Artist.class);
        anArtist.setArtistName("A Name");
        aGroup.addToArtistArray(anArtist);

        context.commitChanges();

        // Preconditions
        assertTrue(aGroup.getArtistArray().contains(anArtist));
        assertTrue(anArtist.getGroupArray().contains(aGroup));

        SQLTemplate checkQuery = new SQLTemplate(
                Artist.class,
                "SELECT * FROM ARTIST_GROUP");
View Full Code Here

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

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

    public void testNullifyToMany() {
        // ArtGroup childGroupsArray
        ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
        parentGroup.setName("Parent");

        ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
        childGroup.setName("Child");
        parentGroup.addToChildGroupsArray(childGroup);

        // Preconditions - good to check to be sure
        assertEquals(parentGroup, childGroup.getToParentGroup());
        assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));

        context.commitChanges();

        context.deleteObjects(parentGroup);

        // The things we are testing.
        assertNull(childGroup.getToParentGroup());

        // Although deleted, the property should be null (good cleanup policy)
        // assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
        context.commitChanges();
    }
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.