Package org.apache.cayenne.testdo.relationship

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


    }

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

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

        Collection targets = o1.getTargets();

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

        assertEquals(3, targets.size());

        assertTrue(targets.contains(Cayenne.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                1)));
        assertTrue(targets.contains(Cayenne.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                2)));
        assertTrue(targets.contains(Cayenne.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                3)));
    }
View Full Code Here


        createTestData("prepare");

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

        Collection targets = o1.getTargets();

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

        assertNotNull(targets);
        assertEquals(3, targets.size());

        assertTrue(targets.contains(Cayenne.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                1)));
        assertTrue(targets.contains(Cayenne.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                2)));
        assertTrue(targets.contains(Cayenne.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                3)));
    }
View Full Code Here

    }

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

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

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

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

        o1.addToTargets(newTarget);
        assertEquals(4, targets.size());
        assertTrue(o1.getTargets().contains(newTarget));
        assertSame(o1, newTarget.getCollectionToMany());

        o1.getObjectContext().commitChanges();

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

    }

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

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

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

        CollectionToManyTarget target = Cayenne
                .objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 2);
        o1.removeFromTargets(target);

        assertEquals(2, targets.size());
        assertFalse(o1.getTargets().contains(target));
        assertNull(target.getCollectionToMany());

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(2, o1.getTargets().size());
        assertFalse(o1.getTargets().contains(target));
    }
View Full Code Here

    }

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

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

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

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

        newTarget.setCollectionToMany(o1);
        assertEquals(4, targets.size());
        assertTrue(o1.getTargets().contains(newTarget));
        assertSame(o1, newTarget.getCollectionToMany());

        o1.getObjectContext().commitChanges();

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

    }

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

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

        Collection targets = o1.getTargets();

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

        assertEquals(3, targets.size());

        assertTrue(targets.contains(DataObjectUtils.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                1)));
        assertTrue(targets.contains(DataObjectUtils.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                2)));
        assertTrue(targets.contains(DataObjectUtils.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                3)));
    }
View Full Code Here

        createTestData("prepare");

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

        Collection targets = o1.getTargets();

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

        assertNotNull(targets);
        assertEquals(3, targets.size());

        assertTrue(targets.contains(DataObjectUtils.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                1)));
        assertTrue(targets.contains(DataObjectUtils.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                2)));
        assertTrue(targets.contains(DataObjectUtils.objectForPK(
                o1.getObjectContext(),
                CollectionToManyTarget.class,
                3)));
    }
View Full Code Here

    }

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

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

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

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

        o1.addToTargets(newTarget);
        assertEquals(4, targets.size());
        assertTrue(o1.getTargets().contains(newTarget));
        assertSame(o1, newTarget.getCollectionToMany());

        o1.getObjectContext().commitChanges();

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

    }

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

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

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

        CollectionToManyTarget target = DataObjectUtils
                .objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 2);
        o1.removeFromTargets(target);

        assertEquals(2, targets.size());
        assertFalse(o1.getTargets().contains(target));
        assertNull(target.getCollectionToMany());

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(2, o1.getTargets().size());
        assertFalse(o1.getTargets().contains(target));
    }
View Full Code Here

    }

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

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

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

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

        newTarget.setCollectionToMany(o1);
        assertEquals(4, targets.size());
        assertTrue(o1.getTargets().contains(newTarget));
        assertSame(o1, newTarget.getCollectionToMany());

        o1.getObjectContext().commitChanges();

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

TOP

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

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.