Search in sources :

Example 1 with ClientTooneMaster

use of org.apache.cayenne.testdo.toone.ClientTooneMaster in project cayenne by apache.

the class NestedCayenneContextTooneIT method testCAY1636.

/*
 * was added for CAY-1636
 */
@Test
public void testCAY1636() throws Exception {
    ClientTooneMaster A = clientContext.newObject(ClientTooneMaster.class);
    clientContext.commitChanges();
    ClientTooneDep B = clientContext.newObject(ClientTooneDep.class);
    A.setToDependent(B);
    clientContext.commitChanges();
    ObjectContext child = runtime.newContext(clientContext);
    ObjectSelect<ClientTooneMaster> query = ObjectSelect.query(ClientTooneMaster.class);
    List<ClientTooneMaster> objects = child.select(query);
    assertEquals(1, objects.size());
    ClientTooneMaster childDeleted = objects.get(0);
    child.deleteObjects(childDeleted);
    child.commitChangesToParent();
    ClientTooneMaster parentDeleted = (ClientTooneMaster) clientContext.getGraphManager().getNode(childDeleted.getObjectId());
    assertNotNull(parentDeleted);
    assertEquals(PersistenceState.DELETED, parentDeleted.getPersistenceState());
    clientContext.commitChanges();
    ObjectSelect<ClientTooneMaster> query2 = ObjectSelect.query(ClientTooneMaster.class);
    List<ClientTooneMaster> objects2 = child.select(query2);
    assertEquals(0, objects2.size());
}
Also used : ClientTooneMaster(org.apache.cayenne.testdo.toone.ClientTooneMaster) ClientTooneDep(org.apache.cayenne.testdo.toone.ClientTooneDep) Test(org.junit.Test)

Example 2 with ClientTooneMaster

use of org.apache.cayenne.testdo.toone.ClientTooneMaster in project cayenne by apache.

the class NestedCayenneContextTooneIT method testCAY1636_2.

@Test
public void testCAY1636_2() throws Exception {
    ClientTooneMaster A = clientContext.newObject(ClientTooneMaster.class);
    clientContext.commitChanges();
    ClientTooneDep B = clientContext.newObject(ClientTooneDep.class);
    A.setToDependent(B);
    clientContext.commitChanges();
    ObjectContext child = runtime.newContext(clientContext);
    ObjectSelect<ClientTooneDep> queryB = ObjectSelect.query(ClientTooneDep.class);
    List<?> objectsB = child.performQuery(queryB);
    assertEquals(1, objectsB.size());
    ClientTooneDep childBDeleted = (ClientTooneDep) objectsB.get(0);
    child.deleteObjects(childBDeleted);
    ObjectSelect<ClientTooneMaster> query = ObjectSelect.query(ClientTooneMaster.class);
    List<ClientTooneMaster> objects = child.select(query);
    assertEquals(1, objects.size());
    ClientTooneMaster childDeleted = objects.get(0);
    child.deleteObjects(childDeleted);
    child.commitChangesToParent();
    ClientTooneMaster parentDeleted = (ClientTooneMaster) clientContext.getGraphManager().getNode(childDeleted.getObjectId());
    assertNotNull(parentDeleted);
    assertEquals(PersistenceState.DELETED, parentDeleted.getPersistenceState());
    clientContext.commitChanges();
    ObjectSelect<ClientTooneMaster> query2 = ObjectSelect.query(ClientTooneMaster.class);
    List<ClientTooneMaster> objects2 = child.select(query2);
    assertEquals(0, objects2.size());
}
Also used : ClientTooneMaster(org.apache.cayenne.testdo.toone.ClientTooneMaster) ClientTooneDep(org.apache.cayenne.testdo.toone.ClientTooneDep) Test(org.junit.Test)

Example 3 with ClientTooneMaster

use of org.apache.cayenne.testdo.toone.ClientTooneMaster in project cayenne by apache.

the class NestedCayenneContextTooneIT method testCommitChangesToParentOneToOne.

@Test
public void testCommitChangesToParentOneToOne() throws Exception {
    ObjectContext child = runtime.newContext(clientContext);
    ClientTooneMaster master = child.newObject(ClientTooneMaster.class);
    ClientTooneDep dep = child.newObject(ClientTooneDep.class);
    master.setToDependent(dep);
    child.commitChangesToParent();
    ClientTooneMaster masterParent = (ClientTooneMaster) clientContext.getGraphManager().getNode(master.getObjectId());
    ClientTooneDep depParent = (ClientTooneDep) clientContext.getGraphManager().getNode(dep.getObjectId());
    assertNotNull(masterParent);
    assertNotNull(depParent);
    assertSame(masterParent, depParent.getToMaster());
    assertSame(depParent, masterParent.getToDependent());
    // 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() {

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

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

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

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

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

        @Override
        public void nodeRemoved(Object nodeId) {
            newNodes[0]--;
        }
    });
    assertEquals(2, newNodes[0]);
    assertEquals(2, arcDiffs[0]);
}
Also used : ClientTooneMaster(org.apache.cayenne.testdo.toone.ClientTooneMaster) ArcId(org.apache.cayenne.graph.ArcId) GraphDiff(org.apache.cayenne.graph.GraphDiff) ClientTooneDep(org.apache.cayenne.testdo.toone.ClientTooneDep) GraphChangeHandler(org.apache.cayenne.graph.GraphChangeHandler) Test(org.junit.Test)

Aggregations

ClientTooneDep (org.apache.cayenne.testdo.toone.ClientTooneDep)3 ClientTooneMaster (org.apache.cayenne.testdo.toone.ClientTooneMaster)3 Test (org.junit.Test)3 ArcId (org.apache.cayenne.graph.ArcId)1 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)1 GraphDiff (org.apache.cayenne.graph.GraphDiff)1