Search in sources :

Example 1 with MutableChangeMap

use of org.apache.cayenne.commitlog.model.MutableChangeMap in project cayenne by apache.

the class CommitLogFilter method onSync.

@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff beforeDiff, int syncType, DataChannelFilterChain 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;
}
Also used : DataChannel(org.apache.cayenne.DataChannel) GraphDiff(org.apache.cayenne.graph.GraphDiff) MutableChangeMap(org.apache.cayenne.commitlog.model.MutableChangeMap)

Example 2 with MutableChangeMap

use of org.apache.cayenne.commitlog.model.MutableChangeMap 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;
}
Also used : DataChannel(org.apache.cayenne.DataChannel) GraphDiff(org.apache.cayenne.graph.GraphDiff) MutableChangeMap(org.apache.cayenne.commitlog.model.MutableChangeMap)

Aggregations

DataChannel (org.apache.cayenne.DataChannel)2 MutableChangeMap (org.apache.cayenne.commitlog.model.MutableChangeMap)2 GraphDiff (org.apache.cayenne.graph.GraphDiff)2