use of org.apache.cayenne.DataChannelSyncCallbackAction in project cayenne by apache.
the class ClientChannel method onSync.
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
DataChannelSyncCallbackAction callbackAction = DataChannelSyncCallbackAction.getCallbackAction(getEntityResolver().getCallbackRegistry(), originatingContext.getGraphManager(), changes, syncType);
callbackAction.applyPreCommit();
changes = diffCompressor.compress(changes);
GraphDiff replyDiff = send(new SyncMessage(originatingContext, syncType, changes), GraphDiff.class);
if (channelEventsEnabled) {
EventSubject subject;
switch(syncType) {
case DataChannel.ROLLBACK_CASCADE_SYNC:
subject = DataChannel.GRAPH_ROLLEDBACK_SUBJECT;
break;
case DataChannel.FLUSH_NOCASCADE_SYNC:
subject = DataChannel.GRAPH_CHANGED_SUBJECT;
break;
case DataChannel.FLUSH_CASCADE_SYNC:
subject = DataChannel.GRAPH_FLUSHED_SUBJECT;
break;
default:
subject = null;
}
if (subject != null) {
// combine message sender changes and message receiver changes into a
// single event
boolean sentNoop = changes == null || changes.isNoop();
boolean receivedNoop = replyDiff == null || replyDiff.isNoop();
if (!sentNoop || !receivedNoop) {
CompoundDiff notification = new CompoundDiff();
if (!sentNoop) {
notification.add(changes);
}
if (!receivedNoop) {
notification.add(replyDiff);
}
GraphEvent e = new GraphEvent(this, originatingContext, notification);
eventManager.postEvent(e, subject);
}
}
}
callbackAction.applyPostCommit();
return replyDiff;
}
use of org.apache.cayenne.DataChannelSyncCallbackAction in project cayenne by apache.
the class TransactionFilter method onSync.
@Override
public GraphDiff onSync(final ObjectContext originatingContext, final GraphDiff changes, final int syncType, final DataChannelFilterChain filterChain) {
DataChannelSyncCallbackAction callbackAction = DataChannelSyncCallbackAction.getCallbackAction(originatingContext.getChannel().getEntityResolver().getCallbackRegistry(), originatingContext.getGraphManager(), changes, syncType);
callbackAction.applyPreCommit();
GraphDiff result;
switch(syncType) {
case DataChannel.ROLLBACK_CASCADE_SYNC:
result = filterChain.onSync(originatingContext, changes, syncType);
;
break;
// including transaction handling logic
case DataChannel.FLUSH_NOCASCADE_SYNC:
case DataChannel.FLUSH_CASCADE_SYNC:
result = transactionManager.performInTransaction(new TransactionalOperation<GraphDiff>() {
@Override
public GraphDiff perform() {
return filterChain.onSync(originatingContext, changes, syncType);
}
});
break;
default:
throw new CayenneRuntimeException("Invalid synchronization type: %d", syncType);
}
callbackAction.applyPostCommit();
return result;
}
Aggregations