use of org.apache.cayenne.graph.CompoundDiff 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.CompoundDiff in project cayenne by apache.
the class SyncMessageTest method testConstructorInvalid.
@Test
public void testConstructorInvalid() {
ObjectContext source = mock(ObjectContext.class);
new SyncMessage(source, DataChannel.FLUSH_NOCASCADE_SYNC, new CompoundDiff());
new SyncMessage(source, DataChannel.FLUSH_CASCADE_SYNC, new CompoundDiff());
new SyncMessage(null, DataChannel.ROLLBACK_CASCADE_SYNC, new CompoundDiff());
int bogusType = 45678;
try {
new SyncMessage(source, bogusType, new CompoundDiff());
fail("invalid type was allowed to go unnoticed...");
} catch (IllegalArgumentException e) {
}
}
use of org.apache.cayenne.graph.CompoundDiff in project cayenne by apache.
the class ObjectContextChangeLogTest method testGetDiffsSerializable.
@Test
public void testGetDiffsSerializable() throws Exception {
ObjectContextChangeLog recorder = new ObjectContextChangeLog();
recorder.addOperation(new NodeCreateOperation(new ObjectId("test")));
CompoundDiff diff = (CompoundDiff) recorder.getDiffs();
Object clone = Util.cloneViaSerialization(diff);
assertNotNull(clone);
assertTrue(clone instanceof CompoundDiff);
CompoundDiff d1 = (CompoundDiff) clone;
assertEquals(1, d1.getDiffs().size());
}
use of org.apache.cayenne.graph.CompoundDiff in project cayenne by apache.
the class ObjectContextChangeLogTest method testGetDiffs.
@Test
public void testGetDiffs() {
// assert that after returning, the diffs array won't get modified by
// operation
// recorder
ObjectContextChangeLog recorder = new ObjectContextChangeLog();
recorder.addOperation(new NodeCreateOperation(new Object()));
CompoundDiff diff = (CompoundDiff) recorder.getDiffs();
assertEquals(1, diff.getDiffs().size());
recorder.addOperation(new NodeCreateOperation(new Object()));
assertEquals(1, diff.getDiffs().size());
CompoundDiff diff2 = (CompoundDiff) recorder.getDiffs();
assertEquals(2, diff2.getDiffs().size());
}
use of org.apache.cayenne.graph.CompoundDiff in project cayenne by apache.
the class DataContext method flushToParent.
/**
* Synchronizes with the parent channel, performing a flush or a commit.
*
* @since 1.2
*/
GraphDiff flushToParent(boolean cascade) {
if (this.getChannel() == null) {
throw new CayenneRuntimeException("Cannot commit changes - channel is not set.");
}
int syncType = cascade ? DataChannel.FLUSH_CASCADE_SYNC : DataChannel.FLUSH_NOCASCADE_SYNC;
ObjectStore objectStore = getObjectStore();
GraphDiff parentChanges = null;
// prevent multiple commits occurring simultaneously
synchronized (objectStore) {
ObjectStoreGraphDiff changes = objectStore.getChanges();
boolean noop = isValidatingObjectsOnCommit() ? changes.validateAndCheckNoop() : changes.isNoop();
if (noop) {
// need to clear phantom changes
objectStore.postprocessAfterPhantomCommit();
} else {
try {
parentChanges = getChannel().onSync(this, changes, syncType);
// Pending better callback design .....
if (objectStore.hasChanges()) {
objectStore.postprocessAfterCommit(parentChanges);
}
// this event is caught by peer nested DataContexts to
// synchronize the
// state
fireDataChannelCommitted(this, changes);
}// "catch" is needed to unwrap OptimisticLockExceptions
catch (CayenneRuntimeException ex) {
Throwable unwound = Util.unwindException(ex);
if (unwound instanceof CayenneRuntimeException) {
throw (CayenneRuntimeException) unwound;
} else {
throw new CayenneRuntimeException("Commit Exception", unwound);
}
}
}
// merge changes from parent as well as changes caused by lifecycle
// event
// callbacks/listeners...
CompoundDiff diff = new CompoundDiff();
diff.addAll(objectStore.getLifecycleEventInducedChanges());
if (parentChanges != null) {
diff.add(parentChanges);
}
// ObjectIds with permanent
if (!diff.isNoop()) {
fireDataChannelCommitted(getChannel(), diff);
}
return diff;
}
}
Aggregations