use of org.apache.cayenne.graph.CompoundDiff in project cayenne by apache.
the class DataContext method rollbackChanges.
/**
* Reverts any changes that have occurred to objects registered with
* DataContext; also performs cascading rollback of all parent DataContexts.
*/
@Override
public void rollbackChanges() {
if (objectStore.hasChanges()) {
GraphDiff diff = getObjectStore().getChanges();
if (channel != null) {
channel.onSync(this, diff, DataChannel.ROLLBACK_CASCADE_SYNC);
}
getObjectStore().objectsRolledBack();
fireDataChannelRolledback(this, diff);
} else {
if (channel != null) {
channel.onSync(this, new CompoundDiff(), DataChannel.ROLLBACK_CASCADE_SYNC);
}
}
}
use of org.apache.cayenne.graph.CompoundDiff in project cayenne by apache.
the class DataDomainSyncBucket method postprocess.
void postprocess() {
if (!objectsByDescriptor.isEmpty()) {
CompoundDiff result = parent.getResultDiff();
Map<ObjectId, DataRow> modifiedSnapshots = parent.getResultModifiedSnapshots();
Collection<ObjectId> deletedIds = parent.getResultDeletedIds();
for (Map.Entry<ClassDescriptor, List<Persistent>> entry : objectsByDescriptor.entrySet()) {
ClassDescriptor descriptor = entry.getKey();
for (Persistent object : entry.getValue()) {
ObjectId id = object.getObjectId();
ObjectId finalId;
// record id change and update attributes for generated ids
if (id.isReplacementIdAttached()) {
Map<String, Object> replacement = id.getReplacementIdMap();
for (AttributeProperty property : descriptor.getIdProperties()) {
Object value = replacement.get(property.getAttribute().getDbAttributeName());
// if the id wasn't generated. We may need to optimize it...
if (value != null) {
property.writePropertyDirectly(object, null, value);
}
}
ObjectId replacementId = id.createReplacementId();
result.add(new NodeIdChangeOperation(id, replacementId));
// DataRowCache has no notion of replaced id...
if (!id.isTemporary()) {
deletedIds.add(id);
}
finalId = replacementId;
} else if (id.isTemporary()) {
throw new CayenneRuntimeException("Temporary ID hasn't been replaced on commit: %s", object);
} else {
finalId = id;
}
// do not take the snapshot until generated columns are processed (see code above)
DataRow dataRow = parent.getContext().currentSnapshot(object);
if (object instanceof DataObject) {
DataObject dataObject = (DataObject) object;
dataRow.setReplacesVersion(dataObject.getSnapshotVersion());
dataObject.setSnapshotVersion(dataRow.getVersion());
}
modifiedSnapshots.put(finalId, dataRow);
// update Map reverse relationships
for (ArcProperty arc : descriptor.getMapArcProperties()) {
ToManyMapProperty reverseArc = (ToManyMapProperty) arc.getComplimentaryReverseArc();
// must resolve faults... hopefully for to-one this will not cause extra fetches...
Object source = arc.readProperty(object);
if (source != null && !reverseArc.isFault(source)) {
remapTarget(reverseArc, source, object);
}
}
}
}
}
}
use of org.apache.cayenne.graph.CompoundDiff in project cayenne by apache.
the class ObjectContextChangeLogSubListMessageFactoryTest method testGetDiffsSerializable.
@Test
public void testGetDiffsSerializable() throws Exception {
ObjectContextChangeLog recorder = new ObjectContextChangeLog();
recorder.addOperation(new NodeCreateOperation(new ObjectId("test")));
CompoundDiff diff = (CompoundDiff) recorder.getDiffs();
byte[] data = serializationService.serialize(diff);
CompoundDiff diff0 = serializationService.deserialize(data, CompoundDiff.class);
assertNotNull(diff0);
assertEquals(1, diff0.getDiffs().size());
}
use of org.apache.cayenne.graph.CompoundDiff in project cayenne by apache.
the class CayenneContext method onContextFlush.
@Override
protected GraphDiff onContextFlush(ObjectContext originatingContext, GraphDiff changes, boolean cascade) {
boolean childContext = this != originatingContext && changes != null;
if (childContext) {
changes.apply(new CayenneContextChildDiffLoader(this));
fireDataChannelChanged(originatingContext, changes);
}
return (cascade) ? doCommitChanges(true) : new CompoundDiff();
}
use of org.apache.cayenne.graph.CompoundDiff in project cayenne by apache.
the class ObjectContextChangeLogTest method testGetDiffsSerializableWithHessian.
@Test
public void testGetDiffsSerializableWithHessian() throws Exception {
ObjectContextChangeLog recorder = new ObjectContextChangeLog();
// id must be a serializable object
recorder.addOperation(new NodeCreateOperation("id-string"));
CompoundDiff diff = (CompoundDiff) recorder.getDiffs();
Object clone = HessianUtil.cloneViaClientServerSerialization(diff, new EntityResolver());
assertNotNull(clone);
assertTrue(clone instanceof CompoundDiff);
CompoundDiff d1 = (CompoundDiff) clone;
assertEquals(1, d1.getDiffs().size());
}
Aggregations