/** * INTERNAL: * Indicates whether valueFromRow should call valueFromRowInternalWithJoin (true) * or valueFromRowInternal (false) */ protected boolean shouldUseValueFromRowWithJoin(JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery) { return ((joinManager != null) && (joinManager.isAttributeJoined(this.descriptor, getAttributeName()))) || sourceQuery.hasPartialAttributeExpressions(); }
/** * This method collects the Joined Mappings from the descriptor and initializes them. */ public void processJoinedMappings() { ObjectBuilder objectBuilder = getDescriptor().getObjectBuilder(); if (objectBuilder.hasJoinedAttributes()) { List mappingJoinedAttributes = objectBuilder.getJoinedAttributes(); if (!hasJoinedAttributeExpressions()) { for (int i = 0; i < mappingJoinedAttributes.size(); i++) { addJoinedMapping((ForeignReferenceMapping)mappingJoinedAttributes.get(i)); } } else { for (int i = 0; i < mappingJoinedAttributes.size(); i++) { ForeignReferenceMapping mapping = (ForeignReferenceMapping)mappingJoinedAttributes.get(i); if (!isAttributeExpressionJoined(mapping.getAttributeName())) { addJoinedMapping(mapping); } } } } }
for (int i = 0; i < mappingJoinedAttributes.size(); i++) { ForeignReferenceMapping mapping = (ForeignReferenceMapping) mappingJoinedAttributes.get(i); if(fetchGroupAttributes == null || fetchGroupAttributes.contains(mapping.getAttributeName())) { addAndPrepareJoinedMapping(mapping, session); ForeignReferenceMapping mapping = (ForeignReferenceMapping) mappingJoinedAttributes.get(i); if (!isAttributeExpressionJoined(mapping)) { if(fetchGroupAttributes == null || fetchGroupAttributes.contains(mapping.getAttributeName())) { addAndPrepareJoinedMapping(mapping, session);
/** * 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; }
/** * INTERNAL: * In cases where a relationship with detached or new entities is merged into itself previous changes may have been recorded for * the detached/new entity that need to be updated. */ public void updateListenerForSelfMerge(ObjectChangeListener listener, ForeignReferenceMapping mapping, Object source, Object target, UnitOfWorkImpl unitOfWork){ ChangeRecord record = (ChangeRecord) ((AttributeChangeListener)listener).getObjectChangeSet().getChangesForAttributeNamed(mapping.getAttributeName()); mapping.updateChangeRecordForSelfMerge(record, source, target, (UnitOfWorkChangeSet) ((AttributeChangeListener)listener).getObjectChangeSet().getUOWChangeSet(), unitOfWork); }
/** * 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; }
/** * INTERNAL: * In cases where a relationship with detached or new entities is merged into itself previous changes may have been recorded for * the detached/new entity that need to be updated. */ public void updateListenerForSelfMerge(ObjectChangeListener listener, ForeignReferenceMapping mapping, Object source, Object target, UnitOfWorkImpl unitOfWork){ ChangeRecord record = (ChangeRecord) ((AttributeChangeListener)listener).getObjectChangeSet().getChangesForAttributeNamed(mapping.getAttributeName()); mapping.updateChangeRecordForSelfMerge(record, source, target, (UnitOfWorkChangeSet) ((AttributeChangeListener)listener).getObjectChangeSet().getUOWChangeSet(), unitOfWork); }
/** * INTERNAL: * Initialize the state of mapping. */ public void preInitialize(AbstractSession session) throws DescriptorException { super.preInitialize(session); // If weaving was used the mapping must be configured to use the weaved get/set methods. if ((this.indirectionPolicy instanceof BasicIndirectionPolicy) && ClassConstants.PersistenceWeavedLazy_Class.isAssignableFrom(getDescriptor().getJavaClass())) { Class attributeType = getAttributeAccessor().getAttributeClass(); // Check that not already weaved or coded. if (!(ClassConstants.ValueHolderInterface_Class.isAssignableFrom(attributeType))) { boolean usesMethodAccess = getAttributeAccessor().isMethodAttributeAccessor(); String originalSetMethod = null; if (usesMethodAccess) { originalSetMethod = getSetMethodName(); } setGetMethodName(Helper.getWeavedValueHolderGetMethodName(getAttributeName())); setSetMethodName(Helper.getWeavedValueHolderSetMethodName(getAttributeName())); if (usesMethodAccess) { useWeavedIndirection(originalSetMethod); } // Must re-initialize the attribute accessor. super.preInitialize(session); } } }
/** * 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); } }
/** * 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.getObjectBuilder().getMappingForAttributeName(partner.getAttributeName()); } } return partner; } }
/** * 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.getObjectBuilder().getMappingForAttributeName(partner.getAttributeName()); } } return partner; } }
/** * 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); }
/** * INTERNAL: * Process the indirection (aka fetch type) */ protected void processIndirection(ForeignReferenceMapping mapping) { boolean usesIndirection = usesIndirection(); // Lazy is not disabled until descriptor initialization (OneToOneMapping preInitialize), // as it cannot be known if weaving occurred until then. String actualAttributeType = getAttributeType(); if (getAccessibleObject() != null){ actualAttributeType = getAccessibleObject().getType(); } if (usesIndirection && usesPropertyAccess()) { mapping.setIndirectionPolicy(new WeavedObjectBasicIndirectionPolicy(getGetMethodName(), getSetMethodName(), actualAttributeType, true)); } else if (usesIndirection && usesFieldAccess()) { mapping.setIndirectionPolicy(new WeavedObjectBasicIndirectionPolicy(Helper.getWeavedGetMethodName(mapping.getAttributeName()), Helper.getWeavedSetMethodName(mapping.getAttributeName()), actualAttributeType, false)); } else { mapping.setUsesIndirection(usesIndirection); } }
/** * 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.getObjectBuilder().getMappingForAttributeName(partner.getAttributeName()); } } return partner; } }
/** * Create a JAXB property for given reference mapping. */ private JAXBElement<XmlElement> createProperty(ForeignReferenceMapping mapping, ObjectFactory objectFactory) { final String referenceClassName = mapping.getReferenceClassName(); final XmlElement xmlElement = new XmlElement(); xmlElement.setJavaAttribute(mapping.getAttributeName()); xmlElement.setType(referenceClassName); final String adapterName = RestReferenceAdapterV2ClassWriter.getClassName(referenceClassName); final XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter(); adapter.setValue(adapterName); adapter.setType(referenceClassName); xmlElement.setXmlJavaTypeAdapter(adapter); return objectFactory.createXmlElement(xmlElement); }
/** * Create a JAXB property for given reference mapping. */ private JAXBElement<XmlElement> createProperty(ForeignReferenceMapping mapping, ObjectFactory objectFactory) { final String referenceClassName = mapping.getReferenceClassName(); final XmlElement xmlElement = new XmlElement(); xmlElement.setJavaAttribute(mapping.getAttributeName()); xmlElement.setType(referenceClassName); final String adapterName = RestReferenceAdapterV2ClassWriter.getClassName(referenceClassName); final XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter(); adapter.setValue(adapterName); adapter.setType(referenceClassName); xmlElement.setXmlJavaTypeAdapter(adapter); return objectFactory.createXmlElement(xmlElement); }
/** * 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()); } }
/** * 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()); } }
/** * INTERNAL: * To validate mappings declaration */ @Override public void validateBeforeInitialization(AbstractSession session) throws DescriptorException { super.validateBeforeInitialization(session); // If a lazy mapping required weaving for lazy, and weaving did not occur, // then the mapping must be reverted to no use indirection. if ((this.indirectionPolicy instanceof WeavedObjectBasicIndirectionPolicy) && !ClassConstants.PersistenceWeavedLazy_Class.isAssignableFrom(getDescriptor().getJavaClass())) { Object[] args = new Object[2]; args[0] = getAttributeName(); args[1] = getDescriptor().getJavaClass(); session.log(SessionLog.WARNING, SessionLog.METADATA, "metadata_warning_ignore_lazy", args); setIndirectionPolicy(new NoIndirectionPolicy()); } if (getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) { Class attributeType = ((InstanceVariableAttributeAccessor)getAttributeAccessor()).getAttributeType(); this.indirectionPolicy.validateDeclaredAttributeType(attributeType, session.getIntegrityChecker()); } else if (getAttributeAccessor().isMethodAttributeAccessor()) { // 323148 Class returnType = ((MethodAttributeAccessor)getAttributeAccessor()).getGetMethodReturnType(); this.indirectionPolicy.validateGetMethodReturnType(returnType, session.getIntegrityChecker()); Class parameterType = ((MethodAttributeAccessor)getAttributeAccessor()).getSetMethodParameterType(); this.indirectionPolicy.validateSetMethodParameterType(parameterType, session.getIntegrityChecker()); } }
/** * 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); } }