/** * PUBLIC: * Return a complete copy of the object. * This can be used to obtain a scatch copy of an object, * or for templatizing an existing object into another new object. * The object and all of its privately owned parts will be copied, the object's primary key will be reset to null. * * @see #copyObject(Object, ObjectCopyingPolicy) */ public Object copyObject(Object original) { return copyObject(original, new ObjectCopyingPolicy()); }
/** * INTERNAL: * Copy of the attribute of the object. * This is NOT used for unit of work but for templatizing an object. */ public void buildCopy(Object copy, Object original, ObjectCopyingPolicy policy) { Object attributeValue = getRealAttributeValueFromObject(original, policy.getSession()); if ((attributeValue != null) && (policy.shouldCascadeAllParts() || (policy.shouldCascadePrivateParts() && isPrivateOwned()))) { attributeValue = policy.getSession().copyObject(attributeValue, policy); } else if (attributeValue != null) { // Check for copy of part, i.e. back reference. Object copyValue = policy.getCopies().get(attributeValue); if (copyValue != null) { attributeValue = copyValue; } } setRealAttributeValueInObject(copy, attributeValue); }
/** * INTERNAL: * Copy of the attribute of the object. * This is NOT used for unit of work but for templatizing an object. */ public void buildCopy(Object copy, Object original, ObjectCopyingPolicy policy) { Object attributeValue = getRealCollectionAttributeValueFromObject(original, policy.getSession()); Object valuesIterator = getContainerPolicy().iteratorFor(attributeValue); attributeValue = getContainerPolicy().containerInstance(getContainerPolicy().sizeFor(attributeValue)); while (getContainerPolicy().hasNext(valuesIterator)) { Object originalValue = getContainerPolicy().next(valuesIterator, policy.getSession()); Object copyValue = originalValue; if (policy.shouldCascadeAllParts() || (policy.shouldCascadePrivateParts() && isPrivateOwned())) { copyValue = policy.getSession().copyObject(originalValue, policy); } else { // Check for backrefs to copies. copyValue = policy.getCopies().get(originalValue); if (copyValue == null) { copyValue = originalValue; } } getContainerPolicy().addInto(copyValue, attributeValue, policy.getSession()); } setRealAttributeValueInObject(copy, attributeValue); }