use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class ObjectStore method processSnapshotEvent.
/**
* @since 1.2
*/
synchronized void processSnapshotEvent(SnapshotEvent event) {
Map<ObjectId, DataRow> modifiedDiffs = event.getModifiedDiffs();
if (modifiedDiffs != null && !modifiedDiffs.isEmpty()) {
for (Map.Entry<ObjectId, DataRow> entry : modifiedDiffs.entrySet()) {
processUpdatedSnapshot(entry.getKey(), entry.getValue());
}
}
Collection<ObjectId> deletedIDs = event.getDeletedIds();
if (deletedIDs != null && !deletedIDs.isEmpty()) {
for (ObjectId deletedID : deletedIDs) {
processDeletedID(deletedID);
}
}
processInvalidatedIDs(event.getInvalidatedIds());
processIndirectlyModifiedIDs(event.getIndirectlyModifiedIds());
// TODO: andrus, 3/28/2006 - 'SnapshotEventDecorator' serves as a bridge (or
// rather a noop wrapper) between old snapshot events and new GraphEvents. Once
// SnapshotEvents are replaced with GraphEvents (in 2.0) we won't need it
GraphDiff diff = new SnapshotEventDecorator(event);
ObjectContext originatingContext = (event.getPostedBy() instanceof ObjectContext) ? (ObjectContext) event.getPostedBy() : null;
context.fireDataChannelChanged(originatingContext, diff);
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class ClientChannelServerDiffsIT method testReturnDiffClientArcChanges.
@Test
public void testReturnDiffClientArcChanges() {
final NoopGraphChangeHandler diffReader = new NoopGraphChangeHandler();
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false) {
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
GraphDiff serverDiff = super.onSync(originatingContext, changes, syncType);
assertNotNull(serverDiff);
serverDiff.apply(diffReader);
return serverDiff;
}
};
CayenneContext context = new CayenneContext(channel);
ClientMtTable1 o = context.newObject(ClientMtTable1.class);
ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
o.addToTable2Array(o2);
context.commitChanges();
assertEquals(2, diffReader.size);
diffReader.reset();
ClientMtTable2 o3 = context.newObject(ClientMtTable2.class);
o3.setTable1(o);
context.commitChanges();
assertEquals(1, diffReader.size);
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class ClientChannelServerDiffsIT method testReturnIdDiff.
@Test
public void testReturnIdDiff() {
final Object[] ids = new Object[2];
final GraphChangeHandler diffReader = new NoopGraphChangeHandler() {
@Override
public void nodeIdChanged(Object oldId, Object newId) {
ids[0] = oldId;
ids[1] = newId;
}
};
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false) {
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
GraphDiff serverDiff = super.onSync(originatingContext, changes, syncType);
assertNotNull(serverDiff);
serverDiff.apply(diffReader);
return serverDiff;
}
};
CayenneContext context = new CayenneContext(channel);
context.newObject(ClientMtTable1.class);
context.commitChanges();
assertTrue(ids[0] instanceof ObjectId);
assertTrue(((ObjectId) ids[0]).isTemporary());
assertTrue(ids[1] instanceof ObjectId);
assertFalse(((ObjectId) ids[1]).isTemporary());
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class NestedCayenneContextIT method testCommitChangesToParentOneToMany.
@Test
public void testCommitChangesToParentOneToMany() {
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() {
@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]);
}
use of org.apache.cayenne.graph.GraphDiff 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]);
}
Aggregations