ServerToClientDiffConverter(EntityResolver resolver) { this.resolver = resolver; this.clientDiff = new CompoundDiff(); }
GraphDiff filter(GraphDiff in) { diffs = new ArrayList<>(); in.apply(this); return new CompoundDiff(diffs); }
/** * Returns a combined GraphDiff for all recorded operations. */ GraphDiff getDiffs() { return new CompoundDiff(immutableList(0, diffs.size())); }
/** * Processes internal objects after the parent DataContext was committed. Changes * object persistence state and handles snapshot updates. * * @since 1.1 * @deprecated since 1.2 unused. */ public synchronized void objectsCommitted() { postprocessAfterCommit(new CompoundDiff()); }
GraphDiff getDiffsAfterMarker(String markerTag) { Integer pos = markers.get(markerTag); int marker = (pos == null) ? -1 : pos.intValue(); if (marker < 0) { throw new IllegalStateException("No marked position for tag '" + markerTag + "'"); } return new CompoundDiff(immutableList(marker, diffs.size())); }
GraphDiff getDiffsAfterMarker(String markerTag) { Integer pos = (Integer) markers.get(markerTag); int marker = (pos == null) ? -1 : pos.intValue(); if (marker < 0) { throw new IllegalStateException("No marked position for tag '" + markerTag + "'"); } return new CompoundDiff(immutableList(marker, diffs.size())); }
/** * Returns a combined GraphDiff for all recorded operations. */ GraphDiff getDiffs() { return new CompoundDiff(immutableList(0, diffs.size())); }
GraphDiff onContextRollback(ObjectContext originatingContext) { rollbackChanges(); return new CompoundDiff(); }
GraphDiff onContextRollback(ObjectContext originatingContext) { rollbackChanges(); return (channel != null) ? channel.onSync( this, null, DataChannel.ROLLBACK_CASCADE_SYNC) : new CompoundDiff(); }
GraphDiff onSyncRollback(ObjectContext originatingContext) { // if there is a transaction in progress, roll it back Transaction transaction = BaseTransaction.getThreadTransaction(); if (transaction != null) { transaction.setRollbackOnly(); } return new CompoundDiff(); }
/** * Converts diffs organized by ObjectId in a collection of diffs sorted by diffId * (same as creation order). */ private void resolveDiff() { if (resolvedDiff == null) { CompoundDiff diff = new CompoundDiff(); Map changes = getChangesByObjectId(); if (!changes.isEmpty()) { List allChanges = new ArrayList(changes.size() * 2); Iterator it = changes.values().iterator(); while (it.hasNext()) { ((ObjectDiff) it.next()).appendDiffs(allChanges); } Collections.sort(allChanges); diff.addAll(allChanges); } this.resolvedDiff = diff; } }
GraphDiff onSyncRollback(ObjectContext originatingContext) { // if there is a transaction in progress, roll it back Transaction transaction = Transaction.getThreadTransaction(); if (transaction != null) { transaction.setRollbackOnly(); } return new CompoundDiff(); }
/** * Converts diffs organized by ObjectId in a collection of diffs sorted by * diffId (same as creation order). */ private void resolveDiff() { // refresh the diff on first access or if the underlying ObjectStore has // changed the the last time we cached the changes. if (resolvedDiff == null || lastSeenDiffId < objectStore.currentDiffId) { CompoundDiff diff = new CompoundDiff(); Map<Object, ObjectDiff> changes = getChangesByObjectId(); if (!changes.isEmpty()) { List<NodeDiff> allChanges = new ArrayList<>(changes.size() * 2); for (final ObjectDiff objectDiff : changes.values()) { objectDiff.appendDiffs(allChanges); } Collections.sort(allChanges); diff.addAll(allChanges); } this.lastSeenDiffId = objectStore.currentDiffId; this.resolvedDiff = diff; } }
return new CompoundDiff(compressed);
GraphDiff flush(DataContext context, GraphDiff changes) { if (changes == null) { return new CompoundDiff(); } // TODO: Andrus, 3/13/2006 - support categorizing an arbitrary diff if (!(changes instanceof ObjectStoreGraphDiff)) { throw new IllegalArgumentException("Expected 'ObjectStoreGraphDiff', got: " + changes.getClass().getName()); } this.context = context; // ObjectStoreGraphDiff contains changes already categorized by objectId... this.changesByObjectId = ((ObjectStoreGraphDiff) changes).getChangesByObjectId(); this.insertBucket = new DataDomainInsertBucket(this); this.deleteBucket = new DataDomainDeleteBucket(this); this.updateBucket = new DataDomainUpdateBucket(this); this.flattenedBucket = new DataDomainFlattenedBucket(this); this.queries = new ArrayList<>(); this.resultIndirectlyModifiedIds = new HashSet<>(); preprocess(context, changes); if (queries.isEmpty()) { return new CompoundDiff(); } this.resultDiff = new CompoundDiff(); this.resultDeletedIds = new ArrayList<>(); this.resultModifiedSnapshots = new HashMap<>(); runQueries(); postprocess(context); return resultDiff; }
GraphDiff onContextFlush( ObjectContext originatingContext, GraphDiff changes, boolean cascade) { if (this != originatingContext && changes != null) { changes.apply(new ChildDiffLoader(this)); fireDataChannelChanged(originatingContext, changes); } return (cascade) ? flushToParent(true) : new CompoundDiff(); }
@Override protected GraphDiff onContextFlush(ObjectContext originatingContext, GraphDiff changes, boolean cascade) { boolean childContext = this != originatingContext && changes != null; if (childContext) { // PropertyChangeProcessingStrategy oldStrategy = // getPropertyChangeProcessingStrategy(); // setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.RECORD); try { changes.apply(new CayenneContextChildDiffLoader(this)); } finally { // setPropertyChangeProcessingStrategy(oldStrategy); } fireDataChannelChanged(originatingContext, changes); } return (cascade) ? doCommitChanges(true) : new CompoundDiff(); }
@Override protected GraphDiff onContextFlush(ObjectContext originatingContext, GraphDiff changes, boolean cascade) { boolean childContext = this != originatingContext && changes != null; try { if (childContext) { getObjectStore().childContextSyncStarted(); changes.apply(new ChildDiffLoader(this)); fireDataChannelChanged(originatingContext, changes); } return (cascade) ? flushToParent(true) : new CompoundDiff(); } finally { if (childContext) { getObjectStore().childContextSyncStopped(); } } }
/** * 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(); // call channel with changes BEFORE reverting them, so that any // interceptors // could record them 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); } } }
CompoundDiff notification = new CompoundDiff(); notification.add(childDiff); notification.add(returnClientDiff);