/** * INTERNAL: * This method will be used during the merge process to either find an equivalent change set * within this UnitOfWorkChangeSet or integrate that changeset into this UOW ChangeSet */ public ObjectChangeSet findOrIntegrateObjectChangeSet(ObjectChangeSet tofind, UnitOfWorkChangeSet mergeFromChangeSet) { if (tofind == null) { return tofind; } ObjectChangeSet localChangeSet = this.findObjectChangeSet(tofind, mergeFromChangeSet); if (localChangeSet == null) {//not found locally then replace it with the one from the merging changeset localChangeSet = new ObjectChangeSet(tofind.getPrimaryKeys(), tofind.getClassType(), tofind.getUnitOfWorkClone(), this, tofind.isNew()); this.addObjectChangeSetForIdentity(localChangeSet, localChangeSet.getUnitOfWorkClone()); } return localChangeSet; }
if (this == changeSetToMergeFrom || this.isInvalid()) { return; for (int index = 0; index < changeSetToMergeFrom.getChanges().size(); ++index) { ChangeRecord record = (ChangeRecord)changeSetToMergeFrom.getChanges().get(index); ChangeRecord thisRecord = (ChangeRecord) this.getChangesForAttributeNamed(record.getAttribute()); if (thisRecord == null) { record.updateReferences(mergeToChangeSet, mergeFromChangeSet); record.setOwner(this); this.addChange(record); } else { thisRecord.mergeRecord(record, mergeToChangeSet, mergeFromChangeSet); this.setOldKey(changeSetToMergeFrom.oldKey); this.setNewKey(changeSetToMergeFrom.newKey); this.hasVersionChange = changeSetToMergeFrom.hasVersionChange; this.shouldModifyVersionField = changeSetToMergeFrom.shouldModifyVersionField;
/** * @return boolean * @param objectChange prototype.changeset.ObjectChangeSet */ public boolean equals(Object object) { if (object instanceof ObjectChangeSet) { return equals((ObjectChangeSet)object); } return false; }
/** * INTERNAL: * Remove change. Used by the event mechanism to reset changes after client has * updated the object within an event; */ public void removeChange(String attributeName){ Object record = getChangesForAttributeNamed(attributeName); if (record != null){ getChanges().removeElement(record); } }
/** * INTERNAL: */ public void setPrimaryKeys(Vector key) { if (key == null) { return; } if (getCacheKey() == null) { setCacheKey(new CacheKey(key)); } else { getCacheKey().setKey(key); } }
object = objectChanges.getTargetVersionOfSourceObject(parentSession); if ((object == null) && (objectChanges.isNew() || objectChanges.isAggregate()) && objectChanges.containsChangesFromSynchronization()) { if (!mergeManager.getObjectsAlreadyMerged().containsKey(objectChanges)) { Class objectClass = objectChanges.getClassType(mergeManager.getSession()); object = mergeManager.getSession().getDescriptor(objectClass).getObjectBuilder().buildNewInstance(); object = objectChanges.getTargetVersionOfSourceObject(parentSession, true); if (objectChanges.containsChangesFromSynchronization()) { mergeManager.mergeChanges(object, objectChanges); mergeManager.mergeChanges(objectChanges.getUnitOfWorkClone(), objectChanges);
/** * 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)); }
boolean objectChangeSetHasChanges = objectChanges.hasChanges(); if (objectChangeSetHasChanges) { this.setHasChanges(true); this.hasForcedChanges = this.hasForcedChanges || objectChanges.hasForcedChanges(); } else { if (!objectChanges.isAggregate()) { if (objectChangeSetHasChanges) { if (objectChanges.getCacheKey() != null) { Hashtable table = (Hashtable)getObjectChanges().get(objectChanges.getClassName()); getObjectChanges().put(objectChanges.getClassName(), table); table.put(objectChanges, objectChanges); } else {
objChangeSet.setUOWChangeSet(this); if (objChangeSet.isAggregate()) { getAggregateList().put(objChangeSet, objChangeSet); } else if (objChangeSet.shouldBeDeleted()) { getDeletedObjects().put(objChangeSet, objChangeSet); } else { getAllChangeSets().put(objChangeSet, objChangeSet); if (objChangeSet.getCacheKey() != null) { Hashtable table = (Hashtable)getObjectChanges().get(objChangeSet.getClassName()); if (table == null) { table = new Hashtable(2); getObjectChanges().put(objChangeSet.getClassName(), table);
AggregateChangeRecord changeRecord = (AggregateChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (changeRecord == null){ changeRecord = new AggregateChangeRecord(objectChangeSet); changeRecord.setAttribute(this.getAttributeName()); changeRecord.setMapping(this); objectChangeSet.addChange(changeRecord); if ( sourceClone.getClass().equals(objectChangeSet.getClassType(uow)) ) { return; }else{ // attribute set to new aggregate UnitOfWorkChangeSet uowChangeSet = (UnitOfWorkChangeSet)objectChangeSet.getUOWChangeSet(); aggregateChangeSet.clear(); // old differences must be thrown away because difference is between old value and new value changeRecord.setChangedObject(referenceDescriptor.getObjectChangePolicy().createObjectChangeSetThroughComparison(sourceClone, null, (UnitOfWorkChangeSet)objectChangeSet.getUOWChangeSet(), true, uow, referenceDescriptor));
/** * 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); } }
/** * 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 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); } }
if (writeQuery.getObjectChangeSet().hasChanges()) { writeQuery.getObjectChangeSet().clear(); if(writeQuery.getDescriptor().getObjectChangePolicy().calculateChanges(object, ((UnitOfWorkImpl)event.getSession()).getBackupClone(object), uowChangeSet, writeQuery.getSession(), writeQuery.getDescriptor(), false) == null) { Boolean shouldModifyVersionField = writeQuery.getObjectChangeSet().shouldModifyVersionField(); if (!getModifyRow().isEmpty() || (shouldModifyVersionField != null) || writeQuery.getObjectChangeSet().hasCmpPolicyForcedUpdate()) {
/** * @param changeRecord prototype.changeset.ChangeRecord */ public void addChange(ChangeRecord changeRecord) { if (changeRecord == null) { return; } ChangeRecord existingChangeRecord = (ChangeRecord)getAttributesToChanges().get(changeRecord.getAttribute()); // change tracking may add a change to an existing attribute fix that here. if ( existingChangeRecord != null){ getChanges().remove(existingChangeRecord); } getChanges().addElement(changeRecord); getAttributesToChanges().put(changeRecord.getAttribute(), changeRecord); updateUOWChangeSet(); }
/** * 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 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); } }
/** * 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); } }
AggregateChangeRecord record = (AggregateChangeRecord)objectChangeSet.getChangesForAttributeNamed(mapping.getAttributeName()); if (aggregate != null) { if (record == null) { record.setAttribute(mapping.getAttributeName()); record.setMapping(mapping); objectChangeSet.addChange(record); objectChangeSet.updateChangeRecordForAttribute(mapping, attributeValue); } else { getSession().log(SessionLog.FINEST, SessionLog.QUERY, "field_for_unsupported_mapping_returned", field, getDescriptor());
CollectionChangeRecord record = (CollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName()); UnitOfWorkChangeSet uowChangeSet = (UnitOfWorkChangeSet)changeSet.getUOWChangeSet(); Enumeration removedObjects = record.getRemoveObjectList().elements(); objectRemovedDuringUpdate(query, removedChangeSet.getUnitOfWorkClone()); objectAddedDuringUpdate(query, addedChangeSet.getUnitOfWorkClone(), addedChangeSet);