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

DirectAccessor

public abstract class DirectAccessor extends NonRelationshipAccessor
A direct accessor. Subclasses: BasicAccessor, XMLBasicAccessor, BasicCollectionAccessor, BasicMapAccessor.
author
Guy Pelletier
since
TopLink 11g

Fields Summary
Constructors Summary
public DirectAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor)
INTERNAL:

        super(accessibleObject, classAccessor);
    
Methods Summary
protected abstract oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataColumngetColumn(java.lang.String loggingCtx)
INTERNAL: This is used to return the column for a BasicAccessor. In the case of a BasicCollectionAccessor or BasicMapAccessor, this method should return the value column. See BasicMapAccessor for processing on the key column.

public oracle.toplink.essentials.internal.helper.DatabaseFieldgetDatabaseField(java.lang.String loggingCtx)
INTERNAL: Process column details from an @Column or column element into a MetadataColumn and return it. This will set correct metadata and log defaulting messages to the user. It also looks for attribute overrides. This method will call getColumn() which assumes the subclasses will return the appropriate MetadataColumn to process based on the context provided.

See
BasicCollectionAccessor and BasicMapAccessor.

        // Check if we have an attribute override first, otherwise process for 
        // a column (ignoring if for a key column on a basic map)
        MetadataColumn column;
        if (m_descriptor.hasAttributeOverrideFor(getAttributeName())) {
            column = m_descriptor.getAttributeOverrideFor(getAttributeName());
        } else {
            column = getColumn(loggingCtx);
        }
        
        // Get the actual database field and apply any defaults.
        DatabaseField field = column.getDatabaseField();
        
        // Set the correct field name, defaulting and logging when necessary.
        String defaultName = column.getUpperCaseAttributeName();
        field.setName(getName(field.getName(), defaultName, loggingCtx));
                    
        return field;
    
public java.lang.StringgetEnumeratedType()
INTERNAL: (Overridden in XMLBasicAccessor)

        Enumerated enumerated = getAnnotation(Enumerated.class);
        
        if (enumerated == null) {
            return EnumType.ORDINAL.name();
        } else {
            return enumerated.value().name();
        }
     
public java.lang.StringgetTemporalType()
INTERNAL: Return the temporal type for this accessor. Assumes there is a @Temporal.

        Temporal temporal = getAnnotation(Temporal.class);
        return temporal.value().name();
    
public booleanhasEnumerated()
INTERNAL: (Overridden in XMLBasicAccessor) Return true if this accessor has a @Enumerated.

		return isAnnotationPresent(Enumerated.class);
    
public booleanhasLob()
INTERNAL: (Overridden in XMLBasicAccessor) Return true if this accessor has a @Lob.

		return isAnnotationPresent(Lob.class);
    
public booleanhasTemporal()
INTERNAL: (Overridden in XMLBasicAccessor) Return true if this accessor has a @Temporal.

        return isAnnotationPresent(Temporal.class);
    
public booleanisEnumerated()
INTERNAL: Return true if this represents an enum type mapping. Will return true if the accessor's reference class is an enum or if a @Enumerated exists.

        return hasEnumerated() || MetadataHelper.isValidEnumeratedType(getReferenceClass());
    
public booleanisLob()
INTERNAL: Return true if this accessor represents a BLOB/CLOB mapping.

        return hasLob();
    
public booleanisSerialized()
INTERNAL: Return true if this accessor represents a serialized mapping.

        return MetadataHelper.isValidSerializedType(getReferenceClass());
    
public booleanisTemporal()
INTERNAL: (Overridden in BasicMapAccessor) Return true if this represents a temporal type mapping. Will return true if the accessor's reference class is a temporal type or if a @Temporal exists.

        return hasTemporal() || MetadataHelper.isValidTemporalType(getReferenceClass());
    
protected voidprocessEnumerated(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: (Overridden in BasicAccessor and BasicMapAccessor) 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 this accessor is tagged as an enumerated type, validate the
        // reference class.
        if (hasEnumerated()) {
            if (! MetadataHelper.isValidEnumeratedType(getReferenceClass())) {
                m_validator.throwInvalidTypeForEnumeratedAttribute(getJavaClass(), mapping.getAttributeName(), getReferenceClass());
            }
        }
        
        // Create an EnumTypeConverter and set it on the mapping.
        setConverter(mapping, new EnumTypeConverter(mapping, getReferenceClass(), getEnumeratedType().equals(EnumType.ORDINAL.name())));
    
protected voidprocessJPAConverters(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: Process an @Enumerated, @Lob or @Temporal annotation. Will default a serialized converter if necessary.

        // Check for an enum first since it will fall into a serializable 
        // mapping otherwise (Enums are serialized)
        if (isEnumerated()) {
            processEnumerated(mapping);
        } else if (isLob()) {
            processLob(mapping);
        } else if (isTemporal()) {
            processTemporal(mapping);
            //gf 1637: converter for Temporal returns false for isMutable, needs to be overriden
            ((AbstractDirectMapping)mapping).setIsMutable(true);
        } else if (isSerialized()) {
            processSerialized(mapping);
        } else if (MetadataHelper.isValidDateType(this.getReferenceClass())){
            //gf 1637: override directmapping ismutable 
            ((AbstractDirectMapping)mapping).setIsMutable(true);
        }
    
protected voidprocessLob(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: (Overridden in BasicAccessor) Process a @Lob or lob sub-element. The lob must be specified to process and create a lob type mapping.

        // Set the field classification type on the mapping based on the
        // referenceClass type.
        if (MetadataHelper.isValidClobType(getReferenceClass())) {
            setFieldClassification(mapping, java.sql.Clob.class);   
            setConverter(mapping, new TypeConversionConverter(mapping));
        } else if (MetadataHelper.isValidBlobType(getReferenceClass())) {
            setFieldClassification(mapping, java.sql.Blob.class);
            setConverter(mapping, new TypeConversionConverter(mapping));
        } else if (Helper.classImplementsInterface(getReferenceClass(), Serializable.class)) {
            setFieldClassification(mapping, java.sql.Blob.class);
            setConverter(mapping, new SerializedObjectConverter(mapping));
        } else {
            // The referenceClass is neither a valid BLOB or CLOB attribute.   
            m_validator.throwInvalidTypeForLOBAttribute(getJavaClass(), mapping.getAttributeName(), getReferenceClass());
        }
    
protected voidprocessMappingConverter(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: Process a converter for the given mapping. Will look for a converter name from a @Convert specified on this accessor.

        processJPAConverters(mapping);
    
protected voidprocessSerialized(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: Process a potential serializable attribute. If the class implements the Serializable interface then set a SerializedObjectConverter on the mapping.

        if (Helper.classImplementsInterface(getReferenceClass(), Serializable.class)) {
            SerializedObjectConverter converter = new SerializedObjectConverter(mapping);
            setConverter(mapping, converter);
        } else {
            m_validator.throwInvalidTypeForSerializedAttribute(getJavaClass(), mapping.getAttributeName(), getReferenceClass());
        }
    
protected voidprocessTemporal(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: Process a temporal type accessor.

        if (hasTemporal()) {
            if (MetadataHelper.isValidTemporalType(getReferenceClass())) {
                // Set a TypeConversionConverter on the mapping.
                setFieldClassification(mapping, MetadataHelper.getFieldClassification(getTemporalType()));
                setConverter(mapping, new TypeConversionConverter(mapping));
            } else {
                m_validator.throwInvalidTypeForTemporalAttribute(getJavaClass(), getAttributeName(), getReferenceClass());
            }    
        } else {
            m_validator.throwNoTemporalTypeSpecified(getJavaClass(), getAttributeName());
        }
    
public abstract voidsetConverter(oracle.toplink.essentials.mappings.DatabaseMapping mapping, oracle.toplink.essentials.mappings.converters.Converter converter)
INTERNAL:

public abstract voidsetFieldClassification(oracle.toplink.essentials.mappings.DatabaseMapping mapping, java.lang.Class classification)
INTERNAL: