/** * Add a change set after it has been applied. */ public void simpleAddChangeSet(Object changeSet) { // check whether the change set was removed earlier if (!this.restoreRemovedChangeSet(changeSet)) { // the change set is tacked on the end of the new collection this.addAddedChangeSet(changeSet, this.getNewCollectionSize()); } }
/** * Attempt to restore the specified change set. * Return true if the change set was removed earlier * and was successfully restored to the end of * the collection. */ private boolean restoreRemovedChangeSet(Object changeSet) { int changeSetIndex = this.getRemovesIndexOf(changeSet); if (changeSetIndex == -1) { return false; } this.getRemoves().remove(changeSetIndex); int removeIndex = this.getRemoveIndex(changeSetIndex); this.setRemoveIndexes(this.removeFrom(changeSetIndex, this.getRemoveIndexes())); // now move the change set over to the collection of moves this.addMovedChangeSet(changeSet, removeIndex, this.getNewCollectionSize()); return true; }
/** * Attempt to remove the specified change set * from the collection of moved change sets. * Return true if the change set was moved earlier * and was successfully removed. */ private boolean removeMovedChangeSet(Object changeSet) { int changeSetIndex = this.getMovesIndexOf(changeSet); if (changeSetIndex == -1) { return false; } this.getMoves().remove(changeSetIndex); int beforeMoveIndex = this.getBeforeMoveIndex(changeSetIndex); this.setMoveIndexPairs(this.removeFrom(changeSetIndex, this.getMoveIndexPairs())); // now move the change set over to the collection of removes this.addRemovedChangeSet(changeSet, beforeMoveIndex); return true; }
/** * Remove a change set after it has been applied. */ public void simpleRemoveChangeSet(Object changeSet) { // the change set must have been either moved or added earlier if (!this.removeMovedChangeSet(changeSet)) { this.cancelAddedChangeSet(changeSet); } } }
/** * Add an moved change set. */ public void addMovedChangeSet(Object changeSet, int oldIndex, int newIndex) { getMoves().add(changeSet); int[] pair = new int[2]; pair[0] = oldIndex; pair[1] = newIndex; setMoveIndexPairs(this.addTo(pair, getMoveIndexPairs())); }
EISOrderedCollectionChangeRecord changeRecord = new EISOrderedCollectionChangeRecord(owner, this.getAttributeName(), this.getDatabaseMapping()); changeRecord.addMovedChangeSet(this.buildChangeSet(cloneElement, owner, session), j, i); break;// matching backup element found - skip the rest of them changeRecord.addAddedChangeSet(this.buildChangeSet(cloneElement, owner, session), i); if (backupElement != XXX) { changeRecord.addRemovedChangeSet(this.buildChangeSet(backupElement, owner, session), i); if (changeRecord.hasChanges()) { return changeRecord; } else {
/** * The specified change set was added earlier; * cancel it out. */ private void cancelAddedChangeSet(Object changeSet) { int changeSetIndex = this.getAddsIndexOf(changeSet); if (changeSetIndex == -1) { throw new IllegalStateException(changeSet.toString()); } this.getAdds().remove(changeSetIndex); this.setAddIndexes(this.removeFrom(changeSetIndex, this.getAddIndexes())); }
/** * Add an removed change set. */ public void addRemovedChangeSet(Object changeSet, int index) { getRemoves().add(changeSet); setRemoveIndexes(this.addTo(index, getRemoveIndexes())); }
/** * Add an added change set. */ public void addAddedChangeSet(Object changeSet, int index) { getAdds().add(changeSet); setAddIndexes(this.addTo(index, getAddIndexes())); }
int newSize = this.getNewCollectionSize(); Vector newCollection = new Vector(newSize); for (int i = 0; i < newSize; i++) { if ((addIndex < localAddIndexes.length) && (localAddIndexes[addIndex] == i)) { newCollection.add(this.getAdd(addIndex)); addIndex++; continue; newCollection.add(this.getMove(moveIndex)); moveIndex++; continue;
/** * Remove stuff from an ordered collection. */ private void simpleRemoveFromCollectionChangeRecordWithOrder(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) { EISOrderedCollectionChangeRecord changeRecord = (EISOrderedCollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName()); if (changeRecord == null) { changeRecord = new EISOrderedCollectionChangeRecord(changeSet, this.getAttributeName(), this.getDatabaseMapping()); changeSet.addChange(changeRecord); } changeRecord.simpleRemoveChangeSet(changeSetToRemove); }
/** * Add stuff to an ordered collection. */ private void simpleAddToCollectionChangeRecordWithOrder(Object referenceKey, Object changeSetToAdd, ObjectChangeSet changeSet, AbstractSession session) { EISOrderedCollectionChangeRecord changeRecord = (EISOrderedCollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName()); if (changeRecord == null) { changeRecord = new EISOrderedCollectionChangeRecord(changeSet, this.getAttributeName(), this.getDatabaseMapping()); changeSet.addChange(changeRecord); } changeRecord.simpleAddChangeSet(changeSetToAdd); }
/** * Return the specified add. */ private Object getAdd(int index) { return this.getAdds().get(index); }
EISOrderedCollectionChangeRecord changeRecord = new EISOrderedCollectionChangeRecord(owner, getAttributeName(), this.getDatabaseMapping()); changeRecord.addMovedChangeSet(this.buildChangeSet(cloneElement, owner, session), j, i); break;// matching backup element found - skip the rest of them changeRecord.addAddedChangeSet(this.buildChangeSet(cloneElement, owner, session), i); if (backupElement != XXX) { changeRecord.addRemovedChangeSet(this.buildChangeSet(backupElement, owner, session), i); if (changeRecord.hasChanges()) { return changeRecord; } else {
/** * The specified change set was added earlier; * cancel it out. */ private void cancelAddedChangeSet(Object changeSet) { int changeSetIndex = this.getAddsIndexOf(changeSet); if (changeSetIndex == -1) { throw new IllegalStateException(changeSet.toString()); } this.getAdds().remove(changeSetIndex); this.setAddIndexes(this.removeFrom(changeSetIndex, this.getAddIndexes())); }
/** * Add an moved change set. */ public void addMovedChangeSet(Object changeSet, int oldIndex, int newIndex) { getMoves().add(changeSet); int[] pair = new int[2]; pair[0] = oldIndex; pair[1] = newIndex; setMoveIndexPairs(this.addTo(pair, getMoveIndexPairs())); }
/** * Add an removed change set. */ public void addRemovedChangeSet(Object changeSet, int index) { this.getRemoves().addElement(changeSet); this.setRemoveIndexes(this.addTo(index, this.getRemoveIndexes())); }
/** * Add an added change set. */ public void addAddedChangeSet(Object changeSet, int index) { getAdds().add(changeSet); setAddIndexes(this.addTo(index, getAddIndexes())); }
int newSize = getNewCollectionSize(); List newCollection = new ArrayList(newSize); for (int i = 0; i < newSize; i++) { if ((addIndex < localAddIndexes.length) && (localAddIndexes[addIndex] == i)) { newCollection.add(this.getAdd(addIndex)); addIndex++; continue; newCollection.add(this.getMove(moveIndex)); moveIndex++; continue;
/** * Remove stuff from an ordered collection. */ private void simpleRemoveFromCollectionChangeRecordWithOrder(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) { EISOrderedCollectionChangeRecord changeRecord = (EISOrderedCollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName()); if (changeRecord == null) { changeRecord = new EISOrderedCollectionChangeRecord(changeSet, this.getAttributeName(), this.getDatabaseMapping()); changeSet.addChange(changeRecord); } changeRecord.simpleRemoveChangeSet(changeSetToRemove); }