/** * INTERNAL: * Either create a new change record or update with the new value. This is used * by attribute change tracking. */ public void updateChangeRecord(Object clone, Object newValue, Object oldValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { DirectToFieldChangeRecord changeRecord = (DirectToFieldChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (changeRecord == null) { objectChangeSet.addChange(internalBuildChangeRecord(newValue, objectChangeSet)); } else { changeRecord.setNewValue(newValue); } }
/** * 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) { DirectMapChangeRecord collectionChangeRecord = (DirectMapChangeRecord)changeSet.getChangesForAttributeNamed(getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectMapChangeRecord(changeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); collectionChangeRecord.getAddObjects().put(referenceKey, objectToAdd); changeSet.addChange(collectionChangeRecord); } else { if (collectionChangeRecord.getRemoveObjects().containsKey(referenceKey)) { collectionChangeRecord.getRemoveObjects().remove(referenceKey); } else { collectionChangeRecord.getAddObjects().put(referenceKey, objectToAdd); } } }
/** * 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 objectToRemove, ObjectChangeSet changeSet, AbstractSession session) { DirectMapChangeRecord collectionChangeRecord = (DirectMapChangeRecord)changeSet.getChangesForAttributeNamed(getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectMapChangeRecord(changeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); collectionChangeRecord.getRemoveObjects().put(referenceKey, objectToRemove); changeSet.addChange(collectionChangeRecord); } else { if (collectionChangeRecord.getAddObjects().containsKey(referenceKey)) { collectionChangeRecord.getAddObjects().remove(referenceKey); } else { collectionChangeRecord.getRemoveObjects().put(referenceKey, objectToRemove); } } }
/** * INTERNAL: * Create ObjectChangeSet */ public ObjectChangeSet createObjectChangeSetThroughComparison(Object clone, Object backUp, oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet changeSet, boolean isNew, AbstractSession session, ClassDescriptor descriptor) { ObjectBuilder builder = descriptor.getObjectBuilder(); ObjectChangeSet changes = builder.createObjectChangeSet(clone, changeSet, isNew, session); // The following code deals with reads that force changes to the flag associated with optimistic locking. if ((descriptor.usesOptimisticLocking()) && (changes.getPrimaryKeys() != null)) { changes.setOptimisticLockingPolicyAndInitialWriteLockValue(descriptor.getOptimisticLockingPolicy(), session); } // PERF: Avoid synchronized enumerator as is concurrency bottleneck. Vector mappings = descriptor.getMappings(); int mappingsSize = mappings.size(); for (int index = 0; index < mappingsSize; index++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(index); changes.addChange(mapping.compareForChange(clone, backUp, changes, session)); } return changes; }
/** * 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. PLEASE ENSURE that the changes * have been made in the object model first. */ public void simpleRemoveFromCollectionChangeRecord(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) { AggregateCollectionChangeRecord collectionChangeRecord = (AggregateCollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.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 = (AggregateCollectionChangeRecord)convertToChangeRecord(cloneCollection, changeSet, session); changeSet.addChange(collectionChangeRecord); } else { collectionChangeRecord.getChangedValues().remove(changeSetToRemove); } }
/** * 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. PLEASE ENSURE that the changes * have been made in the object model first. */ public void simpleAddToCollectionChangeRecord(Object referenceKey, Object changeSetToAdd, ObjectChangeSet changeSet, AbstractSession session) { AggregateCollectionChangeRecord collectionChangeRecord = (AggregateCollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.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 = (AggregateCollectionChangeRecord)convertToChangeRecord(cloneCollection, changeSet, session); changeSet.addChange(collectionChangeRecord); } else { collectionChangeRecord.getChangedValues().add(changeSetToAdd); } }
/** * INTERNAL: * Add a new value and its change set to the collection change record. This is used by * attribute change tracking. If a value has changed then issue a remove first with the key * then an add. */ public void addToCollectionChangeRecord(Object newKey, Object newValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) throws DescriptorException { DirectMapChangeRecord collectionChangeRecord = (DirectMapChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectMapChangeRecord(objectChangeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); objectChangeSet.addChange(collectionChangeRecord); } collectionChangeRecord.addAdditionChange(newKey, newValue); }
/** * INTERNAL: * Remove a value and its change set from the collection change record. This is used by * attribute change tracking. */ public void removeFromCollectionChangeRecord(Object newKey, Object newValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) throws DescriptorException { DirectMapChangeRecord collectionChangeRecord = (DirectMapChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectMapChangeRecord(objectChangeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); objectChangeSet.addChange(collectionChangeRecord); } collectionChangeRecord.addRemoveChange(newKey, newValue); }
/** * 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 objectToRemove, 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.addRemoveChange(objectToRemove, new Integer(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)); }
/** * INTERNAL: * Remove a value and its change set from the collection change record. This is used by * attribute change tracking. */ public void removeFromCollectionChangeRecord(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.addRemoveChange(newValue, new Integer(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 changeSetToAdd, ObjectChangeSet changeSet, AbstractSession session) { CollectionChangeRecord collectionChangeRecord = (CollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new CollectionChangeRecord(changeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); collectionChangeRecord.getAddObjectList().put(changeSetToAdd, changeSetToAdd); collectionChangeRecord.getOrderedAddObjects().add(changeSetToAdd); changeSet.addChange(collectionChangeRecord); } else { getContainerPolicy().recordAddToCollectionInChangeRecord((ObjectChangeSet)changeSetToAdd, collectionChangeRecord); } if (referenceKey != null){ ((ObjectChangeSet)changeSetToAdd).setNewKey(referenceKey); } }
/** * INTERNAL: * Used to update a changeRecord that is stored in the CHangeSet with a new value. */ public void updateChangeRecordForAttribute(DatabaseMapping mapping, Object value) { String attributeName = mapping.getAttributeName(); ChangeRecord changeRecord = (ChangeRecord)getChangesForAttributeNamed(attributeName); // bug 2641228 always ensure that we convert the value to the correct type value = ConversionManager.getDefaultManager().convertObject(value, mapping.getAttributeClassification()); if (changeRecord != null) { changeRecord.updateChangeRecordWithNewValue(value); } else if (mapping.isDirectToFieldMapping()) { //if it is direct to field then this is most likely the result of a forced update and // we will need to merge this object changeRecord = new DirectToFieldChangeRecord(this); changeRecord.setAttribute(attributeName); changeRecord.setMapping(mapping); ((DirectToFieldChangeRecord)changeRecord).setNewValue(value); this.addChange(changeRecord); } }
/** * INTERNAL: * Either create a new change record or update the change record with the new value. * This is used by attribute change tracking. */ public void updateChangeRecord(Object clone, Object newValue, Object oldValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) throws DescriptorException { DirectMapChangeRecord collectionChangeRecord = (DirectMapChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectMapChangeRecord(objectChangeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); objectChangeSet.addChange(collectionChangeRecord); } if (collectionChangeRecord.getOriginalCollection() == null){ collectionChangeRecord.setOriginalCollection(oldValue); } collectionChangeRecord.setLatestCollection(newValue); objectChangeSet.deferredDetectionRequiredOn(getAttributeName()); }
/** * 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) { CollectionChangeRecord collectionChangeRecord = (CollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new CollectionChangeRecord(changeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); collectionChangeRecord.getRemoveObjectList().put(changeSetToRemove, changeSetToRemove); changeSet.addChange(collectionChangeRecord); } else { getContainerPolicy().recordRemoveFromCollectionInChangeRecord((ObjectChangeSet)changeSetToRemove, collectionChangeRecord); } if (referenceKey != null){ ((ObjectChangeSet)changeSetToRemove).setOldKey(referenceKey); } }
/** * INTERNAL: * Either create a new change record or update with the new value. This is used * by attribute change tracking. * Specifically in a collection mapping this will be called when the customer * Set a new collection. In this case we will need to mark the change record * with the new and the old versions of the collection. * And mark the ObjectChangeSet with the attribute name then when the changes are calculated * force a compare on the collections to determine changes. */ public void updateChangeRecord(Object clone, Object newValue, Object oldValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { DirectCollectionChangeRecord collectionChangeRecord = (DirectCollectionChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectCollectionChangeRecord(objectChangeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); objectChangeSet.addChange(collectionChangeRecord); } if (collectionChangeRecord.getOriginalCollection() == null){ collectionChangeRecord.setOriginalCollection(oldValue); } collectionChangeRecord.setLatestCollection(newValue); objectChangeSet.deferredDetectionRequiredOn(getAttributeName()); }
/** * INTERNAL: * Either create a new change record or update with the new value. This is used * by attribute change tracking. * Specifically in a collection mapping this will be called when the customer * Set a new collection. In this case we will need to mark the change record * with the new and the old versions of the collection. * And mark the ObjectChangeSet with the attribute name then when the changes are calculated * force a compare on the collections to determine changes. */ public void updateChangeRecord(Object clone, Object newValue, Object oldValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { CollectionChangeRecord collectionChangeRecord = (CollectionChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new CollectionChangeRecord(objectChangeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); objectChangeSet.addChange(collectionChangeRecord); } if (collectionChangeRecord.getOriginalCollection() == null){ collectionChangeRecord.setOriginalCollection(oldValue); } collectionChangeRecord.setLatestCollection(newValue); objectChangeSet.deferredDetectionRequiredOn(getAttributeName()); }
/** * INTERNAL: * Either create a new change record or update the change record with the new value. * This is used by attribute change tracking. */ public void updateChangeRecord(Object clone, Object newValue, Object oldValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { // Must ensure values are unwrapped. Object unwrappedNewValue = newValue; Object unwrappedOldValue = oldValue; if (newValue != null) { unwrappedNewValue = getReferenceDescriptor().getObjectBuilder().unwrapObject(newValue, uow); } if (oldValue != null) { unwrappedOldValue = getReferenceDescriptor().getObjectBuilder().unwrapObject(oldValue, uow); } ObjectReferenceChangeRecord changeRecord = (ObjectReferenceChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (changeRecord == null) { changeRecord = internalBuildChangeRecord(unwrappedNewValue, objectChangeSet, uow); changeRecord.setOldValue(unwrappedOldValue); objectChangeSet.addChange(changeRecord); } else { setNewValueInChangeRecord(unwrappedNewValue, changeRecord, objectChangeSet, uow); } }
changeRecord.setAttribute(this.getAttributeName()); changeRecord.setMapping(this); objectChangeSet.addChange(changeRecord);