/** * INTERNAL: * Build and return a clone of the attribute. */ protected Object buildClonePart(Object original, Object attributeValue, UnitOfWorkImpl unitOfWork) { if (attributeValue == null) { return null; } if (unitOfWork.isOriginalNewObject(original)) { unitOfWork.addNewAggregate(attributeValue); } // Do not clone for read-only. if (unitOfWork.isClassReadOnly(attributeValue.getClass())) { return attributeValue; } ObjectBuilder aggregateObjectBuilder = getObjectBuilder(attributeValue, unitOfWork); // bug 2612602 as we are building the working copy make sure that we call to correct clone method. Object clonedAttributeValue = aggregateObjectBuilder.instantiateWorkingCopyClone(attributeValue, unitOfWork); aggregateObjectBuilder.populateAttributesForClone(attributeValue, clonedAttributeValue, unitOfWork); return clonedAttributeValue; }
workingClone = instantiateWorkingCopyClone(original, unitOfWork);
/** * INTERNAL: * Clone the aggregate collection, if necessary. */ protected Object buildElementClone(Object element, UnitOfWorkImpl unitOfWork, boolean isExisting) { // Do not clone for read-only. if (unitOfWork.isClassReadOnly(element.getClass())) { return element; } ClassDescriptor aggregateDescriptor = getReferenceDescriptor(element.getClass(), unitOfWork); // bug 2612602 as we are building the working copy make sure that we call to correct clone method. Object clonedElement = aggregateDescriptor.getObjectBuilder().instantiateWorkingCopyClone(element, unitOfWork); aggregateDescriptor.getObjectBuilder().populateAttributesForClone(element, clonedElement, unitOfWork); // CR 4155 add the originals to the UnitOfWork so that we can find it later in the merge // as aggregates have no identity. If we don't do this we will loose indirection information. unitOfWork.getCloneToOriginals().put(clonedElement, element); return clonedElement; }
/** * ADVANCED: * Register the new object with the unit of work. * This will register the new object with cloning. * Normally the registerObject method should be used for all registration of new and existing objects. * This version of the register method can only be used for new objects. * This method should only be used if a new object is desired to be registered without an existence Check. * * @see #registerObject(Object) */ public Object cloneAndRegisterNewObject(Object original) { ClassDescriptor descriptor = getDescriptor(original); ObjectBuilder builder = descriptor.getObjectBuilder(); // bug 2612602 create the working copy object. Object clone = builder.instantiateWorkingCopyClone(original, this); // Must put in the original to clone to resolv circular refs. getNewObjectsOriginalToClone().put(original, clone); // Must put in clone mapping. getCloneMapping().put(clone, clone); builder.populateAttributesForClone(original, clone, this); // Must reregister in both new objects. registerNewObjectClone(clone, original, descriptor); //Build backup clone for DeferredChangeDetectionPolicy or ObjectChangeTrackingPolicy, //but not for AttributeChangeTrackingPolicy Object backupClone = descriptor.getObjectChangePolicy().buildBackupClone(clone, builder, this); getCloneMapping().put(clone, backupClone);// The backup clone must be updated. return clone; }
Object workingClone = builder.instantiateWorkingCopyClone(original, this);