use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class ObjectContextChangeLogTest method testReset.
@Test
public void testReset() {
ObjectContextChangeLog recorder = new ObjectContextChangeLog();
assertNotNull(recorder.getDiffs());
assertTrue(recorder.getDiffs().isNoop());
recorder.addOperation(new NodeCreateOperation(new Object()));
assertNotNull(recorder.getDiffs());
assertFalse(recorder.getDiffs().isNoop());
recorder.reset();
assertNotNull(recorder.getDiffs());
assertTrue(recorder.getDiffs().isNoop());
// now test that a diff stored before "clear" is not affected by 'clear'
recorder.addOperation(new NodeCreateOperation(new Object()));
GraphDiff diff = recorder.getDiffs();
assertFalse(diff.isNoop());
recorder.reset();
assertFalse(diff.isNoop());
}
use of org.apache.cayenne.graph.GraphDiff 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.graph.GraphDiff in project cayenne by apache.
the class ClientChannelServerDiffsIT method testReturnDiffInPrePersist.
@Test
public void testReturnDiffInPrePersist() {
final List<GenericDiff> diffs = new ArrayList<>();
final NoopGraphChangeHandler diffReader = new NoopGraphChangeHandler() {
@Override
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
super.nodePropertyChanged(nodeId, property, oldValue, newValue);
diffs.add(new GenericDiff((ObjectId) nodeId, property, oldValue, newValue));
}
};
LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
try {
callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersist");
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);
ObjectId tempId = o.getObjectId();
o.setServerAttribute1("YY");
context.commitChanges();
assertEquals(2, diffReader.size);
assertEquals(1, diffs.size());
assertEquals(tempId, diffs.get(0).sourceId);
assertEquals(ClientMtTable1.GLOBAL_ATTRIBUTE1.getName(), diffs.get(0).property);
assertNull(diffs.get(0).oldValue);
assertEquals("XXX", diffs.get(0).newValue);
} finally {
callbackRegistry.clear();
}
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class SyncMessageTest method testConstructor.
@Test
public void testConstructor() {
ObjectContext source = mock(ObjectContext.class);
GraphDiff diff = new CompoundDiff();
SyncMessage message = new SyncMessage(source, DataChannel.FLUSH_NOCASCADE_SYNC, diff);
assertSame(source, message.getSource());
assertEquals(DataChannel.FLUSH_NOCASCADE_SYNC, message.getType());
assertSame(diff, message.getSenderChanges());
}
use of org.apache.cayenne.graph.GraphDiff in project cayenne by apache.
the class CacheInvalidationFilter method onSync.
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType, DataChannelSyncFilterChain filterChain) {
try {
GraphDiff result = filterChain.onSync(originatingContext, changes, syncType);
// no exceptions, flush...
Collection<CacheGroupDescriptor> groupSet = groups.get();
if (groupSet != null && !groupSet.isEmpty()) {
QueryCache cache = cacheProvider.get();
for (CacheGroupDescriptor group : groupSet) {
if (group.getKeyType() != Void.class) {
cache.removeGroup(group.getCacheGroupName(), group.getKeyType(), group.getValueType());
} else {
cache.removeGroup(group.getCacheGroupName());
}
}
}
return result;
} finally {
groups.set(null);
}
}
Aggregations