Package org.apache.cayenne.testdo.mt

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


    }

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

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

        ClientMtTable2 p = context.newObject(ClientMtTable2.class);
        p.setTable1(a);
        p.setGlobalAttribute("PPP");
        a.setGlobalAttribute1("X");
        altA.setGlobalAttribute1("Y");
        context.commitChanges();

        ObjectContext peer1 = context.createChildContext();
        ClientMtTable2 p1 = (ClientMtTable2) peer1.localObject(p.getObjectId(), p);
        ClientMtTable1 altA1 = (ClientMtTable1) peer1.localObject(altA.getObjectId(), altA);

        ObjectContext peer2 = context.createChildContext();
        ClientMtTable2 p2 = (ClientMtTable2) peer2.localObject(p.getObjectId(), p);
        ClientMtTable1 altA2 = (ClientMtTable1) peer2.localObject(altA.getObjectId(), altA);
        ClientMtTable1 a2 = (ClientMtTable1) peer2.localObject(a.getObjectId(), a);

        p1.setTable1(altA1);
        assertSame(a2, p2.getTable1());
        peer1.commitChangesToParent();
        assertEquals(altA2, p2.getTable1());
View Full Code Here


    }

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

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

        ClientMtTable2 px = context.newObject(ClientMtTable2.class);
        px.setTable1(a);
        px.setGlobalAttribute("PX");

        ClientMtTable2 py = context.newObject(ClientMtTable2.class);
        py.setGlobalAttribute("PY");

        context.commitChanges();

        ObjectContext peer1 = context.createChildContext();
        ClientMtTable2 py1 = (ClientMtTable2) peer1.localObject(py.getObjectId(), py);
        ClientMtTable1 a1 = (ClientMtTable1) peer1.localObject(a.getObjectId(), a);

        ObjectContext peer2 = context.createChildContext();
        ClientMtTable2 py2 = (ClientMtTable2) peer2.localObject(py.getObjectId(), py);
        ClientMtTable1 a2 = (ClientMtTable1) peer2.localObject(a.getObjectId(), a);

        a1.addToTable2Array(py1);
        assertEquals(1, a2.getTable2Array().size());
        assertFalse(a2.getTable2Array().contains(py2));
        peer1.commitChangesToParent();
        assertEquals(2, a2.getTable2Array().size());
        assertTrue(a2.getTable2Array().contains(py2));

        assertFalse("Peer data context became dirty on event processing", peer2
                .hasChanges());
    }
View Full Code Here

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

        ClientMtTable1 ac = child.newObject(ClientMtTable1.class);
        ac.setGlobalAttribute1("X");
        child.commitChangesToParent();

        ClientMtTable1 ap = (ClientMtTable1) context.getGraphManager().getNode(ac.getObjectId());
        assertNotNull(ap);

        assertTrue(ap.getObjectId().isTemporary());
        context.commitChanges();

        assertFalse(ap.getObjectId().isTemporary());
        assertEquals(ap.getObjectId(), ac.getObjectId());
    }
View Full Code Here

    }

    public void testAddRemove() throws Exception {
        ObjectContext child = clientContext.createChildContext();

        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
        child.deleteObjects(p2);

        child.commitChangesToParent();
View Full Code Here

    }

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

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

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

        a.addToTable2Array(b);
        assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());

        child.commitChangesToParent();
        ClientMtTable1 parentA = (ClientMtTable1) clientContext.getGraphManager().getNode(
                a.getObjectId());
        assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
        assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
        assertEquals(1, parentA.getTable2Array().size());

        clientContext.commitChanges();
        assertEquals(PersistenceState.COMMITTED, parentA.getPersistenceState());

        a.removeFromTable2Array(b);
        assertEquals(PersistenceState.MODIFIED, a.getPersistenceState());

        child.commitChangesToParent();
        assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
        assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
        assertEquals(0, parentA.getTable2Array().size());
    }
View Full Code Here

        assertEquals(PersistenceState.MODIFIED, parentA.getPersistenceState());
        assertEquals(0, parentA.getTable2Array().size());
    }

    public void testCAY1183() throws Exception {
        ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
        clientContext.commitChanges();

        ObjectContext child = clientContext.createChildContext();
        ClientMtTable1 childMt = (ClientMtTable1) Cayenne.objectForPK(child, parentMt
                .getObjectId());
        childMt.setGlobalAttribute1("1183");
        ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
        childMt2.setGlobalAttribute("1183");
        childMt2.setTable1(childMt);

        child.commitChangesToParent();
View Full Code Here

        // fetching other relationship... this fails per CAY-1183
        childMt2.getTable3();
    }

    public void testCAY1194() throws Exception {
        ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
        ObjectContext child = clientContext.createChildContext();

        ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
        childMt2.setGlobalAttribute("222");

        ClientMtTable1 localParentMt = (ClientMtTable1) child.localObject(parentMt
                .getObjectId(), null);
        assertEquals(0, parentMt.getTable2Array().size());
        assertEquals(0, localParentMt.getTable2Array().size());

        childMt2.setTable1(localParentMt);

        assertEquals(0, parentMt.getTable2Array().size());
        assertEquals(1, localParentMt.getTable2Array().size());

        assertEquals(localParentMt.getTable2Array().get(0).getObjectContext(), child);

        child.commitChangesToParent();
        assertEquals(1, parentMt.getTable2Array().size());
        assertEquals(parentMt.getTable2Array().get(0).getObjectContext(), clientContext);
    }
View Full Code Here

    }

    public void testCommitChangesToParentOneToMany() throws Exception {
        ObjectContext child = clientContext.createChildContext();

        ClientMtTable1 master = child.newObject(ClientMtTable1.class);
        ClientMtTable2 dep = child.newObject(ClientMtTable2.class);
        master.addToTable2Array(dep);

        child.commitChangesToParent();

        ClientMtTable1 masterParent = (ClientMtTable1) clientContext.getGraphManager().getNode(
                master.getObjectId());
        ClientMtTable2 depParent = (ClientMtTable2) clientContext.getGraphManager().getNode(
                dep.getObjectId());

        assertNotNull(masterParent);
        assertNotNull(depParent);

        assertSame(masterParent, depParent.getTable1());
        assertTrue(masterParent.getTable2Array().contains(depParent));

        // check that arc changes got recorded in the parent context
        GraphDiff diffs = clientContext.internalGraphManager().getDiffs();

        final int[] arcDiffs = new int[1];
View Full Code Here

        CayenneContext c1 = (CayenneContext) runtime.getContext();
        CayenneContext c2 = (CayenneContext) runtime.getContext();
        assertNotSame(c1, c2);

        ClientMtTable1 o1 = c1.newObject(ClientMtTable1.class);
        o1.setGlobalAttribute1("X");
        c1.commitChanges();

        ClientMtTable1 o2 = (ClientMtTable1) c2.getGraphManager().getNode(
                o1.getObjectId());

        assertNull(o2);
        // now fetch it fresh

        o2 = (ClientMtTable1) c2.performQuery(new ObjectIdQuery(o1.getObjectId())).get(0);
        assertNotNull(o2);

        assertEquals("X", o2.getGlobalAttribute1());
        assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
        assertFalse(c1.internalGraphManager().hasChanges());
        assertFalse(c2.internalGraphManager().hasChanges());
    }
View Full Code Here

        CayenneContext c1 = (CayenneContext) runtime.getContext();
        CayenneContext c2 = (CayenneContext) runtime.getContext();
        assertNotSame(c1, c2);

        // insert, then delete - this shouldn't propagate via an event.
        ClientMtTable1 o1 = c1.newObject(ClientMtTable1.class);
        o1.setGlobalAttribute1("X");
        c1.deleteObjects(o1);

        // introduce some other change so that commit can go ahead...
        ClientMtTable1 o1x = c1.newObject(ClientMtTable1.class);
        o1x.setGlobalAttribute1("Y");
        c1.commitChanges();

        ClientMtTable1 o2 = (ClientMtTable1) c2.getGraphManager().getNode(
                o1.getObjectId());

        assertNull(o2);

        assertFalse(c1.internalGraphManager().hasChanges());
View Full Code Here

TOP

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

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.