Package org.apache.cayenne.testdo.relationship

Examples of org.apache.cayenne.testdo.relationship.MapToMany


    }

    public void testReadToMany() throws Exception {
        createTestData("prepare");

        MapToMany o1 = Cayenne.objectForPK(
                createDataContext(),
                MapToMany.class,
                1);

        Map targets = o1.getTargets();

        assertTrue(((ValueHolder) targets).isFault());

        assertNotNull(targets);
        assertEquals(3, targets.size());
View Full Code Here


        createTestData("prepare");

        SelectQuery query = new SelectQuery(MapToMany.class, ExpressionFactory
                .matchDbExp(MapToMany.ID_PK_COLUMN, new Integer(1)));
        query.addPrefetch(MapToMany.TARGETS_PROPERTY);
        MapToMany o1 = (MapToMany) Cayenne.objectForQuery(
                createDataContext(),
                query);

        Map targets = o1.getTargets();

        assertFalse(((ValueHolder) targets).isFault());

        assertNotNull(targets);
        assertEquals(3, targets.size());
View Full Code Here

    }

    public void testAddToMany() throws Exception {
        createTestData("prepare");

        MapToMany o1 = Cayenne.objectForPK(
                createDataContext(),
                MapToMany.class,
                1);

        Map targets = o1.getTargets();
        assertNotNull(targets);
        assertEquals(3, targets.size());

        MapToManyTarget newTarget = o1.getObjectContext().newObject(
                MapToManyTarget.class);

        newTarget.setName("X");
        o1.addToTargets(newTarget);
        assertEquals(4, targets.size());
        assertSame(newTarget, o1.getTargets().get("X"));
        assertSame(o1, newTarget.getMapToMany());

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(4, o1.getTargets().size());
    }
View Full Code Here

    }

    public void testRemoveToMany() throws Exception {
        createTestData("prepare");

        MapToMany o1 = Cayenne.objectForPK(
                createDataContext(),
                MapToMany.class,
                1);

        Map targets = o1.getTargets();
        assertEquals(3, targets.size());

        MapToManyTarget target = (MapToManyTarget) targets.get("B");
        o1.removeFromTargets(target);

        assertEquals(2, targets.size());
        assertNull(o1.getTargets().get("B"));
        assertNull(target.getMapToMany());

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(2, o1.getTargets().size());
        assertNotNull(o1.getTargets().get("A"));
        assertNotNull(o1.getTargets().get("C"));
    }
View Full Code Here

    }

    public void testAddToManyViaReverse() throws Exception {
        createTestData("prepare");

        MapToMany o1 = Cayenne.objectForPK(
                createDataContext(),
                MapToMany.class,
                1);

        Map targets = o1.getTargets();
        assertNotNull(targets);
        assertEquals(3, targets.size());

        MapToManyTarget newTarget = o1.getObjectContext().newObject(
                MapToManyTarget.class);

        newTarget.setName("X");
        newTarget.setMapToMany(o1);
        assertSame(o1, newTarget.getMapToMany());
        assertEquals(4, targets.size());
        assertSame(newTarget, o1.getTargets().get("X"));

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(4, o1.getTargets().size());
    }
View Full Code Here

    }

    public void testModifyToManyKey() throws Exception {
        createTestData("prepare");

        MapToMany o1 = Cayenne.objectForPK(
                createDataContext(),
                MapToMany.class,
                1);

        Map targets = o1.getTargets();
        MapToManyTarget target = (MapToManyTarget) targets.get("B");
        target.setName("B1");

        o1.getObjectContext().commitChanges();

        assertNull(o1.getTargets().get("B"));
        assertSame(target, o1.getTargets().get("B1"));
    }
View Full Code Here

    }

    public void testReadToMany() throws Exception {
        createTestData("prepare");

        MapToMany o1 = DataObjectUtils.objectForPK(
                createDataContext(),
                MapToMany.class,
                1);

        Map targets = o1.getTargets();

        assertTrue(((ValueHolder) targets).isFault());

        assertNotNull(targets);
        assertEquals(3, targets.size());
View Full Code Here

        createTestData("prepare");

        SelectQuery query = new SelectQuery(MapToMany.class, ExpressionFactory
                .matchDbExp(MapToMany.ID_PK_COLUMN, new Integer(1)));
        query.addPrefetch(MapToMany.TARGETS_PROPERTY);
        MapToMany o1 = (MapToMany) DataObjectUtils.objectForQuery(
                createDataContext(),
                query);

        Map targets = o1.getTargets();

        assertFalse(((ValueHolder) targets).isFault());

        assertNotNull(targets);
        assertEquals(3, targets.size());
View Full Code Here

    }

    public void testAddToMany() throws Exception {
        createTestData("prepare");

        MapToMany o1 = DataObjectUtils.objectForPK(
                createDataContext(),
                MapToMany.class,
                1);

        Map targets = o1.getTargets();
        assertNotNull(targets);
        assertEquals(3, targets.size());

        MapToManyTarget newTarget = o1.getObjectContext().newObject(
                MapToManyTarget.class);

        newTarget.setName("X");
        o1.addToTargets(newTarget);
        assertEquals(4, targets.size());
        assertSame(newTarget, o1.getTargets().get("X"));
        assertSame(o1, newTarget.getMapToMany());

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(4, o1.getTargets().size());
    }
View Full Code Here

    }

    public void testRemoveToMany() throws Exception {
        createTestData("prepare");

        MapToMany o1 = DataObjectUtils.objectForPK(
                createDataContext(),
                MapToMany.class,
                1);

        Map targets = o1.getTargets();
        assertEquals(3, targets.size());

        MapToManyTarget target = (MapToManyTarget) targets.get("B");
        o1.removeFromTargets(target);

        assertEquals(2, targets.size());
        assertNull(o1.getTargets().get("B"));
        assertNull(target.getMapToMany());

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(2, o1.getTargets().size());
        assertNotNull(o1.getTargets().get("A"));
        assertNotNull(o1.getTargets().get("C"));
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.testdo.relationship.MapToMany

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.