/** * ADVANCED: * This method is used to have an object removed from a collection once the changeSet is applied * The referenceKey parameter should only be used for direct Maps. */ public void simpleRemoveFromCollectionChangeRecord(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) { DirectToFieldChangeRecord collectionChangeRecord = (DirectToFieldChangeRecord)changeSet.getAttributesToChanges().get(getAttributeName()); if (collectionChangeRecord == null) { //if there is no change for this attribute then create a changeSet for it. no need to modify the resulting // change record as it should be built from the clone which has the changes allready Object cloneObject = ((UnitOfWorkChangeSet)changeSet.getUOWChangeSet()).getUOWCloneForObjectChangeSet(changeSet); Object cloneCollection = this.getRealAttributeValueFromObject(cloneObject, session); collectionChangeRecord = (DirectToFieldChangeRecord)convertToChangeRecord(cloneCollection, changeSet, session); changeSet.addChange(collectionChangeRecord); } else { getContainerPolicy().removeFrom(changeSetToRemove, collectionChangeRecord.getNewValue(), session); } }
/** * ADVANCED: * This method is used to have an object add to a collection once the changeSet is applied * The referenceKey parameter should only be used for direct Maps. */ public void simpleAddToCollectionChangeRecord(Object referenceKey, Object changeSetToAdd, ObjectChangeSet changeSet, AbstractSession session) { DirectToFieldChangeRecord collectionChangeRecord = (DirectToFieldChangeRecord)changeSet.getAttributesToChanges().get(getAttributeName()); if (collectionChangeRecord == null) { //if there is no change for this attribute then create a changeSet for it. no need to modify the resulting // change record as it should be built from the clone which has the changes allready Object cloneObject = ((UnitOfWorkChangeSet)changeSet.getUOWChangeSet()).getUOWCloneForObjectChangeSet(changeSet); Object cloneCollection = this.getRealAttributeValueFromObject(cloneObject, session); collectionChangeRecord = (DirectToFieldChangeRecord)convertToChangeRecord(cloneCollection, changeSet, session); changeSet.addChange(collectionChangeRecord); } else { getContainerPolicy().addInto(changeSetToAdd, collectionChangeRecord.getNewValue(), session); } }
protected ChangeRecord convertToChangeRecord(Object cloneCollection, ObjectChangeSet owner, AbstractSession session) { //since a minimal update for composites can't be done, we are only recording //an all-or-none change. Therefore, this can be treated as a simple direct //value. ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(cloneCollection); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, session), container, session); } DirectToFieldChangeRecord changeRecord = new DirectToFieldChangeRecord(owner); changeRecord.setAttribute(getAttributeName()); changeRecord.setMapping(this); changeRecord.setNewValue(container); return changeRecord; }
protected ChangeRecord convertToChangeRecord(Object cloneCollection, ObjectChangeSet owner, AbstractSession session) { //since a minimal update for composites can't be done, we are only recording //an all-or-none change. Therefore, this can be treated as a simple direct //value. ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(cloneCollection); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, session), container, session); } DirectToFieldChangeRecord changeRecord = new DirectToFieldChangeRecord(owner); changeRecord.setAttribute(getAttributeName()); changeRecord.setMapping(this); changeRecord.setNewValue(container); return changeRecord; }
protected ChangeRecord convertToChangeRecord(Object cloneCollection, ObjectChangeSet owner, AbstractSession session) { //since a minimal update for composites can't be done, we are only recording //an all-or-none change. Therefore, this can be treated as a simple direct //value. ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(cloneCollection); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, session), container, session); } DirectToFieldChangeRecord changeRecord = new DirectToFieldChangeRecord(owner); changeRecord.setAttribute(getAttributeName()); changeRecord.setMapping(this); changeRecord.setNewValue(container); return changeRecord; }