/** * Determine if the object is a registered new object, and that this is a nested unit of work * merge into the parent. In this case private mappings will register the object as being removed. */ public void registerRemovedNewObjectIfRequired(Object removedObject) { if (getSession().isUnitOfWork()) { UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession(); if (shouldMergeWorkingCopyIntoOriginal() && unitOfWork.getParent().isUnitOfWork() && unitOfWork.isCloneNewObject(removedObject)) { Object originalVersionOfRemovedObject = unitOfWork.getOriginalVersionOfObject(removedObject); unitOfWork.addRemovedObject(originalVersionOfRemovedObject); } } }
/** * Recursively merge changes in the object dependent on the merge policy. * The hastable is used to resolv recursion. */ public Object mergeChanges(Object object, ObjectChangeSet objectChangeSet) throws ValidationException { if (object == null) { return object; } // Do not merged read-only objects in a unit of work. if (getSession().isClassReadOnly(object.getClass())) { return object; } // Means that object is either already merged or in the process of being merged. if (getObjectsAlreadyMerged().containsKey(object)) { return object; } // Put the object to be merged in the set. getObjectsAlreadyMerged().put(object, object); Object mergedObject; if (shouldMergeWorkingCopyIntoOriginal()) { mergedObject = mergeChangesOfWorkingCopyIntoOriginal(object, objectChangeSet); } else if (shouldMergeCloneIntoWorkingCopy() || shouldMergeCloneWithReferencesIntoWorkingCopy()) { mergedObject = mergeChangesOfCloneIntoWorkingCopy(object); } else if (shouldMergeOriginalIntoWorkingCopy()) { mergedObject = mergeChangesOfOriginalIntoWorkingCopy(object); } else { throw ValidationException.invalidMergePolicy(); } return mergedObject; }
/** * Return the coresponding value that should be assigned to the target object for the source object. * This value must be local to the targets object space. */ public Object getTargetVersionOfSourceObject(Object source) { if (shouldMergeWorkingCopyIntoOriginal() || shouldMergeWorkingCopyIntoRemote()) { // Target is in uow parent, or original instance for new object. return ((UnitOfWorkImpl)getSession()).getOriginalVersionOfObject(source); } else if (shouldMergeCloneIntoWorkingCopy() || shouldMergeOriginalIntoWorkingCopy() || shouldMergeCloneWithReferencesIntoWorkingCopy()) { // Target is clone from uow. //make sure we use the register for merge //bug 3584343 return registerObjectForMergeCloneIntoWorkingCopy(source); } else if (shouldRefreshRemoteObject()) { // Target is in session's cache. ClassDescriptor descriptor = getSession().getDescriptor(source); Vector primaryKey = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(source, getSession()); return getSession().getIdentityMapAccessorInstance().getFromIdentityMap(primaryKey, source.getClass(), descriptor); } throw ValidationException.invalidMergePolicy(); }
if (shouldMergeWorkingCopyIntoOriginal()) { sourceSet = buildIdentitySet(source, containerPolicy, false); } else { if (shouldMergeWorkingCopyIntoOriginal()) {// Source and backup are the same space. if (!sourceSet.containsKey(backupElement)) { changeOccured = true; if (shouldMergeWorkingCopyIntoOriginal()) {// Source and backup are the same space. if (!backupSet.containsKey(sourceElement)) { changeOccured = true;
if (isTargetUnInitialized) { if (mergeManager.shouldMergeWorkingCopyIntoOriginal() && (!isAttributeValueInstantiated(source))) { setAttributeValueInObject(target, getIndirectionPolicy().getOriginalIndirectionObject(getAttributeValueFromObject(source), mergeManager.getSession())); return;
if (isTargetUnInitialized) { if (mergeManager.shouldMergeWorkingCopyIntoOriginal() && (!isAttributeValueInstantiated(source))) { setAttributeValueInObject(target, getIndirectionPolicy().getOriginalIndirectionObject(getAttributeValueFromObject(source), mergeManager.getSession())); return;
if (isTargetUnInitialized) { if (mergeManager.shouldMergeWorkingCopyIntoOriginal() && (!isAttributeValueInstantiated(source))) { setAttributeValueInObject(target, getIndirectionPolicy().getOriginalIndirectionObject(getAttributeValueFromObject(source), mergeManager.getSession())); return;
if (isTargetUnInitialized) { if (mergeManager.shouldMergeWorkingCopyIntoOriginal() && (!isAttributeValueInstantiated(source))) { setAttributeValueInObject(target, getIndirectionPolicy().getOriginalIndirectionObject(getAttributeValueFromObject(source), mergeManager.getSession())); return;
if (isTargetUnInitialized) { if (mergeManager.shouldMergeWorkingCopyIntoOriginal() && (!isAttributeValueInstantiated(source))) { setAttributeValueInObject(target, getIndirectionPolicy().getOriginalIndirectionObject(getAttributeValueFromObject(source), mergeManager.getSession())); return;