/** * PUBLIC: * Indirection means that some sort of indirection object will be put in-between the attribute and the real object. * This allows for the reading of the target from the database to be delayed until accessed. * This defaults to true and is strongly suggested as it give a huge performance gain. */ public boolean usesIndirection() { return getIndirectionPolicy().usesIndirection(); }
/** * INTERNAL: * Set the value of the attribute mapped by this mapping, * placing it inside a value holder if necessary. * If the value holder is not instantiated then it is instantiated. */ public void setRealAttributeValueInObject(Object object, Object value) throws DescriptorException { this.getIndirectionPolicy().setRealAttributeValueInObject(object, value); }
/** * INTERNAL: * Returns the attribute value from the reference object. * If the attribute is using indirection the value of the value-holder is returned. * If the value holder is not instantiated then it is instantiated. */ public Object getRealAttributeValueFromObject(Object object, AbstractSession session) { return getIndirectionPolicy().getRealAttributeValueFromObject(object, getAttributeValueFromObject(object)); }
/** * INTERNAL: * The referenced object is checked if it is instantiated or not */ public boolean isAttributeValueInstantiated(Object object) { return getIndirectionPolicy().objectIsInstantiated(getAttributeValueFromObject(object)); }
/** * INTERNAL: * Clone the attribute from the original and assign it to the clone. */ public void buildClone(Object original, Object clone, UnitOfWorkImpl unitOfWork) { Object attributeValue = getAttributeValueFromObject(original); Object clonedAttributeValue = getIndirectionPolicy().cloneAttribute(attributeValue, original, clone, unitOfWork, false); // building clone from an original not a row. //GFBug#404 - fix moved to ObjectBuildingQuery.registerIndividualResult setAttributeValueInObject(clone, clonedAttributeValue); }
/** * INTERNAL: * Iterate on the iterator's current object's attribute defined by this mapping. * The iterator's settings for cascading and value holders determine how the * iteration continues from here. */ public void iterate(DescriptorIterator iterator) { Object attributeValue = this.getAttributeValueFromObject(iterator.getVisitedParent()); this.getIndirectionPolicy().iterateOnAttributeValue(iterator, attributeValue); }
/** * INTERNAL: * Clone the attribute from the clone and assign it to the backup. */ public void buildBackupClone(Object clone, Object backup, UnitOfWorkImpl unitOfWork) { Object attributeValue = getAttributeValueFromObject(clone); Object clonedAttributeValue = getIndirectionPolicy().backupCloneAttribute(attributeValue, clone, backup, unitOfWork); setAttributeValueInObject(backup, clonedAttributeValue); }
/** * INTERNAL: * Return the value of an attribute which this mapping represents for an object. */ public Object getAttributeValueFromObject(Object object) throws DescriptorException { Object attributeValue = super.getAttributeValueFromObject(object); Object indirectionValue = getIndirectionPolicy().validateAttributeOfInstantiatedObject(attributeValue); // PERF: Allow the indirection policy to initialize null attribute values, // this allows the indirection objects to not be initialized in the constructor. if (indirectionValue != attributeValue) { setAttributeValueInObject(object, indirectionValue); attributeValue = indirectionValue; } return attributeValue; }
/** * INTERNAL: * Initialize the state of mapping. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); initializeReferenceDescriptor(session); initializeSelectionQuery(session); getIndirectionPolicy().initialize(); }
/** * INTERNAL: * A combination of readFromRowIntoObject and buildClone. * <p> * buildClone assumes the attribute value exists on the original and can * simply be copied. * <p> * readFromRowIntoObject assumes that one is building an original. * <p> * Both of the above assumptions are false in this method, and actually * attempts to do both at the same time. * <p> * Extract value from the row and set the attribute to this value in the * working copy clone. * In order to bypass the shared cache when in transaction a UnitOfWork must * be able to populate working copies directly from the row. */ public void buildCloneFromRow(AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object clone, ObjectBuildingQuery sourceQuery, UnitOfWorkImpl unitOfWork, AbstractSession executionSession) { Object attributeValue = valueFromRow(databaseRow, joinManager, sourceQuery, executionSession); Object clonedAttributeValue = getIndirectionPolicy().cloneAttribute(attributeValue, null,// no original clone, unitOfWork, true);// building clone directly from row. setAttributeValueInObject(clone, clonedAttributeValue); }
/** * INTERNAL: * To validate mappings decleration */ public void validateBeforeInitialization(AbstractSession session) throws DescriptorException { super.validateBeforeInitialization(session); if (getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) { Class attributeType = ((InstanceVariableAttributeAccessor)getAttributeAccessor()).getAttributeType(); getIndirectionPolicy().validateDeclaredAttributeType(attributeType, session.getIntegrityChecker()); } else if (getAttributeAccessor() instanceof MethodAttributeAccessor) { Class returnType = ((MethodAttributeAccessor)getAttributeAccessor()).getGetMethodReturnType(); getIndirectionPolicy().validateGetMethodReturnType(returnType, session.getIntegrityChecker()); Class parameterType = ((MethodAttributeAccessor)getAttributeAccessor()).getSetMethodParameterType(); getIndirectionPolicy().validateSetMethodParameterType(parameterType, session.getIntegrityChecker()); } }
ForeignReferenceMapping refMapping = (ForeignReferenceMapping)baseMapping; if (refMapping.usesIndirection()) { allAttributesNull = refMapping.getIndirectionPolicy().objectIsInstantiated(baseValue);
Object attributeValue = mapping.getRealAttributeValueFromObject(clone, unitOfWork); if (attributeValue != null){ if ( mapping.isForeignReferenceMapping() && (((ForeignReferenceMapping)mapping).getIndirectionPolicy().usesTransparentIndirection()) ) { ((IndirectContainer)attributeValue).getValueHolder().getValue();
if (!((ForeignReferenceMapping)mapping).getIndirectionPolicy().objectIsInstantiated(valueFromMapping)) { if (!valueHolderPolicy.shouldTriggerIndirection()) {
if (!((attributeValue != null) && dm.isForeignReferenceMapping() && ((ForeignReferenceMapping)dm).usesIndirection() && ((ForeignReferenceMapping)dm).getIndirectionPolicy().objectIsInstantiated(attributeValue))) { dm.readFromRowIntoObject(databaseRow, joinManager, domainObject, query, query.getSession().getExecutionSession(query));