Package org.apache.cayenne.testdo.mt

Examples of org.apache.cayenne.testdo.mt.ClientMtMapToMany


public class ROPPrefetchToManyMapTest extends RemoteCayenneCase {
    public void test() throws Exception {
        deleteTestData();
        ObjectContext context = createROPContext();
       
        ClientMtMapToMany map = context.newObject(ClientMtMapToMany.class);
        ClientMtMapToManyTarget target = context.newObject(ClientMtMapToManyTarget.class);
        target.setMapToMany(map);
        context.commitChanges();
       
        context.performQuery(new RefreshQuery());
       
        SelectQuery query = new SelectQuery(ClientMtMapToMany.class);
        query.addPrefetch("targets");
       
        map = (ClientMtMapToMany) Cayenne.objectForQuery(context, query);
       
        try {
            blockQueries();
            assertEquals(map.getTargets().size(), 1);
        }
        finally {
            unblockQueries();
        }
    }
View Full Code Here


        createTestData("prepare");

        ObjectContext context = createClientContext();

        ObjectId id = new ObjectId("MtMapToMany", MtMapToMany.ID_PK_COLUMN, 1);
        ClientMtMapToMany o1 = (ClientMtMapToMany) DataObjectUtils.objectForQuery(
                context,
                new ObjectIdQuery(id));

        Map targets = o1.getTargets();

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

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

        createTestData("prepare");

        ObjectContext context = createClientContext();

        ObjectId id = new ObjectId("MtMapToMany", MtMapToMany.ID_PK_COLUMN, 1);
        ClientMtMapToMany o1 = (ClientMtMapToMany) DataObjectUtils.objectForQuery(
                context,
                new ObjectIdQuery(id));

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

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

        o1.addToTargets(newTarget);
        assertEquals(4, targets.size());
        assertSame(o1, newTarget.getMapToMany());

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(4, o1.getTargets().size());
       
        int newId = DataObjectUtils.intPKForObject(newTarget);
        assertSame(newTarget, o1.getTargets().get(new Integer(newId)));
       
        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
        assertEquals(PersistenceState.COMMITTED, newTarget.getPersistenceState());
    }
View Full Code Here

public class ROPPrefetchToManyMapTest extends RemoteCayenneCase {
    public void test() throws Exception {
        deleteTestData();
        ObjectContext context = createROPContext();
       
        ClientMtMapToMany map = context.newObject(ClientMtMapToMany.class);
        ClientMtMapToManyTarget target = context.newObject(ClientMtMapToManyTarget.class);
        target.setMapToMany(map);
        context.commitChanges();
       
        context.performQuery(new RefreshQuery());
       
        SelectQuery query = new SelectQuery(ClientMtMapToMany.class);
        query.addPrefetch("targets");
       
        map = (ClientMtMapToMany) DataObjectUtils.objectForQuery(context, query);
       
        try {
            blockQueries();
            assertEquals(map.getTargets().size(), 1);
        }
        finally {
            unblockQueries();
        }
    }
View Full Code Here

    public void testReadToMany() throws Exception {
        createTwoMapToManysWithTargetsDataSet();

        ObjectId id = new ObjectId("MtMapToMany", MtMapToMany.ID_PK_COLUMN, 1);
        ClientMtMapToMany o1 = (ClientMtMapToMany) Cayenne.objectForQuery(
                context,
                new ObjectIdQuery(id));

        Map<Object, ClientMtMapToManyTarget> targets = o1.getTargets();

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

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

    public void testAddToMany() throws Exception {
        createTwoMapToManysWithTargetsDataSet();

        ObjectId id = new ObjectId("MtMapToMany", MtMapToMany.ID_PK_COLUMN, 1);
        ClientMtMapToMany o1 = (ClientMtMapToMany) Cayenne.objectForQuery(
                context,
                new ObjectIdQuery(id));

        Map<Object, ClientMtMapToManyTarget> targets = o1.getTargets();
        assertNotNull(targets);
        assertEquals(3, targets.size());

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

        o1.addToTargets(newTarget);
        assertEquals(4, targets.size());
        assertSame(o1, newTarget.getMapToMany());

        o1.getObjectContext().commitChanges();

        o1.getObjectContext().performGenericQuery(new RefreshQuery());
        assertEquals(4, o1.getTargets().size());

        int newId = Cayenne.intPKForObject(newTarget);
        assertSame(newTarget, o1.getTargets().get(new Integer(newId)));

        assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
        assertEquals(PersistenceState.COMMITTED, newTarget.getPersistenceState());
    }
View Full Code Here

    }
   
    public void test() throws Exception {
        ObjectContext context = createROPContext();
       
        ClientMtMapToMany map = context.newObject(ClientMtMapToMany.class);
        ClientMtMapToManyTarget target = context.newObject(ClientMtMapToManyTarget.class);
        target.setMapToMany(map);
        context.commitChanges();
       
        context.performQuery(new RefreshQuery());
       
        SelectQuery query = new SelectQuery(ClientMtMapToMany.class);
        query.addPrefetch("targets");
       
        final ClientMtMapToMany mapToMany = (ClientMtMapToMany) Cayenne.objectForQuery(context, query);
       
        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
           
            public void execute() {
                assertEquals(mapToMany.getTargets().size(), 1);
            }
        });
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.testdo.mt.ClientMtMapToMany

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.