Search in sources :

Example 31 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class NestedCayenneContextIT method testChangeRel.

@Test
public void testChangeRel() throws Exception {
    ObjectContext child = runtime.newContext(clientContext);
    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());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 32 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class NestedCayenneContextIT method testCommitChangesToParentOneToMany.

@Test
public void testCommitChangesToParentOneToMany() throws Exception {
    ObjectContext child = runtime.newContext(clientContext);
    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];
    final int[] newNodes = new int[1];
    diffs.apply(new GraphChangeHandler() {

        public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
            arcDiffs[0]++;
        }

        public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
            arcDiffs[0]--;
        }

        public void nodeCreated(Object nodeId) {
            newNodes[0]++;
        }

        public void nodeIdChanged(Object nodeId, Object newId) {
        }

        public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
        }

        public void nodeRemoved(Object nodeId) {
            newNodes[0]--;
        }
    });
    assertEquals(2, newNodes[0]);
    assertEquals(2, arcDiffs[0]);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) GraphDiff(org.apache.cayenne.graph.GraphDiff) GraphChangeHandler(org.apache.cayenne.graph.GraphChangeHandler) Test(org.junit.Test)

Example 33 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class NestedCayenneContextIT method testCAY1183.

@Test
public void testCAY1183() throws Exception {
    ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
    clientContext.commitChanges();
    ObjectContext child = runtime.newContext(clientContext);
    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();
    // fetching other relationship... this fails per CAY-1183
    childMt2.getTable3();
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 34 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class NestedCayenneContextIT method testCAY1194.

@Test
public void testCAY1194() throws Exception {
    ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
    ObjectContext child = runtime.newContext(clientContext);
    ClientMtTable2 childMt2 = child.newObject(ClientMtTable2.class);
    childMt2.setGlobalAttribute("222");
    ClientMtTable1 localParentMt = child.localObject(parentMt);
    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);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 35 with ClientMtTable2

use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.

the class NestedCayenneContextIT method testQueriesOnTemporaryObject.

/**
 * CAY1714
 */
@Test
public void testQueriesOnTemporaryObject() throws Exception {
    ObjectContext clientContext = runtime.newContext((DataChannel) this.clientContext);
    ClientMtTable1 parentMt = clientContext.newObject(ClientMtTable1.class);
    ObjectContext childContext = runtime.newContext((DataChannel) clientContext);
    ClientMtTable1 childMt = (ClientMtTable1) Cayenne.objectForPK(childContext, parentMt.getObjectId());
    childMt.setGlobalAttribute1("1183");
    ClientMtTable2 childMt2 = childContext.newObject(ClientMtTable2.class);
    childMt2.setGlobalAttribute("1183");
    childMt2.setTable1(childMt);
    childContext.commitChangesToParent();
    assertNull(childMt2.getTable3());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Aggregations

ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)48 Test (org.junit.Test)48 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)46 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)9 Expression (org.apache.cayenne.exp.Expression)7 SelectQuery (org.apache.cayenne.query.SelectQuery)7 ObjectContext (org.apache.cayenne.ObjectContext)6 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 Iterator (java.util.Iterator)3 List (java.util.List)3 GraphDiff (org.apache.cayenne.graph.GraphDiff)3 PersistentObjectHolder (org.apache.cayenne.util.PersistentObjectHolder)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)2 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)2 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)2 ROPSerializationService (org.apache.cayenne.rop.ROPSerializationService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CayenneContext (org.apache.cayenne.CayenneContext)1 ValueHolder (org.apache.cayenne.ValueHolder)1