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

ObjectAccessor

public abstract class ObjectAccessor extends RelationshipAccessor
A single object relationship accessor.
author
Guy Pelletier
since
TopLink EJB 3.0 Reference Implementation

Fields Summary
Constructors Summary
protected ObjectAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor)

        super(accessibleObject, classAccessor);
    
Methods Summary
public java.lang.ClassgetReferenceClass()
INTERNAL: (Override from MetadataAccessor) If a target entity is specified in metadata, it will be set as the reference class, otherwise we will use the raw class.

        if (m_referenceClass == null) {
            m_referenceClass = getTargetEntity();
        
            if (m_referenceClass == void.class) {
                // Get the reference class from the accessible object and
                // log the defaulting contextual reference class.
                m_referenceClass = super.getReferenceClass();
                m_logger.logConfigMessage(getLoggingContext(), getAnnotatedElement(), m_referenceClass);
            } 
        }
        
        return m_referenceClass;
    
protected oracle.toplink.essentials.mappings.OneToOneMappinginitOneToOneMapping()
INTERNAL: Initialize a OneToOneMapping.

    	OneToOneMapping mapping = new OneToOneMapping();
        mapping.setIsReadOnly(false);
        mapping.setIsPrivateOwned(false);
        mapping.setIsOptional(isOptional());
        mapping.setAttributeName(getAttributeName());
        mapping.setReferenceClassName(getReferenceClassName());
        
        // If the global weave for value holders is true, the use the value
        // from usesIndirection. Otherwise, force it to false.
        boolean usesIndirection = (m_project.enableLazyForOneToOne()) ? usesIndirection() : false;
        if (usesIndirection && m_descriptor.usesPropertyAccess()) {
            mapping.setIndirectionPolicy(new WeavedObjectBasicIndirectionPolicy(getSetMethodName()));
        } else {
            mapping.setUsesIndirection(usesIndirection);
        }
        
        // Set the getter and setter methods if access is PROPERTY.
        setAccessorMethods(mapping);
        
        // Process the cascade types.
        processCascadeTypes(mapping);
        
        return mapping;
    
protected voidprocessOneToOneForeignKeyRelationship(oracle.toplink.essentials.mappings.OneToOneMapping mapping)
INTERNAL: Process the @JoinColumn(s) for the owning side of a one to one mapping. The default pk and pk field names are used only with single primary key entities. The processor should never get as far as to use them with entities that have a composite primary key (validation exception will be thrown).

         
        // If the pk field (referencedColumnName) is not specified, it 
        // defaults to the primary key of the referenced table.
        String defaultPKFieldName = getReferenceDescriptor().getPrimaryKeyFieldName();
        
        // If the fk field (name) is not specified, it defaults to the 
        // concatenation of the following: the name of the referencing 
        // relationship property or field of the referencing entity; "_"; 
        // the name of the referenced primary key column.
        String defaultFKFieldName = getUpperCaseAttributeName() + "_" + defaultPKFieldName;
            
        // Join columns will come from a @JoinColumn(s).
        List<MetadataJoinColumn> joinColumns = processJoinColumns();

        // Add the source foreign key fields to the mapping.
        for (MetadataJoinColumn joinColumn : joinColumns) {
            DatabaseField pkField = joinColumn.getPrimaryKeyField();
            pkField.setName(getName(pkField, defaultPKFieldName, MetadataLogger.PK_COLUMN));
            pkField.setTableName(getReferenceDescriptor().getPrimaryKeyTableName());
            
            DatabaseField fkField = joinColumn.getForeignKeyField();
            fkField.setName(getName(fkField, defaultFKFieldName, MetadataLogger.FK_COLUMN));
            // Set the table name if one is not already set.
            if (fkField.getTableName().equals("")) {
                fkField.setTableName(m_descriptor.getPrimaryTableName());
            }
            
            // Add a source foreign key to the mapping.
            mapping.addForeignKeyField(fkField, pkField);
            
            // If any of the join columns is marked read-only then set the 
            // mapping to be read only.
            if (fkField.isReadOnly()) {
                mapping.setIsReadOnly(true);
            }
        }
    
protected voidprocessOneToOnePrimaryKeyRelationship(oracle.toplink.essentials.mappings.OneToOneMapping mapping)
INTERNAL: Process the primary key join columns for the owning side of a one to one mapping. The default pk and pk field names are used only with single primary key entities. The processor should never get as far as to use them with entities that have a composite primary key (validation exception will be thrown).

        // Join columns will come from a @PrimaryKeyJoinColumn(s).
        MetadataDescriptor referenceDescriptor = getReferenceDescriptor();
        List<MetadataPrimaryKeyJoinColumn> primaryKeyJoinColumns = processPrimaryKeyJoinColumns(getPrimaryKeyJoinColumns(referenceDescriptor.getPrimaryTableName(), m_descriptor.getPrimaryTableName()));

        // Add the source foreign key fields to the mapping.
        for (MetadataPrimaryKeyJoinColumn primaryKeyJoinColumn : primaryKeyJoinColumns) {
            // The default primary key name is the primary key field name of the
            // referenced entity.
            DatabaseField pkField = primaryKeyJoinColumn.getPrimaryKeyField();
            pkField.setName(getName(pkField, referenceDescriptor.getPrimaryKeyFieldName(), m_logger.PK_COLUMN));
            
            // The default foreign key name is the primary key of the
            // referencing entity.
            DatabaseField fkField = primaryKeyJoinColumn.getForeignKeyField();
            fkField.setName(getName(fkField, m_descriptor.getPrimaryKeyFieldName(), m_logger.FK_COLUMN));
            
            // Add a source foreign key to the mapping.
            mapping.addForeignKeyField(fkField, pkField);
            
            // Mark the mapping read only
            mapping.setIsReadOnly(true);
        }
    
protected voidprocessOwningMappingKeys(oracle.toplink.essentials.mappings.OneToOneMapping mapping)
INTERNAL: Process the the correct metadata join column for the owning side of a one to one mapping.

        if (isOneToOnePrimaryKeyRelationship()) {
            processOneToOnePrimaryKeyRelationship(mapping);
        } else {
            processOneToOneForeignKeyRelationship(mapping);
        }