EclipseLink 1.1.4, build 'v20100812-r7860' API Reference

org.eclipse.persistence.mappings.converters
Class ObjectTypeConverter

java.lang.Object
  extended by org.eclipse.persistence.mappings.converters.ObjectTypeConverter
All Implemented Interfaces:
java.io.Serializable, Converter
Direct Known Subclasses:
EnumTypeConverter, JAXBEnumTypeConverter

public class ObjectTypeConverter
extends java.lang.Object
implements Converter

Purpose: Object type converter is used to match a fixed number of database data values to Java object value. It can be used when the values on the database and in the Java differ. To create an object type converter, simply specify the set of conversion value pairs. A default value and one-way conversion are also supported for legacy data situations.

See Also:
Serialized Form
Author:
James Sutherland
Since:
Toplink 10

Field Summary
protected  java.util.Map attributeToFieldValues
           
protected  java.lang.Object defaultAttributeValue
           
protected  java.lang.Class fieldClassification
           
protected  java.lang.String fieldClassificationName
           
protected  java.util.Map fieldToAttributeValues
           
protected  DatabaseMapping mapping
           
 
Constructor Summary
ObjectTypeConverter()
          PUBLIC: Default constructor.
ObjectTypeConverter(DatabaseMapping mapping)
          PUBLIC: Default constructor.
 
Method Summary
 void addConversionValue(java.lang.Object fieldValue, java.lang.Object attributeValue)
          PUBLIC: A type conversion value is a two-way mapping from the database to the object.
 void addToAttributeOnlyConversionValue(java.lang.Object fieldValue, java.lang.Object attributeValue)
          PUBLIC: An attribute only conversion value is a one-way mapping from the database to the object.
 void convertClassNamesToClasses(java.lang.ClassLoader classLoader)
          INTERNAL: Convert all the class-name-based settings in this converter to actual class-based settings.
 java.lang.Object convertDataValueToObjectValue(java.lang.Object fieldValue, Session session)
          INTERNAL: Returns the corresponding attribute value for the specified field value.
 java.lang.Object convertObjectValueToDataValue(java.lang.Object attributeValue, Session session)
          INTERNAL: Convert to the data value.
 java.util.Map getAttributeToFieldValues()
          INTERNAL: Get the attribute to field mapping.
 java.lang.Object getDefaultAttributeValue()
          PUBLIC: The default value can be used if the database can possibly store additional values then those that have been mapped.
 java.lang.Class getFieldClassification()
          INTERNAL: Get the type of the field value to allow conversion from the database.
 java.lang.Class getFieldClassification(org.eclipse.persistence.internal.helper.DatabaseField fieldToClassify)
          INTERNAL: Return the classifiction for the field contained in the mapping.
 java.lang.String getFieldClassificationName()
           
 java.util.Vector getFieldToAttributeValueAssociations()
          INTERNAL: Return a collection of the field to attribute value associations.
 java.util.Map getFieldToAttributeValues()
          INTERNAL: Get the field to attribute mapping.
protected  DatabaseMapping getMapping()
          INTERNAL: Return the mapping.
 void initialize(DatabaseMapping mapping, Session session)
          INTERNAL: Set the mapping.
 void initializeFieldClassification(Session session)
          INTERNAL: Set the field classification through searching the fields hashtable.
 boolean isMutable()
          INTERNAL: If the converter converts the value to a non-atomic value, i.e.
 void mapBooleans()
          PUBLIC: This is a very specific protocol which maps fieldValues "T" and "F" to true and false respectively.
 void mapGenders()
          PUBLIC: This is a very specific protocol which maps fieldValues "F" and "M" to "Female" and "Male" respectively.
 void mapResponses()
          PUBLIC: This is a very specific protocol which maps fieldValues "Y" and "N" to "Yes" and "No" respectively.
 void setAttributeToFieldValues(java.util.Map attributeToFieldValues)
          INTERNAL: Set the attribute to field mapping.
 void setDefaultAttributeValue(java.lang.Object defaultAttributeValue)
          PUBLIC: The default value can be used if the database can possibly store additional values then those that have been mapped.
 void setFieldClassification(java.lang.Class fieldClassification)
          INTERNAL: Set the type of the field value to allow conversion from the database.
 void setFieldClassificationName(java.lang.String fieldClassificationName)
           
 void setFieldToAttributeValueAssociations(java.util.Vector fieldToAttributeValueAssociations)
          INTERNAL: Set a collection of the field to attribute value associations.
 void setFieldToAttributeValues(java.util.Map fieldToAttributeValues)
          INTERNAL: Set the field to attribute mapping.
protected  void setMapping(DatabaseMapping mapping)
          INTERNAL: Set the mapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapping

protected DatabaseMapping mapping

fieldToAttributeValues

protected transient java.util.Map fieldToAttributeValues

attributeToFieldValues

protected java.util.Map attributeToFieldValues

defaultAttributeValue

protected transient java.lang.Object defaultAttributeValue

fieldClassification

protected transient java.lang.Class fieldClassification

fieldClassificationName

protected transient java.lang.String fieldClassificationName
Constructor Detail

ObjectTypeConverter

public ObjectTypeConverter()
PUBLIC: Default constructor.


ObjectTypeConverter

public ObjectTypeConverter(DatabaseMapping mapping)
PUBLIC: Default constructor.

Method Detail

addConversionValue

public void addConversionValue(java.lang.Object fieldValue,
                               java.lang.Object attributeValue)
PUBLIC: A type conversion value is a two-way mapping from the database to the object. The database value will be substituted for the object value when read, and the object value will be substituted for database value when written. Note that each field/attribute value must have one and only one attribute/field value to maintain a two-way mapping.


addToAttributeOnlyConversionValue

public void addToAttributeOnlyConversionValue(java.lang.Object fieldValue,
                                              java.lang.Object attributeValue)
PUBLIC: An attribute only conversion value is a one-way mapping from the database to the object. This can be used if multiple database values are desired to be mapped to the same object value. Note that when written only the default value will be used for the attribute, not this value.


getAttributeToFieldValues

public java.util.Map getAttributeToFieldValues()
INTERNAL: Get the attribute to field mapping.


convertClassNamesToClasses

public void convertClassNamesToClasses(java.lang.ClassLoader classLoader)
INTERNAL: Convert all the class-name-based settings in this converter to actual class-based settings. This method is used when converting a project that has been built with class names to a project with classes.

Parameters:
classLoader -

convertDataValueToObjectValue

public java.lang.Object convertDataValueToObjectValue(java.lang.Object fieldValue,
                                                      Session session)
INTERNAL: Returns the corresponding attribute value for the specified field value.

Specified by:
convertDataValueToObjectValue in interface Converter

getDefaultAttributeValue

public java.lang.Object getDefaultAttributeValue()
PUBLIC: The default value can be used if the database can possibly store additional values then those that have been mapped. Any value retreived from the database that is not mapped will be substitued for the default value.


getMapping

protected DatabaseMapping getMapping()
INTERNAL: Return the mapping.


setMapping

protected void setMapping(DatabaseMapping mapping)
INTERNAL: Set the mapping.


getFieldClassification

public java.lang.Class getFieldClassification()
INTERNAL: Get the type of the field value to allow conversion from the database.


getFieldClassificationName

public java.lang.String getFieldClassificationName()

getFieldClassification

public java.lang.Class getFieldClassification(org.eclipse.persistence.internal.helper.DatabaseField fieldToClassify)
INTERNAL: Return the classifiction for the field contained in the mapping. This is used to convert the row value to a consistent java value. By default this is null which means unknown.


getFieldToAttributeValueAssociations

public java.util.Vector getFieldToAttributeValueAssociations()
INTERNAL: Return a collection of the field to attribute value associations.


getFieldToAttributeValues

public java.util.Map getFieldToAttributeValues()
INTERNAL: Get the field to attribute mapping.


convertObjectValueToDataValue

public java.lang.Object convertObjectValueToDataValue(java.lang.Object attributeValue,
                                                      Session session)
INTERNAL: Convert to the data value.

Specified by:
convertObjectValueToDataValue in interface Converter

mapBooleans

public void mapBooleans()
PUBLIC: This is a very specific protocol which maps fieldValues "T" and "F" to true and false respectively.


mapGenders

public void mapGenders()
PUBLIC: This is a very specific protocol which maps fieldValues "F" and "M" to "Female" and "Male" respectively.


mapResponses

public void mapResponses()
PUBLIC: This is a very specific protocol which maps fieldValues "Y" and "N" to "Yes" and "No" respectively.


initializeFieldClassification

public void initializeFieldClassification(Session session)
                                   throws DescriptorException
INTERNAL: Set the field classification through searching the fields hashtable.

Throws:
DescriptorException

initialize

public void initialize(DatabaseMapping mapping,
                       Session session)
INTERNAL: Set the mapping.

Specified by:
initialize in interface Converter

setAttributeToFieldValues

public void setAttributeToFieldValues(java.util.Map attributeToFieldValues)
INTERNAL: Set the attribute to field mapping.


setDefaultAttributeValue

public void setDefaultAttributeValue(java.lang.Object defaultAttributeValue)
PUBLIC: The default value can be used if the database can possibly store additional values then those that have been mapped. Any value retreived from the database that is not mapped will be substitued for the default value.


setFieldClassification

public void setFieldClassification(java.lang.Class fieldClassification)
INTERNAL: Set the type of the field value to allow conversion from the database.


setFieldClassificationName

public void setFieldClassificationName(java.lang.String fieldClassificationName)

setFieldToAttributeValueAssociations

public void setFieldToAttributeValueAssociations(java.util.Vector fieldToAttributeValueAssociations)
INTERNAL: Set a collection of the field to attribute value associations.


setFieldToAttributeValues

public void setFieldToAttributeValues(java.util.Map fieldToAttributeValues)
INTERNAL: Set the field to attribute mapping.


isMutable

public boolean isMutable()
INTERNAL: If the converter converts the value to a non-atomic value, i.e. a value that can have its' parts changed without being replaced, then it must return false, serialization can be non-atomic.

Specified by:
isMutable in interface Converter

EclipseLink 1.1.4, build 'v20100812-r7860' API Reference