FileDocCategorySizeDatePackage
RelationshipAccessor.javaAPI DocGlassfish v2 API12543Tue May 22 16:54:26 BST 2007oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors

RelationshipAccessor

public abstract class RelationshipAccessor extends MetadataAccessor
An relational accessor.
author
Guy Pelletier
since
TopLink EJB 3.0 Reference Implementation

Fields Summary
protected Class
m_referenceClass
Constructors Summary
protected RelationshipAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor)
INTERNAL:

        super(accessibleObject, classAccessor);
    
Methods Summary
public abstract java.util.ListgetCascadeTypes()
INTERNAL: Return the cascade types for this accessor. This method is supported by all relational accessors.

public java.util.ArrayListgetCascadeTypes(javax.persistence.CascadeType[] cascadeTypes)
INTERNAL: WIP: Probably should make cascade types into its own object eventually.

        ArrayList<String> cTypes = new ArrayList<String>();
        
        for (CascadeType cascadeType : cascadeTypes) {
            cTypes.add(cascadeType.name());
		}
        
        return cTypes;
    
protected oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataJoinColumnsgetJoinColumns()
INTERNAL: (Overridden in XMLOneToOneAccessor, XMLManyToManyAccessor and XMLOneToManyAccessor) Process the @JoinColumns and @JoinColumn.

        JoinColumn joinColumn = getAnnotation(JoinColumn.class);
        JoinColumns joinColumns = getAnnotation(JoinColumns.class);
        
        return new MetadataJoinColumns(joinColumns, joinColumn);
    
protected abstract java.lang.StringgetLoggingContext()
INTERNAL: Return the logging context for this accessor.

public java.lang.StringgetMappedBy()
INTERNAL: Subclasses that support processing a mapped by should override this method, otherwise a runtime development exception is thrown for those accessors who call this method and don't implement it themselves.

        throw new RuntimeException("Development exception. The accessor: [" + this + "] should not call the getMappedBy method unless it overrides it.");
    
protected oracle.toplink.essentials.mappings.DatabaseMappinggetOwningMapping()
INTERNAL: Method to return an owner mapping. It will tell the owner class to process itself if it hasn't already done so.

        String ownerAttributeName = getMappedBy();
        MetadataDescriptor ownerDescriptor = getReferenceDescriptor();
        DatabaseMapping mapping = ownerDescriptor.getMappingForAttributeName(ownerAttributeName, this);
        
        // If no mapping was found, there is an error in the mappedBy field, 
        // therefore, throw an exception.
        if (mapping == null) {
            m_validator.throwNoMappedByAttributeFound(ownerDescriptor.getJavaClass(), ownerAttributeName, getJavaClass(), getAttributeName());
        }
        
        return mapping;
    
public oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptorgetReferenceDescriptor()
INTERNAL: Return the reference metadata descriptor for this accessor. This method does additional checks to make sure that the target entity is indeed an entity class.

        MetadataDescriptor descriptor;
       
        try {
            descriptor = super.getReferenceDescriptor();
        } catch (Exception exception) {
            descriptor = null;
        }
       
        if (descriptor == null || descriptor.isEmbeddable() || descriptor.isEmbeddableCollection()) {
            m_validator.throwNonEntityTargetInRelationship(getJavaClass(), getReferenceClass(), getAnnotatedElement());
        }
       
        return descriptor;
    
public abstract java.lang.ClassgetTargetEntity()
INTERNAL: Return the target entity for this accessor. This method is supported by all relational accessors.

public booleanhasJoinColumn()
INTERNAL: Method to check if an annotated element has a @JoinColumn.

		return isAnnotationPresent(JoinColumn.class);
    
public booleanhasJoinColumns()
INTERNAL: Method to check if an annotated element has a @JoinColumns.

		return isAnnotationPresent(JoinColumns.class);
    
public booleanhasPrimaryKeyJoinColumns()
INTERNAL: (Overridden in XMLOneToOneAccessor) Method to check if an annotated element has a @PrimaryKeyJoinColumns or at the very least a @PrimaryKeyJoinColumn.

		return isAnnotationPresent(PrimaryKeyJoinColumns.class) || isAnnotationPresent(PrimaryKeyJoinColumn.class);
    
public booleanisOneToOnePrimaryKeyRelationship()
INTERNAL: Return true if this accessor represents a 1-1 primary key relationship.

        return isOneToOne() && hasPrimaryKeyJoinColumns();
    
protected voidprocessCascadeTypes(oracle.toplink.essentials.mappings.ForeignReferenceMapping mapping)
INTERNAL:

        for (String cascadeType : getCascadeTypes()) {
			setCascadeType(cascadeType, mapping);
		}
        
        // Apply the persistence unit default cascade-persist if necessary.
        if (m_descriptor.isCascadePersist() && ! mapping.isCascadePersist()) {
        	setCascadeType(CascadeType.PERSIST.name(), mapping);
        }
    
protected java.util.ListprocessJoinColumns()
INTERNAL: Process a @JoinColumns or @JoinColumn. Will look for association overrides.

 
        if (m_descriptor.hasAssociationOverrideFor(getAttributeName())) {
            return processJoinColumns(m_descriptor.getAssociationOverrideFor(getAttributeName()), getReferenceDescriptor());
        } else {
            return processJoinColumns(getJoinColumns(), getReferenceDescriptor());
        }
    
protected java.util.ListprocessJoinColumns(oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataJoinColumns joinColumns, oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor descriptor)
INTERNAL: Process MetadataJoinColumns.

 
        // This call will add any defaulted columns as necessary.
        List<MetadataJoinColumn> jColumns = joinColumns.values(descriptor);
        
        if (descriptor.hasCompositePrimaryKey()) {
            // The number of join columns should equal the number of primary key fields.
            if (jColumns.size() != descriptor.getPrimaryKeyFields().size()) {
                m_validator.throwIncompleteJoinColumnsSpecified(getJavaClass(), getAnnotatedElement());
            }
            
            // All the primary and foreign key field names should be specified.
            for (MetadataJoinColumn jColumn : jColumns) {
                if (jColumn.isPrimaryKeyFieldNotSpecified() || jColumn.isForeignKeyFieldNotSpecified()) {
                    m_validator.throwIncompleteJoinColumnsSpecified(getJavaClass(), getAnnotatedElement());
                }
            }
        } else {
            if (jColumns.size() > 1) {
                m_validator.throwExcessiveJoinColumnsSpecified(getJavaClass(), getAnnotatedElement());
            }
        }
        
        return jColumns;
    
public voidprocessRelationship()
INTERNAL: Front end validation before actually processing the relationship accessor. The process() method should not be called directly.

        // The processing of this accessor may have been fast tracked through a 
        // non-owning relationship. If so, no processing is required.
        if (! isProcessed()) {
            if (m_descriptor.hasMappingForAttributeName(getAttributeName())) {
                // Only true if there is one that came from Project.xml
                m_logger.logWarningMessage(m_logger.IGNORE_MAPPING, this);
            } else {
                // If a @Column is specified then throw an exception.
                if (hasColumn()) {
                    m_validator.throwRelationshipHasColumnSpecified(getJavaClass(), getAttributeName());
                }
                
                // Process the relationship accessor only if the target entity
                // is not a ValueHolderInterface.
                if (getTargetEntity() == ValueHolderInterface.class || (getTargetEntity() == void.class && getReferenceClass() == ValueHolderInterface.class)) {
                    // do nothing ... I'm too lazy (or too stupid) to do the negation of this expression :-)
                } else { 
                    process();
                }
            }
            
            // Set its processing completed flag to avoid double processing.
            setIsProcessed();
        }
    
protected voidsetCascadeType(java.lang.String type, oracle.toplink.essentials.mappings.ForeignReferenceMapping mapping)
INTERNAL: Set the cascade type on a mapping.

        if (type.equals(MetadataConstants.CASCADE_ALL) || type.equals(CascadeType.ALL.name())) {
            mapping.setCascadeAll(true);
        } else if (type.equals(MetadataConstants.CASCADE_MERGE) || type.equals(CascadeType.MERGE.name())) {
            mapping.setCascadeMerge(true);
        } else if (type.equals(MetadataConstants.CASCADE_PERSIST) || type.equals(CascadeType.PERSIST.name())) {
            mapping.setCascadePersist(true);
        }  else if (type.equals(MetadataConstants.CASCADE_REFRESH) || type.equals(CascadeType.REFRESH.name())) {
            mapping.setCascadeRefresh(true);
        } else if (type.equals(MetadataConstants.CASCADE_REMOVE) || type.equals(CascadeType.REMOVE.name())) {
            mapping.setCascadeRemove(true);
        }