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

EmbeddedIdAccessor

public class EmbeddedIdAccessor extends EmbeddedAccessor
An embedded id relationship accessor.
author
Guy Pelletier
since
TopLink EJB 3.0 Reference Implementation

Fields Summary
protected HashMap
m_idFields
Constructors Summary
public EmbeddedIdAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor)
INTERNAL:


          
         
        super(accessibleObject, classAccessor);
    
Methods Summary
public booleanisEmbeddedId()
INTERNAL: (Override from MetadataAccesor)

        return true;
    
public voidprocess()
INTERNAL: (Override from EmbeddedAccessor) Process an @EmbeddedId or embedded-id element.

        if (m_descriptor.ignoreIDs()) {
            // XML/Annotation merging. XML wins, ignore annotations.
            m_logger.logWarningMessage(m_logger.IGNORE_EMBEDDED_ID, this);
        } else {
            // Check if we already processed an EmbeddedId for this entity.
            if (m_descriptor.hasEmbeddedIdAttribute()) {
                m_validator.throwMultipleEmbeddedIdsFound(getJavaClass(), getAttributeName(), m_descriptor.getEmbeddedIdAttributeName());
            } 
            
            // Check if we already processed an Id or IdClass.
            if (m_descriptor.hasPrimaryKeyFields()) {
                m_validator.throwEmbeddedIdAndIdFound(getJavaClass(), getAttributeName(), m_descriptor.getIdAttributeName());
            }
            
            // Set the PK class.
            m_descriptor.setPKClass(getReferenceClass());
            
            // Store the embeddedId attribute name.
            m_descriptor.setEmbeddedIdAttributeName(getAttributeName());
        }
        
        // Process the embeddable mapping specifics.
        super.process();
            
        // Add the fields from the embeddable as primary keys on the owning
        // metadata descriptor.
        for (DatabaseField field : m_idFields.values()) {
            m_descriptor.addPrimaryKeyField(field);
        }
    
protected voidprocessAttributeOverride(oracle.toplink.essentials.mappings.AggregateObjectMapping mapping, oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataColumn column)
INTERNAL: (Override from EmbeddedAccesor) Process an @AttributeOverride or attribute-override element for an embedded object, that is, an aggregate object mapping in TopLink.

        super.processAttributeOverride(mapping, column);
        
        // Update our primary key field with the attribute override field.
        // The super class with ensure the correct field is on the metadata
        // column.
        DatabaseField field = column.getDatabaseField();
        field.setTableName(m_descriptor.getPrimaryTableName());
        m_idFields.put(column.getAttributeName(), field);
	
protected oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptorprocessEmbeddableClass()
INTERNAL: (Override from EmbeddedAccesor) Process the embeddable class and gather up our 'original' collection of primary key fields. They are original because they may change with the specification of an attribute override.

        MetadataDescriptor embeddableDescriptor = super.processEmbeddableClass();
        
        // After processing the embeddable class, we need to gather our 
        // primary keys fields that we will eventually set on the owning 
        // descriptor metadata.
        if (isEmbeddedId() && ! m_descriptor.ignoreIDs()) {
            if (embeddableDescriptor.getMappings().isEmpty()) {
                String accessType = embeddableDescriptor.usesPropertyAccess() ? AccessType.PROPERTY.name() : AccessType.FIELD.name();
                m_validator.throwEmbeddedIdHasNoAttributes(m_descriptor.getJavaClass(), embeddableDescriptor.getJavaClass(), accessType);
            }

            for (DatabaseMapping mapping : embeddableDescriptor.getMappings()) {
                DatabaseField field = (DatabaseField) mapping.getField().clone();
                field.setTableName(m_descriptor.getPrimaryTableName());
                m_idFields.put(mapping.getAttributeName(), field);
            }
        }
        
        return embeddableDescriptor;