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

OneToManyAccessor

public class OneToManyAccessor extends CollectionAccessor
A OneToMany relationship accessor. A @OneToMany annotation currently is not required to be on the accessible object, that is, a 1-M can default.
author
Guy Pelletier
since
TopLink EJB 3.0 Reference Implementation

Fields Summary
private OneToMany
m_oneToMany
Constructors Summary
public OneToManyAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor)
INTERNAL:

        super(accessibleObject, classAccessor);
        m_oneToMany = getAnnotation(OneToMany.class);
    
Methods Summary
public java.util.ListgetCascadeTypes()
INTERNAL: (Overridden in XMLOneToManyAccessor)

        if (m_oneToMany == null) {
            return new ArrayList<String>();
        } else {
            return getCascadeTypes(m_oneToMany.cascade());
        } 
    
public java.lang.StringgetFetchType()
INTERNAL: (Overridden in XMLOneToManyAccessor)

        return (m_oneToMany == null) ? MetadataConstants.LAZY : m_oneToMany.fetch().name();
    
protected java.lang.StringgetLoggingContext()
INTERNAL: Return the logging context for this accessor.

        return m_logger.ONE_TO_MANY_MAPPING_REFERENCE_CLASS;
    
public java.lang.StringgetMappedBy()
INTERNAL: (Overridden in XMLOneToManyAccessor)

        return (m_oneToMany == null) ? "" : m_oneToMany.mappedBy();
    
public java.lang.ClassgetTargetEntity()
INTERNAL: (Overridden in XMLOneToManyAccessor)

        return (m_oneToMany == null) ? void.class : m_oneToMany.targetEntity();
    
public booleanisOneToMany()
INTERNAL:

        return true;
    
public voidprocess()
INTERNAL: Process an @OneToMany or one-to-many element into a TopLink OneToMany mapping. If a JoinTable is found however, we must create a ManyToMany mapping.

        String mappedBy = getMappedBy();
        
        // Should be treated as a uni-directional mapping using a join table.
        if (mappedBy.equals("")) {
            // If we find a JoinColumn(s), then throw an exception.
            if (hasJoinColumn() || hasJoinColumns()) {
                getValidator().throwUniDirectionalOneToManyHasJoinColumnSpecified(getAttributeName(), getJavaClass());
            }
            
            // Create a M-M mapping and process common collection mapping
            // metadata.
            ManyToManyMapping mapping = new ManyToManyMapping();
            process(mapping);
            
            // Process the @JoinTable.
            processJoinTable(getJoinTable(), mapping);
            
            // Add the mapping to the descriptor.
            m_descriptor.addMapping(mapping);
        } else {
            // Create a 1-M mapping and process common collection mapping
            // metadata.
            OneToManyMapping mapping = new OneToManyMapping();
            process(mapping);
            
            // Non-owning side, process the foreign keys from the owner.
			OneToOneMapping ownerMapping = null;
            if (getOwningMapping().isOneToOneMapping()){ 
            	ownerMapping = (OneToOneMapping) getOwningMapping();
            } else {
				// If improper mapping encountered, throw an exception.
            	getValidator().throwInvalidMappingEncountered(getJavaClass(), getReferenceClass()); 
            }
                
            Map<DatabaseField, DatabaseField> keys = ownerMapping.getSourceToTargetKeyFields();
            for (DatabaseField fkField : keys.keySet()) {
                mapping.addTargetForeignKeyField(fkField, keys.get(fkField));
            }   
            
            // Add the mapping to the descriptor.
            m_descriptor.addMapping(mapping);
        }