void synchronizeValueHolder(Object object) { try { ValueHolder valueHolder = (ValueHolder)valueHolderField.get(object); if(valueHolder != null){ Object value = field.get(object); valueHolder.setValue(value); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
/** * INTERNAL: * Return a backup clone of the attribute. */ public Object backupCloneAttribute(Object attributeValue, Object clone, Object backup, UnitOfWorkImpl unitOfWork) { //no need to check if the attribute is a valueholder because closeAttribute // should always be called first ValueHolderInterface valueHolder = (ValueHolderInterface)attributeValue;// cast the value ValueHolder result = new ValueHolder(); // delay instantiation until absolutely necessary if ((!(valueHolder instanceof UnitOfWorkValueHolder)) || valueHolder.isInstantiated()) { result.setValue(super.backupCloneAttribute(valueHolder.getValue(), clone, backup, unitOfWork)); } else { ((UnitOfWorkValueHolder)valueHolder).setBackupValueHolder(result); } return result; }
/** * Get the value from the wrapped value holder, instantiating it * if necessary, and clone it. */ protected Object instantiate() { UnitOfWorkImpl unitOfWork; if (isSerializedRemoteUnitOfWorkValueHolder()) { unitOfWork = getRemoteUnitOfWork(); } else { unitOfWork = getUnitOfWork(); } if (unitOfWork == null){ throw ValidationException.instantiatingValueholderWithNullSession(); } Object originalAttributeValue; Object cloneAttributeValue; // the wrapped value holder is transient, so it will be null for a remote UOW if (isSerializedRemoteUnitOfWorkValueHolder()) { originalAttributeValue = getValueFromServerObject(); cloneAttributeValue = buildCloneFor(originalAttributeValue); } else { cloneAttributeValue = instantiateImpl(); } // Set the value in the backup clone also. // In some cases we may want to force instantiation before the backup is built if (getBackupValueHolder() != null) { getBackupValueHolder().setValue(buildBackupCloneFor(cloneAttributeValue)); } return cloneAttributeValue; }