use of org.apache.cayenne.graph.GraphChangeHandler in project cayenne by apache.
the class DataContextCommitIT method testFlushToParent_Commit_New.
@Test
public void testFlushToParent_Commit_New() {
// commit new object
Artist a = context.newObject(Artist.class);
a.setArtistName("Test");
assertTrue(context.hasChanges());
ObjectId beforeId = a.getObjectId();
GraphDiff diff = context.flushToParent(true);
ObjectId afterId = a.getObjectId();
assertNotNull(diff);
assertFalse(context.hasChanges());
assertNotEquals(beforeId, afterId);
GraphChangeHandler diffChecker = mock(GraphChangeHandler.class);
diff.apply(diffChecker);
verify(diffChecker).nodeIdChanged(beforeId, afterId);
verifyZeroInteractions(diffChecker);
}
use of org.apache.cayenne.graph.GraphChangeHandler 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]);
}
use of org.apache.cayenne.graph.GraphChangeHandler 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]);
}
use of org.apache.cayenne.graph.GraphChangeHandler 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.GraphChangeHandler in project cayenne by apache.
the class CommitLogFilter method afterCommit.
private void afterCommit(MutableChangeMap changes, DataChannel channel, GraphDiff contextDiff, GraphDiff dbDiff) {
GraphChangeHandler handler = new DiffFilter(entityFactory, new DiffProcessor(changes, channel.getEntityResolver()));
contextDiff.apply(handler);
dbDiff.apply(handler);
}
Aggregations