/** * INTERNAL: * Return the referenceDescriptor. This is a descriptor which is associated with * the reference class. */ public ClassDescriptor getReferenceDescriptor() { if (referenceDescriptor == null) { if (getTempSession() == null) { return null; } else { referenceDescriptor = getTempSession().getDescriptor(getReferenceClass()); } } return referenceDescriptor; }
/** * INTERNAL: * Compare the attributes belonging to this mapping for the objects. */ public boolean compareObjects(Object firstObject, Object secondObject, AbstractSession session) { if (isPrivateOwned()) { return compareObjectsWithPrivateOwned(firstObject, secondObject, session); } else { return compareObjectsWithoutPrivateOwned(firstObject, secondObject, session); } }
/** * INTERNAL: * Convert all the class-name-based settings in this mapping to actual class-based * settings * This method is implemented by subclasses as necessary. * @param classLoader */ public void convertClassNamesToClasses(ClassLoader classLoader){ super.convertClassNamesToClasses(classLoader); containerPolicy.convertClassNamesToClasses(classLoader); };
/** * PUBLIC: * Indirection means that a ValueHolder 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. * @see #useBasicIndirection() * @see #dontUseIndirection() */ public void setUsesIndirection(boolean usesIndirection) { if (usesIndirection) { useBasicIndirection(); } else { dontUseIndirection(); } }
/** * 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); }
/** * Initialize and set the descriptor for the referenced class in this mapping. */ protected void initializeReferenceDescriptor(AbstractSession session) throws DescriptorException { if (getReferenceClass() == null) { throw DescriptorException.referenceClassNotSpecified(this); } ClassDescriptor refDescriptor = session.getDescriptor(getReferenceClass()); if (refDescriptor == null) { throw DescriptorException.descriptorIsMissing(getReferenceClass().getName(), this); } if (refDescriptor.isAggregateDescriptor() && (!isAggregateCollectionMapping())) { throw DescriptorException.referenceDescriptorCannotBeAggregate(this); } // can not be isolated if it is null. Seems that only aggregates do not set // the owning descriptor on the mapping. if ((!((this.getDescriptor() != null) && this.getDescriptor().isIsolated())) && refDescriptor.isIsolated()) { throw DescriptorException.isolateDescriptorReferencedBySharedDescriptor(refDescriptor.getJavaClassName(), this.getDescriptor().getJavaClassName(), this); } setReferenceDescriptor(refDescriptor); }
DatabaseMapping mapping = (DatabaseMapping)mappings.nextElement(); if (mapping.isForeignReferenceMapping()) { if (((ForeignReferenceMapping)mapping).hasConstraintDependency()) { Class ownedClass; ClassDescriptor refDescriptor = ((ForeignReferenceMapping)mapping).getReferenceDescriptor(); if (refDescriptor == null) { refDescriptor = session.getDescriptor(((ForeignReferenceMapping)mapping).getReferenceClass()); } else if (((ForeignReferenceMapping)mapping).hasInverseConstraintDependency()) { Class ownerClass; ClassDescriptor refDescriptor = ((ForeignReferenceMapping)mapping).getReferenceDescriptor(); if (refDescriptor == null) { refDescriptor = session.getDescriptor(((ForeignReferenceMapping)mapping).getReferenceClass());
/** * INTERNAL: * Indicates whether valueFromRow should call valueFromRowInternalWithJoin (true) * or valueFromRowInternal (false) */ protected boolean shouldUseValueFromRowWithJoin(JoinedAttributeManager joinManager) { return isJoiningSupported() && ( joinManager.isAttributeJoined(getDescriptor(), getAttributeName()) || joinManager.getBaseQuery().hasPartialAttributeExpressions()); // only true on OLRQ and above }
/** * This method will lazily initialize the set method * Lazy initialization occurs to that we are not required to have a handle on * the actual class that we are using until runtime. This helps to satisfy the * weaving requirement that demands that we avoid loading domain classes into * the main class loader until after weaving occurs. * @return */ protected Method getSetMethod(){ if (setMethod == null){ ForeignReferenceMapping sourceMapping = (ForeignReferenceMapping)mapping; // The parameter type for the set method must always be the return type of the get method. Class[] parameterTypes = new Class[1]; parameterTypes[0] = sourceMapping.getReferenceClass(); try { setMethod = Helper.getDeclaredMethod(sourceMapping.getDescriptor().getJavaClass(), setMethodName, parameterTypes); } catch (NoSuchMethodException e){ throw DescriptorException.errorAccessingSetMethodOfEntity(sourceMapping.getDescriptor().getJavaClass(), setMethodName ,sourceMapping.getDescriptor(), e); } } return setMethod; }
/** * INTERNAL: * The referenced object is checked if it is instantiated or not */ public boolean isAttributeValueInstantiated(Object object) { return getIndirectionPolicy().objectIsInstantiated(getAttributeValueFromObject(object)); }
/** * Sets the query */ protected void setSelectionQuery(ReadQuery aQuery) { selectionQuery = aQuery; // Make sure the reference class of the selectionQuery is set. if ((selectionQuery != null) && selectionQuery.isObjectLevelReadQuery() && (selectionQuery.getReferenceClassName() == null)) { ((ObjectLevelReadQuery)selectionQuery).setReferenceClass(getReferenceClass()); } }
/** * 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()); } }
/** * Helper method to retrieve the relationship partner mapping. This will take inheritance * into account and return the mapping associated with correct subclass if necessary. This * is needed for EJB 2.0 inheritance */ private ForeignReferenceMapping getRelationshipPartnerFor(Object partnerObject) { ForeignReferenceMapping partner = (ForeignReferenceMapping)getMapping().getRelationshipPartner(); if ((partner == null) || (partnerObject == null)) { // no partner, nothing to do return partner; } // if the target object is not an instance of the class type associated with the partner // mapping, try and look up the same partner mapping but as part of the partnerObject's // descriptor. Only check if inheritance is involved... if (partner.getDescriptor().hasInheritance()) { ClassDescriptor partnerObjectDescriptor = this.getSession().getDescriptor(partnerObject); if (!(partner.getDescriptor().getJavaClass().isAssignableFrom(partnerObjectDescriptor.getJavaClass()))) { return (ForeignReferenceMapping)partnerObjectDescriptor.getMappingForAttributeName(partner.getAttributeName()); } } return partner; } }
ObjectLevelReadQuery nestedQuery = (ObjectLevelReadQuery)((ObjectLevelReadQuery)getSelectionQuery()).deepClone(); nestedQuery.getJoinedAttributeManager().setJoinedAttributeExpressions_(extractNestedExpressions(joinManager.getJoinedAttributeExpressions(), nestedQuery.getExpressionBuilder(), false)); if (baseQuery.getLockingClause().isForUpdateOfClause()) { ForUpdateOfClause clause = (ForUpdateOfClause)baseQuery.getLockingClause().clone(); clause.setLockedExpressions(extractNestedExpressions(clause.getLockedExpressions(), nestedQuery.getExpressionBuilder(), true)); nestedQuery.setLockingClause(clause); } else {
/** * INTERNAL: * Compare the attributes belonging to this mapping for the objects. */ public boolean compareObjects(Object firstObject, Object secondObject, AbstractSession session) { Object firstObjectCollection = getRealCollectionAttributeValueFromObject(firstObject, session); Object secondObjectCollection = getRealCollectionAttributeValueFromObject(secondObject, session); return super.compareObjects(firstObjectCollection, secondObjectCollection, session); }
/** * 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 getAttributeValueWithClonedValueHolders(Object object) { Object attributeValue = getAttributeValueFromObject(object); if (attributeValue instanceof DatabaseValueHolder){ return ((DatabaseValueHolder)attributeValue).clone(); } else if (attributeValue instanceof ValueHolder){ return ((ValueHolder)attributeValue).clone(); } return attributeValue; }
/** * 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: * 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)); }
&& WeavedAttributeValueHolderInterface.class.isAssignableFrom(lType) && mapping instanceof ForeignReferenceMapping) { this.type = ForeignReferenceMapping.class.cast(mapping).getReferenceClass(); } else { this.type = lType; ForeignReferenceMapping fMapping = ForeignReferenceMapping.class .cast(mapping); elementType = fMapping.getReferenceClass();
/** * 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); }