Package org.apache.cayenne.testdo.mt

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


        ObjectId gid = new ObjectId(
                "MtTable2",
                MtTable2.TABLE2_ID_PK_COLUMN,
                new Integer(1));
        ClientMtTable2 mtTable21 = (ClientMtTable2) DataObjectUtils.objectForQuery(
                context,
                new ObjectIdQuery(gid));

        assertNotNull(mtTable21);

        ClientMtTable1 mtTable1 = mtTable21.getTable1();
        assertNotNull("To one relationship incorrectly resolved to null", mtTable1);

        List list = mtTable1.getTable2Array();
        assertNotNull(list);
        assertTrue(list instanceof ValueHolder);

        assertTrue(((ValueHolder) list).isFault());

        // resolve it here...
        assertEquals(2, list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
            ClientMtTable2 t2 = (ClientMtTable2) it.next();

            PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
            assertFalse(holder.isFault());
            assertSame(mtTable1, holder.getValue());
        }

        assertEquals("g1", mtTable1.getGlobalAttribute1());
View Full Code Here


            ClientServerChannel csChannel = new ClientServerChannel(getDomain());
            ClientChannel channel = new ClientChannel(new LocalConnection(csChannel));
            CayenneContext context = new CayenneContext(channel);
            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
            ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
            o.addToTable2Array(o1);
            context.commitChanges();

            assertFalse(o.getObjectId().isTemporary());
            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
View Full Code Here

            ClientServerChannel csChannel = new ClientServerChannel(getDomain());
            ClientChannel channel = new ClientChannel(new LocalConnection(csChannel));
            CayenneContext context = new CayenneContext(channel);
            ClientMtTable1 o = context.newObject(ClientMtTable1.class);
            ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
            o.addToTable2Array(o1);
            context.commitChanges();

            assertFalse(o.getObjectId().isTemporary());
            assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
View Full Code Here

        deleteTestData();

        ObjectContext child = context.createChildContext();

        ClientMtTable1 _new = context.newObject(ClientMtTable1.class);
        ClientMtTable2 _new2 = context.newObject(ClientMtTable2.class);
        _new.addToTable2Array(_new2);

        blockQueries();

        try {
            ClientMtTable2 child2 = (ClientMtTable2) child.localObject(_new2
                    .getObjectId(), _new2);
            assertEquals(PersistenceState.COMMITTED, child2.getPersistenceState());
            assertNotNull(child2.getTable1());
            assertEquals(PersistenceState.COMMITTED, child2
                    .getTable1()
                    .getPersistenceState());
        }
        finally {
            unblockQueries();
View Full Code Here

    public void testPrefetchingToOne() throws Exception {
        deleteTestData();

        ClientMtTable1 mt11 = context.newObject(ClientMtTable1.class);
        ClientMtTable1 mt12 = context.newObject(ClientMtTable1.class);
        ClientMtTable2 mt21 = context.newObject(ClientMtTable2.class);
        ClientMtTable2 mt22 = context.newObject(ClientMtTable2.class);

        mt21.setTable1(mt11);
        mt22.setTable1(mt11);

        context.commitChanges();

        ObjectContext child = context.createChildContext();

        SelectQuery q = new SelectQuery(ClientMtTable2.class);
        q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);

        List results = child.performQuery(q);

        blockQueries();
        try {
            assertEquals(2, results.size());
            Iterator it = results.iterator();
            while (it.hasNext()) {
                ClientMtTable2 o = (ClientMtTable2) it.next();
                assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
                assertSame(child, o.getObjectContext());

                ClientMtTable1 o1 = o.getTable1();
                assertNotNull(o1);
                assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
                assertSame(child, o1.getObjectContext());
                assertEquals(mt11.getObjectId(), o1.getObjectId());
            }
View Full Code Here

        mt11.setGlobalAttribute1("1");

        ClientMtTable1 mt12 = context.newObject(ClientMtTable1.class);
        mt12.setGlobalAttribute1("2");

        ClientMtTable2 mt21 = context.newObject(ClientMtTable2.class);
        ClientMtTable2 mt22 = context.newObject(ClientMtTable2.class);

        mt21.setTable1(mt11);
        mt22.setTable1(mt11);

        context.commitChanges();

        ObjectContext child = context.createChildContext();

        SelectQuery q = new SelectQuery(ClientMtTable1.class);
        q.addOrdering("globalAttribute1", true);
        q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);

        List results = child.performQuery(q);

        blockQueries();
        try {

            ClientMtTable1 o1 = (ClientMtTable1) results.get(0);
            assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
            assertSame(child, o1.getObjectContext());

            List<ClientMtTable2> children1 = o1.getTable2Array();

            assertEquals(2, children1.size());
            Iterator<ClientMtTable2> it = children1.iterator();
            while (it.hasNext()) {
                ClientMtTable2 o = it.next();
                assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
                assertSame(child, o.getObjectContext());

                assertEquals(o1, o.getTable1());
            }

            ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
            assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
            assertSame(child, o2.getObjectContext());
View Full Code Here

        ObjectContext child = context.createChildContext();

        ClientMtTable1 a = context.newObject(ClientMtTable1.class);
        context.commitChanges();

        ClientMtTable2 p = child.newObject(ClientMtTable2.class);
        ClientMtTable1 aChild = (ClientMtTable1) DataObjectUtils.objectForPK(child, a
                .getObjectId());
        p.setGlobalAttribute("X");
        aChild.addToTable2Array(p);

        child.commitChangesToParent();

        child.deleteObject(p);
View Full Code Here

     */
    public void testNullifyToOne() throws Exception {
        deleteTestData();

        ClientMtTable1 a = context.newObject(ClientMtTable1.class);
        ClientMtTable2 b = context.newObject(ClientMtTable2.class);
        a.addToTable2Array(b);

        context.commitChanges();

        ObjectContext child = context.createChildContext();
        ObjectContext childPeer = context.createChildContext();

        ClientMtTable2 childP1 = (ClientMtTable2) DataObjectUtils.objectForPK(child, b
                .getObjectId());

        // trigger object creation in the peer nested DC
        DataObjectUtils.objectForPK(childPeer, b.getObjectId());
        childP1.setTable1(null);

        blockQueries();

        try {
            child.commitChangesToParent();
            assertEquals(PersistenceState.COMMITTED, childP1.getPersistenceState());

            ClientMtTable2 parentP1 = (ClientMtTable2) context.getGraphManager().getNode(
                    childP1.getObjectId());

            assertNotNull(parentP1);
            assertEquals(PersistenceState.MODIFIED, parentP1.getPersistenceState());
            assertNull(parentP1.getTable1());

            // check that arc changes got recorded in the parent context
            GraphDiff diffs = context.internalGraphManager().getDiffs();
            final int[] arcDiffs = new int[1];

View Full Code Here

        ClientMtTable1 a = child.newObject(ClientMtTable1.class);
        a.setGlobalAttribute1("X");
        child.commitChanges();

        ClientMtTable2 p1 = child.newObject(ClientMtTable2.class);
        p1.setGlobalAttribute("P1");
        a.addToTable2Array(p1);

        ClientMtTable2 p2 = child.newObject(ClientMtTable2.class);
        p2.setGlobalAttribute("P2");
        a.addToTable2Array(p2);

        a.removeFromTable2Array(p2);

        // this causes an error on commit
View Full Code Here

    public void testChangeRel() throws Exception {
        deleteTestData();
        ObjectContext child = context.createChildContext();

        ClientMtTable1 a = child.newObject(ClientMtTable1.class);
        ClientMtTable2 b = child.newObject(ClientMtTable2.class);
        child.commitChanges();

        assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());

        a.addToTable2Array(b);
View Full Code Here

TOP

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

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.