Search in sources :

Example 1 with ClientTooneDep

use of org.apache.cayenne.testdo.toone.ClientTooneDep 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);
    SelectQuery<ClientTooneMaster> query = new SelectQuery<ClientTooneMaster>(ClientTooneMaster.class);
    List<ClientTooneMaster> objects = child.select(query);
    assertEquals(1, objects.size());
    ClientTooneMaster childDeleted = (ClientTooneMaster) 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();
    SelectQuery<ClientTooneMaster> query2 = new SelectQuery<ClientTooneMaster>(ClientTooneMaster.class);
    List<ClientTooneMaster> objects2 = child.select(query2);
    assertEquals(0, objects2.size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientTooneMaster(org.apache.cayenne.testdo.toone.ClientTooneMaster) ClientTooneDep(org.apache.cayenne.testdo.toone.ClientTooneDep) Test(org.junit.Test)

Example 2 with ClientTooneDep

use of org.apache.cayenne.testdo.toone.ClientTooneDep 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);
    SelectQuery<ClientTooneDep> queryB = new SelectQuery<ClientTooneDep>(ClientTooneDep.class);
    List<?> objectsB = child.performQuery(queryB);
    assertEquals(1, objectsB.size());
    ClientTooneDep childBDeleted = (ClientTooneDep) objectsB.get(0);
    child.deleteObjects(childBDeleted);
    SelectQuery<ClientTooneMaster> query = new SelectQuery<ClientTooneMaster>(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();
    SelectQuery<ClientTooneMaster> query2 = new SelectQuery<ClientTooneMaster>(ClientTooneMaster.class);
    List<ClientTooneMaster> objects2 = child.select(query2);
    assertEquals(0, objects2.size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientTooneMaster(org.apache.cayenne.testdo.toone.ClientTooneMaster) ClientTooneDep(org.apache.cayenne.testdo.toone.ClientTooneDep) Test(org.junit.Test)

Example 3 with ClientTooneDep

use of org.apache.cayenne.testdo.toone.ClientTooneDep 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() {

        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 : ClientTooneMaster(org.apache.cayenne.testdo.toone.ClientTooneMaster) 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 SelectQuery (org.apache.cayenne.query.SelectQuery)2 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)1 GraphDiff (org.apache.cayenne.graph.GraphDiff)1