FileDocCategorySizeDatePackage
ManyToManyAccessor.javaAPI DocGlassfish v2 API5812Thu May 31 10:59:18 BST 2007oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors

ManyToManyAccessor

public class ManyToManyAccessor extends CollectionAccessor
A many to many relationship accessor.
author
Guy Pelletier
since
TopLink EJB 3.0 Reference Implementation

Fields Summary
private ManyToMany
m_manyToMany
Constructors Summary
public ManyToManyAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor)
INTERNAL:

        super(accessibleObject, classAccessor);
        m_manyToMany = getAnnotation(ManyToMany.class);
    
Methods Summary
public java.util.ListgetCascadeTypes()
INTERNAL: (Overridden in XMLManyToManyAccessor)

        return getCascadeTypes(m_manyToMany.cascade());
    
public java.lang.StringgetFetchType()
INTERNAL: (Overridden in XMLManyToManyAccessor)

        return m_manyToMany.fetch().name();
    
protected java.lang.StringgetLoggingContext()
INTERNAL: Return the logging context for this accessor.

        return m_logger.MANY_TO_MANY_MAPPING_REFERENCE_CLASS;
    
public java.lang.StringgetMappedBy()
INTERNAL: (Overridden in XMLManyToManyAccessor)

        return m_manyToMany.mappedBy();
    
public java.lang.ClassgetTargetEntity()
INTERNAL: (Overridden in XMLManyToManyAccessor)

        return m_manyToMany.targetEntity();
    
public booleanisManyToMany()
INTERNAL:

        return true;
    
public voidprocess()
INTERNAL: Process a @ManyToMany or many-to-many element into a TopLink MnayToMany mapping.

        // Create a M-M mapping and process common collection mapping metadata.
        ManyToManyMapping mapping = new ManyToManyMapping();
        process(mapping);

        if (getMappedBy().equals("")) { 
            // Processing the owning side of a M-M that is process a join table.
            processJoinTable(getJoinTable(), mapping);
        } else {
            // We are processing the a non-owning side of a M-M. Must set the
            // mapping read-only.
            mapping.setIsReadOnly(true);
            
            // Get the owning mapping from the reference descriptor metadata.
            ManyToManyMapping ownerMapping = null;
            if (getOwningMapping().isManyToManyMapping()){
            	ownerMapping = (ManyToManyMapping)getOwningMapping();
            } else {
            	// If improper mapping encountered, throw an exception.
            	getValidator().throwInvalidMappingEncountered(getJavaClass(), getReferenceClass());
            }

            // Set the relation table name from the owner.
	        mapping.setRelationTableName(ownerMapping.getRelationTableQualifiedName());
	             
	        // Add all the source foreign keys we found on the owner.
	        mapping.setSourceKeyFields(ownerMapping.getTargetKeyFields());
	        mapping.setSourceRelationKeyFields(ownerMapping.getTargetRelationKeyFields());
	            
	        // Add all the target foreign keys we found on the owner.
	        mapping.setTargetKeyFields(ownerMapping.getSourceKeyFields());
	        mapping.setTargetRelationKeyFields(ownerMapping.getSourceRelationKeyFields());
        }

        // Add the mapping to the descriptor.
        m_descriptor.addMapping(mapping);