/** * INTERNAL: * This method sets the list of added objects. It should only be used in RCM */ public void setAddObjectList(Vector list){ for (Iterator iterator = list.iterator(); iterator.hasNext();){ Object object = iterator.next(); this.addAdditionChange(object, new Integer(1)); } }
/** * This method takes a hastable of primitive objects and adds them to the add list. * the hashtable stores the number of times the object is in the list * @param objectChanges prototype.changeset.ObjectChangeSet */ public void addAdditionChange(HashMap additions, HashMap databaseCount) { Iterator enumtr = additions.keySet().iterator(); while (enumtr.hasNext()) { Object object = enumtr.next(); if (databaseCount.containsKey(object)){ getCommitAddMap().put(object, databaseCount.get(object)); } addAdditionChange(object, (Integer)additions.get(object)); } }
/** * INTERNAL: * This method will be used to merge one record into another */ public void mergeRecord(ChangeRecord mergeFromRecord, UnitOfWorkChangeSet mergeToChangeSet, UnitOfWorkChangeSet mergeFromChangeSet) { HashMap addMapToMerge = ((DirectCollectionChangeRecord)mergeFromRecord).getAddObjectMap(); HashMap removeMapToMerge = ((DirectCollectionChangeRecord)mergeFromRecord).getRemoveObjectMap(); //merge additions for (Iterator iterator = addMapToMerge.keySet().iterator(); iterator.hasNext();){ Object added = iterator.next(); if (!((DirectCollectionChangeRecord)mergeFromRecord).getCommitAddMap().containsKey(added)){ // we have not recorded a change of this type in this class before so add it this.getCommitAddMap().put(added, ((DirectCollectionChangeRecord)mergeFromRecord).getCommitAddMap().get(added)); } this.addAdditionChange(added, (Integer)addMapToMerge.get(added)); } //merge removals for (Iterator iterator = removeMapToMerge.keySet().iterator(); iterator.hasNext();){ Object removed = iterator.next(); if (!((DirectCollectionChangeRecord)mergeFromRecord).getCommitAddMap().containsKey(removed)){ // we have not recorded a change of this type in this class before so add it this.getCommitAddMap().put(removed, ((DirectCollectionChangeRecord)mergeFromRecord).getCommitAddMap().get(removed)); } this.addRemoveChange(removed, (Integer)addMapToMerge.get(removed)); } }
return; ((DirectCollectionChangeRecord)changeRecord).addAdditionChange(cloneKeyValues, databaseCount); ((DirectCollectionChangeRecord)changeRecord).addRemoveChange(originalKeyValues, databaseCount); ((DirectCollectionChangeRecord)changeRecord).getCommitAddMap().put(DirectCollectionChangeRecord.Null, new Integer(databaseNullCount)); if (numberOfNewNulls > 0) { ((DirectCollectionChangeRecord)changeRecord).addAdditionChange(DirectCollectionChangeRecord.Null, new Integer(numberOfNewNulls)); } else { numberOfNewNulls *= -1;
/** * 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 objectToAdd, ObjectChangeSet changeSet, AbstractSession session) { DirectCollectionChangeRecord collectionChangeRecord = (DirectCollectionChangeRecord)changeSet.getChangesForAttributeNamed(getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectCollectionChangeRecord(changeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); changeSet.addChange(collectionChangeRecord); Object collection = getRealAttributeValueFromObject(changeSet.getUnitOfWorkClone(), session); collectionChangeRecord.storeDatabaseCounts(collection, getContainerPolicy(), session); } collectionChangeRecord.addAdditionChange(objectToAdd, new Integer(1)); }
/** * INTERNAL: * Add a new value and its change set to the collection change record. This is used by * attribute change tracking. */ public void addToCollectionChangeRecord(Object newKey, Object newValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { if (newValue == null) { newValue = DirectCollectionChangeRecord.Null; } ClassDescriptor descriptor; DirectCollectionChangeRecord collectionChangeRecord = (DirectCollectionChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectCollectionChangeRecord(objectChangeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); objectChangeSet.addChange(collectionChangeRecord); Object collection = getRealAttributeValueFromObject(objectChangeSet.getUnitOfWorkClone(), uow); collectionChangeRecord.storeDatabaseCounts(collection, getContainerPolicy(), uow); } collectionChangeRecord.addAdditionChange(newValue, new Integer(1)); }