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

BasicAccessor

public class BasicAccessor extends DirectAccessor
A relational accessor. A @Basic annotation may or may not be present on the accessible object.
author
Guy Pelletier
since
TopLink EJB 3.0 Reference Implementation

Fields Summary
private Basic
m_basic
Constructors Summary
public BasicAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor)
INTERNAL:

        super(accessibleObject, classAccessor);
        m_basic = getAnnotation(Basic.class);
    
Methods Summary
protected oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataColumngetColumn(java.lang.String loggingCtx)
INTERNAL: (Overridden in XMLBasicAccessor) Build a metadata column.

        Column column = getAnnotation(Column.class);
        return new MetadataColumn(column, this);
    
public java.lang.StringgetFetchType()
INTERNAL: (Overridden in XMLBasicAccessor)

        return (m_basic == null) ? MetadataConstants.EAGER : m_basic.fetch().name();
    
public booleanisBasic()
INTERNAL: (Override from MetadataAccessor)

     	return true;
     
public booleanisId()
INTERNAL: (Overridden in XMLBasicAccessor) Return true if this accessor represents an id field.

        return isAnnotationPresent(Id.class);
    
public booleanisOptional()
INTERNAL: (Overridden in XMLBasicAccessor)

        return (m_basic == null) ? true : m_basic.optional();
    
public booleanisVersion()
INTERNAL: (Overridden in XMLBasicAccessor) Return true if this accessor represents an optimistic locking field.

        return isAnnotationPresent(Version.class);
    
public voidprocess()
INTERNAL: Process a basic accessor.

    	// Process the @Column or column element if there is one.
        DatabaseField field = getDatabaseField(m_logger.COLUMN);
        
        // Make sure there is a table name on the field.
        if (field.getTableName().equals("")) {
            field.setTableName(m_descriptor.getPrimaryTableName());
        }
        
        // Process an @Version or version element if there is one.
        if (isVersion()) {
            if (m_descriptor.usesOptimisticLocking()) {
                // Ignore the version locking if it is already set.
                m_logger.logWarningMessage(m_logger.IGNORE_VERSION_LOCKING, this);
            } else {
                processVersion(field);
            }
        } else if (isId()) {
            // Process an @Id or id element.
            processId(field);
        }
                
        if (m_descriptor.hasMappingForAttributeName(getAttributeName())) {
            // Ignore the mapping if one already exists for it.
            m_logger.logWarningMessage(m_logger.IGNORE_MAPPING, this);
        } else {
            // Process a DirectToFieldMapping, that is a Basic that could
            // be used in conjunction with a Lob, Temporal, Enumerated
            // or inferred to be used with a serialized mapping.
            processDirectToFieldMapping(field);
        }
    
protected voidprocessDirectToFieldMapping(oracle.toplink.essentials.internal.helper.DatabaseField field)
INTERNAL: Process a Serialized or Basic into a DirectToFieldMapping. If neither is found a DirectToFieldMapping is created regardless.

        DirectToFieldMapping mapping = new DirectToFieldMapping();
        mapping.setField(field);
        mapping.setIsReadOnly(field.isReadOnly());
        mapping.setAttributeName(getAttributeName());
		mapping.setIsOptional(isOptional());
        
        if (usesIndirection()) {
            m_logger.logWarningMessage(m_logger.IGNORE_BASIC_FETCH_LAZY, this);
        }
        
        // Will check for PROPERTY access
        setAccessorMethods(mapping);
        
        // Process a converter for this mapping. We will look for a @Convert
        // first. If none is found then we'll look for a JPA converter, that 
        // is, @Enumerated, @Lob and @Temporal. With everything falling into 
        // a serialized mapping if no converter whatsoever is found.
        processMappingConverter(mapping);
        
        // Add the mapping to the descriptor.
        m_descriptor.addMapping(mapping);
    
protected voidprocessEnumerated(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: (Override from DirectAccessor) Process an @Enumerated. The method may still be called if no @Enumerated has been specified but the accessor's reference class is a valid enumerated type.

        // If the raw class is a collection or map (with generics or not), we 
        // don't want to put a TypeConversionConverter on the mapping. Instead, 
        // we will want a serialized converter. For example, we could have 
        // an EnumSet<Enum> relation type.
        if (MetadataHelper.isCollectionClass(getReferenceClass()) || MetadataHelper.isMapClass(getReferenceClass())) {
            processSerialized(mapping);
        } else {
            super.processEnumerated(mapping);
        }
    
protected voidprocessGeneratedValue(oracle.toplink.essentials.internal.helper.DatabaseField field)
INTERNAL: (Overridden In XMLBasicAccessor) Process a @GeneratedValue.

        GeneratedValue generatedValue = getAnnotation(GeneratedValue.class);
        
        if (generatedValue != null) {
            processGeneratedValue(new MetadataGeneratedValue(generatedValue), field);
        }
    
protected voidprocessGeneratedValue(oracle.toplink.essentials.internal.ejb.cmp3.metadata.sequencing.MetadataGeneratedValue generatedValue, oracle.toplink.essentials.internal.helper.DatabaseField sequenceNumberField)
INTERNAL:

        // Set the sequence number field on the descriptor.		
        DatabaseField existingSequenceNumberField = m_descriptor.getSequenceNumberField();
        
        if (existingSequenceNumberField == null) {
            m_descriptor.setSequenceNumberField(sequenceNumberField);
            getProject().addGeneratedValue(generatedValue, getJavaClass());
        } else {
            m_validator.throwOnlyOneGeneratedValueIsAllowed(getJavaClass(), existingSequenceNumberField.getQualifiedName(), sequenceNumberField.getQualifiedName());
        }
    
protected voidprocessId(oracle.toplink.essentials.internal.helper.DatabaseField field)
INTERNAL: Process an @Id or id element if there is one.

    	if (m_descriptor.ignoreIDs()) {
            // Project XML merging. XML wins, ignore annotations/orm xml.
            m_logger.logWarningMessage(m_logger.IGNORE_PRIMARY_KEY, this);
        } else {
            String attributeName = getAttributeName();
            
            if (m_descriptor.hasEmbeddedIdAttribute()) {
                // We found both an Id and an EmbeddedId, throw an exception.
                m_validator.throwEmbeddedIdAndIdFound(getJavaClass(), m_descriptor.getEmbeddedIdAttributeName(), attributeName);
            }
            
            // If this entity has a pk class, we need to validate our ids. 
            m_descriptor.validatePKClassId(attributeName, getReferenceClass());
        
            // Store the Id attribute name. Used with validation and OrderBy.
            m_descriptor.addIdAttributeName(attributeName);

            // Add the primary key field to the descriptor.            
            m_descriptor.addPrimaryKeyField(field);
	
            // Process the generated value for this id.
            processGeneratedValue(field);
            
            // Process a table generator.
            processTableGenerator();
            
            // Process a sequence generator.
            processSequenceGenerator();
        }
    
protected voidprocessLob(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: (Override from DirectAccessor) Process a @Lob or lob sub-element. The lob must be specified to process and create a lob type mapping.

        // If the raw class is a collection or map (with generics or not), we 
        // don't want to put a TypeConversionConverter on the mapping. Instead, 
        // we will want a serialized converter.
        if (MetadataHelper.isCollectionClass(getReferenceClass()) || MetadataHelper.isMapClass(getReferenceClass())) {
            setFieldClassification(mapping, java.sql.Blob.class);
            processSerialized(mapping);
        } else {
            super.processLob(mapping);
        }
    
protected voidprocessVersion(oracle.toplink.essentials.internal.helper.DatabaseField field)
INTERNAL:

        Class lockType = getRawClass();
        field.setType(lockType);
        
        if (MetadataHelper.isValidVersionLockingType(lockType)) {
            m_descriptor.useVersionLockingPolicy(field);
        } else if (MetadataHelper.isValidTimstampVersionLockingType(lockType)) {
            m_descriptor.useTimestampLockingPolicy(field);
        } else {
            m_validator.throwInvalidTypeForVersionAttribute(getJavaClass(), getAttributeName(), lockType);
        }
    
public voidsetConverter(oracle.toplink.essentials.mappings.DatabaseMapping mapping, oracle.toplink.essentials.mappings.converters.Converter converter)
INTERNAL:

        ((DirectToFieldMapping) mapping).setConverter(converter);
    
public voidsetFieldClassification(oracle.toplink.essentials.mappings.DatabaseMapping mapping, java.lang.Class classification)
INTERNAL:

        ((DirectToFieldMapping) mapping).setFieldClassification(classification);