/** * 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: Return the value of the reference attribute or a value holder. * Check whether the mapping's attribute should be optimized through batch * and joining. */ public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) throws DatabaseException { // PERF: Direct variable access. // If the query uses batch reading, return a special value holder // or retrieve the object from the query property. if (sourceQuery.isReadAllQuery() && (((ReadAllQuery)sourceQuery).isAttributeBatchRead(this.descriptor, getAttributeName()) || this.usesBatchReading)) { return batchedValueFromRow(row, (ReadAllQuery)sourceQuery); } if (shouldUseValueFromRowWithJoin(joinManager, sourceQuery)) { return valueFromRowInternalWithJoin(row, joinManager, sourceQuery, executionSession); } else { return valueFromRowInternal(row, joinManager, sourceQuery, executionSession); } }
protected boolean shouldBuildDeleteStatementForMapping(ForeignReferenceMapping frMapping, boolean dontCheckDescriptor, ClassDescriptor descriptor) { return (dontCheckDescriptor || frMapping.getDescriptor().equals(descriptor)) && !(frMapping.isCascadeOnDeleteSetOnDatabase()); }
/** * INTERNAL: Compare the attributes belonging to this mapping for the * objects. */ @Override public boolean compareObjects(Object firstObject, Object secondObject, AbstractSession session) { if (isPrivateOwned()) { return compareObjectsWithPrivateOwned(firstObject, secondObject, session); } else { return compareObjectsWithoutPrivateOwned(firstObject, secondObject, session); } }
public Object getAttributeValueFromObject(Object object) { if (((ForeignReferenceMapping)object).hasCustomSelectionQuery()) { return ((ForeignReferenceMapping)object).getSelectionQuery(); } return null; }
/** * INTERNAL: * Return if the mapping has any ownership or other dependency over its target object(s). */ @Override public boolean hasDependency() { return isPrivateOwned() || isCascadeRemove(); }
protected void addForeignReferenceMappingLines(NonreflectiveMethodDefinition method, String mappingName, ForeignReferenceMapping mapping) { if (mapping.getReferenceClassName() != null) { method.addLine(mappingName + ".setReferenceClass(" + mapping.getReferenceClassName() + ".class);"); if (mapping.getRelationshipPartnerAttributeName() != null) { method.addLine(mappingName + ".setRelationshipPartnerAttributeName(\"" + mapping.getRelationshipPartnerAttributeName() + "\");"); IndirectionPolicy policy = mapping.getIndirectionPolicy(); if (policy instanceof ContainerIndirectionPolicy) { String containerClassName = ((ContainerIndirectionPolicy)policy).getContainerClassName(); if (mapping.shouldUseBatchReading()) { method.addLine(mappingName + ".useBatchReading();"); if (mapping.isJoinFetched()) { if (mapping.isInnerJoinFetched()) { method.addLine(mappingName + ".useInnerJoinFetch();"); } else if (mapping.isOuterJoinFetched()) { method.addLine(mappingName + ".useOuterJoinFetch();"); if ((!mapping.isDirectCollectionMapping()) && mapping.isPrivateOwned()) { method.addLine(mappingName + ".privateOwnedRelationship();"); if (mapping.isCollectionMapping()) { CollectionMapping collectionMapping = (CollectionMapping)mapping; String collectionClassName = collectionMapping.getContainerPolicy().getContainerClassName(); if (mapping.getContainerPolicy().isCollectionPolicy()) { if (policy instanceof TransparentIndirectionPolicy) { method.addLine(mappingName + ".useTransparentCollection();");
/** * 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); }
/** * A subclass should implement this method if it wants non default behavior. */ protected void initializeSelectionQuery(AbstractSession session) throws DescriptorException { if (((ObjectLevelReadQuery)getSelectionQuery()).getReferenceClass() == null) { throw DescriptorException.referenceClassNotSpecified(this); } getSelectionQuery().setName(getAttributeName()); getSelectionQuery().setDescriptor(getReferenceDescriptor()); getSelectionQuery().setSourceMapping(this); if (getSelectionQuery().getPartitioningPolicy() == null) { getSelectionQuery().setPartitioningPolicy(getPartitioningPolicy()); } }
if (getReferenceClassName() != null) { Class referenceClass = null; try{ if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { referenceClass = AccessController.doPrivileged(new PrivilegedClassForName(getReferenceClassName(), true, classLoader)); } catch (PrivilegedActionException exception) { throw ValidationException.classNotFoundWhileConvertingClassNames(getReferenceClassName(), exception.getException()); referenceClass = PrivilegedAccessHelper.getClassForName(getReferenceClassName(), true, classLoader); throw ValidationException.classNotFoundWhileConvertingClassNames(getReferenceClassName(), exc); setReferenceClass(referenceClass); if (getSelectionQuery() != null) { getSelectionQuery().convertClassNamesToClasses(classLoader);
/** * 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. setReferenceDescriptor(refDescriptor); }
@Override public Class<?> getAttributeClass() { if (mapping.isForeignReferenceMapping()) { ForeignReferenceMapping refMapping = (ForeignReferenceMapping)mapping; if (refMapping.isCollectionMapping()) { return ((CollectionMapping)refMapping).getContainerPolicy().getContainerClass(); } if (refMapping.usesIndirection()) { return ValueHolderInterface.class; } return refMapping.getReferenceClass(); } else { if (mapping.getAttributeClassification() == null) { return ClassConstants.OBJECT; } return mapping.getAttributeClassification(); } } }
/** * INTERNAL: * Return the relationshipPartner mapping for this bi-directional mapping. If the relationshipPartner is null then * this is a uni-directional mapping. */ @Override public DatabaseMapping getRelationshipPartner() { if ((this.relationshipPartner == null) && (this.relationshipPartnerAttributeName != null)) { setRelationshipPartner(getReferenceDescriptor().getObjectBuilder().getMappingForAttributeName(getRelationshipPartnerAttributeName())); } return this.relationshipPartner; }
/** * A subclass should implement this method if it wants non default behavior. */ protected void initializeSelectionQuery(AbstractSession session) throws DescriptorException { if (((ObjectLevelReadQuery)getSelectionQuery()).getReferenceClass() == null) { throw DescriptorException.referenceClassNotSpecified(this); } getSelectionQuery().setName(getAttributeName()); getSelectionQuery().setDescriptor(getReferenceDescriptor()); getSelectionQuery().setSourceMapping(this); }
/** * Add the mapping for join fetch, prepare and return the join expression being used. */ public Expression addAndPrepareJoinedMapping(ForeignReferenceMapping mapping, AbstractSession session) { Expression joinMappingExpression = null; if (mapping.isCollectionMapping()) { if (mapping.isInnerJoinFetched()) { joinMappingExpression = getBaseExpressionBuilder().anyOf(mapping.getAttributeName(), false); } else if (mapping.isOuterJoinFetched()) { joinMappingExpression = getBaseExpressionBuilder().anyOfAllowingNone(mapping.getAttributeName(), false); } } else { if (mapping.isInnerJoinFetched()) { joinMappingExpression = getBaseExpressionBuilder().get(mapping.getAttributeName()); } else if (mapping.isOuterJoinFetched()) { joinMappingExpression = getBaseExpressionBuilder().getAllowingNull(mapping.getAttributeName()); } } if (joinMappingExpression != null) { joinMappingExpression = prepareJoinExpression(joinMappingExpression, session); addJoinedMappingExpression(joinMappingExpression); } return joinMappingExpression; }
@Override public Object getAttributeValueFromObject(Object object) { IndirectionPolicy policy = ((ForeignReferenceMapping)object).getIndirectionPolicy(); if (policy instanceof NoIndirectionPolicy) { return null; } return policy; }
/** * PUBLIC: * Set the referenced class. */ public void setReferenceClass(Class referenceClass) { this.referenceClass = referenceClass; if (referenceClass != null) { setReferenceClassName(referenceClass.getName()); // Make sure the reference class of the selectionQuery is set. setSelectionQuery(getSelectionQuery()); } }
/** * INTERNAL: * Returns true if the merge should cascade to the mappings reference's parts. */ public boolean shouldMergeCascadeParts(MergeManager mergeManager) { return (mergeManager.shouldCascadeByMapping() && ((this.isCascadeMerge() && !mergeManager.isForRefresh()) || (this.isCascadeRefresh() && mergeManager.isForRefresh()) )) || mergeManager.shouldCascadeAllParts() || (mergeManager.shouldCascadePrivateParts() && isPrivateOwned()); }
/** * Build an XMLInverseMapping based on a particular mapping and replace that mapping with * the newly created XMLInverseMapping in jaxbDescriptor * @param jaxbDescriptor * @param mapping * @param mappedBy */ private static void convertMappingToXMLInverseReferenceMapping(ClassDescriptor jaxbDescriptor, DatabaseMapping mapping, ForeignReferenceMapping jpaMapping) { if ((mapping != null) && (jaxbDescriptor != null)) { if (!(mapping.isXMLMapping())) { return; } if ((jpaMapping.isAggregateCollectionMapping()) || (jpaMapping.isAggregateMapping())) { return; } XMLInverseReferenceMapping jaxbInverseMapping = new XMLInverseReferenceMapping(); copyAccessorToMapping(mapping, jaxbInverseMapping); jaxbInverseMapping.setProperties(mapping.getProperties()); jaxbInverseMapping.setIsReadOnly(mapping.isReadOnly()); jaxbInverseMapping.setMappedBy(jpaMapping.getAttributeName()); if (mapping.isAbstractCompositeCollectionMapping()) { jaxbInverseMapping.setContainerPolicy(mapping.getContainerPolicy()); jaxbInverseMapping.setReferenceClass(((XMLCompositeCollectionMapping) mapping).getReferenceClass()); } else if (mapping.isAbstractCompositeObjectMapping()) { jaxbInverseMapping.setReferenceClass(((XMLCompositeObjectMapping) mapping).getReferenceClass()); } jaxbDescriptor.removeMappingForAttributeName(mapping.getAttributeName()); jaxbDescriptor.addMapping(jaxbInverseMapping); } }
if (mapping instanceof ForeignReferenceMapping) { final ForeignReferenceMapping fkMapping = (ForeignReferenceMapping) mapping; if ((fkMapping.isCascadePersist()) || (fkMapping.isCascadeMerge())) { final ClassDescriptor referenceDescriptor = fkMapping.getReferenceDescriptor(); if (referenceDescriptor != null) { if (referenceDescriptor instanceof RelationalDescriptor) {