use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class CommitLogFilter method onSync.
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff beforeDiff, int syncType, DataChannelSyncFilterChain filterChain) {
// process commits only; skip rollback
if (syncType != DataChannel.FLUSH_CASCADE_SYNC && syncType != DataChannel.FLUSH_NOCASCADE_SYNC) {
return filterChain.onSync(originatingContext, beforeDiff, syncType);
}
// don't collect changes if there are no listeners
if (listeners.isEmpty()) {
return filterChain.onSync(originatingContext, beforeDiff, syncType);
}
MutableChangeMap changes = new MutableChangeMap();
// passing DataDomain, not ObjectContext to speed things up
// and avoid capturing changed state when fetching snapshots
DataChannel channel = originatingContext.getChannel();
beforeCommit(changes, channel, beforeDiff);
GraphDiff afterDiff = filterChain.onSync(originatingContext, beforeDiff, syncType);
afterCommit(changes, channel, beforeDiff, afterDiff);
notifyListeners(originatingContext, changes);
return afterDiff;
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class DataDomainFiltersIT method testOnSync_FilterOrdering.
@Test
public void testOnSync_FilterOrdering() {
DataDomain domain = runtime.getDataDomain();
List<String> results = new ArrayList<>();
DataChannelSyncFilter f1 = (originatingContext, changes, syncType, filterChain) -> {
results.add("f1start");
GraphDiff response = filterChain.onSync(originatingContext, changes, syncType);
results.add("f1end");
return response;
};
DataChannelSyncFilter f2 = (originatingContext, changes, syncType, filterChain) -> {
results.add("f2start");
GraphDiff response = filterChain.onSync(originatingContext, changes, syncType);
results.add("f2end");
return response;
};
domain.syncFilters.add(f1);
domain.syncFilters.add(f2);
Artist a = context.newObject(Artist.class);
a.setArtistName("AAA");
// testing domain.onSync indirectly
context.commitChanges();
assertEquals(4, results.size());
assertEquals("f2start", results.get(0));
assertEquals("f1start", results.get(1));
assertEquals("f1end", results.get(2));
assertEquals("f2end", results.get(3));
}
Aggregations