Module org.eclipse.persistence.core
Class ObjectTypeConverter
- java.lang.Object
-
- org.eclipse.persistence.mappings.converters.ObjectTypeConverter
-
- All Implemented Interfaces:
Serializable,CoreConverter<DatabaseMapping,Session>,ClassNameConversionRequired,Converter
- Direct Known Subclasses:
EnumTypeConverter,ExpressionOperatorConverter
public class ObjectTypeConverter extends Object implements Converter, ClassNameConversionRequired
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.- Since:
- Toplink 10
- Author:
- James Sutherland
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,String>addToAttributeOnlyConversionValueStringsprotected MapattributeToFieldValuesprotected Map<String,String>conversionValueStringsprotected StringconverterNameprotected Class<?>dataTypeprotected StringdataTypeNameprotected ObjectdefaultAttributeValueprotected StringdefaultAttributeValueStringprotected Class<?>fieldClassificationprotected StringfieldClassificationNameprotected MapfieldToAttributeValuesprotected DatabaseMappingmappingprotected Class<?>objectTypeprotected StringobjectTypeName
-
Constructor Summary
Constructors Constructor Description ObjectTypeConverter()PUBLIC: Default constructor.ObjectTypeConverter(DatabaseMapping mapping)PUBLIC: Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConversionValue(Object fieldValue, Object attributeValue)PUBLIC: A type conversion value is a two-way mapping from the database to the object.voidaddConversionValueStrings(String dataValue, String objectValue)INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.voidaddToAttributeOnlyConversionValue(Object fieldValue, Object attributeValue)PUBLIC: An attribute only conversion value is a one-way mapping from the database to the object.voidaddToAttributeOnlyConversionValueStrings(String dataValue, String objectValue)INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.voidconvertClassNamesToClasses(ClassLoader classLoader)INTERNAL: Convert all the class-name-based settings in this converter to actual class-based settings.ObjectconvertDataValueToObjectValue(Object fieldValue, Session session)INTERNAL: Returns the corresponding attribute value for the specified field value.ObjectconvertObjectValueToDataValue(Object attributeValue, Session session)INTERNAL: Convert to the data value.MapgetAttributeToFieldValues()INTERNAL: Get the attribute to field mapping.ObjectgetDefaultAttributeValue()PUBLIC: The default value can be used if the database can possibly store additional values then those that have been mapped.Class<?>getFieldClassification()INTERNAL: Get the type of the field value to allow conversion from the database.Class<?>getFieldClassification(DatabaseField fieldToClassify)INTERNAL: Return the classifiction for the field contained in the mapping.StringgetFieldClassificationName()VectorgetFieldToAttributeValueAssociations()INTERNAL: Return a collection of the field to attribute value associations.MapgetFieldToAttributeValues()INTERNAL: Get the field to attribute mapping.protected DatabaseMappinggetMapping()INTERNAL: Return the mapping.voidinitialize(DatabaseMapping mapping, Session session)INTERNAL: Set the mapping.voidinitializeFieldClassification(Session session)INTERNAL: Set the field classification through searching the fields map.booleanisMutable()INTERNAL: If the converter converts the value to a non-atomic value, i.e.protected Class<?>loadClass(String className, ClassLoader classLoader)Load the given class name with the given loader.voidmapBooleans()PUBLIC: This is a very specific protocol which maps fieldValues "T" and "F" to true and false respectively.voidmapGenders()PUBLIC: This is a very specific protocol which maps fieldValues "F" and "M" to "Female" and "Male" respectively.voidmapResponses()PUBLIC: This is a very specific protocol which maps fieldValues "Y" and "N" to "Yes" and "No" respectively.voidsetAttributeToFieldValues(Map attributeToFieldValues)INTERNAL: Set the attribute to field mapping.voidsetConverterName(String converterName)INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.voidsetDataTypeName(String dataTypeName)INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.voidsetDefaultAttributeValue(Object defaultAttributeValue)PUBLIC: The default value can be used if the database can possibly store additional values then those that have been mapped.voidsetDefaultAttributeValueString(String defaultAttributeValueString)INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.voidsetFieldClassification(Class<?> fieldClassification)INTERNAL: Set the type of the field value to allow conversion from the database.voidsetFieldClassificationName(String fieldClassificationName)voidsetFieldToAttributeValueAssociations(Vector fieldToAttributeValueAssociations)INTERNAL: Set a collection of the field to attribute value associations.voidsetFieldToAttributeValues(Map fieldToAttributeValues)INTERNAL: Set the field to attribute mapping.protected voidsetMapping(DatabaseMapping mapping)INTERNAL: Set the mapping.voidsetObjectTypeName(String objectTypeName)INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.protected voidthrowInitObjectException(Exception exception, Class<?> type, String value, boolean isData)INTERNAL:
-
-
-
Field Detail
-
converterName
protected String converterName
-
dataType
protected Class<?> dataType
-
dataTypeName
protected String dataTypeName
-
objectType
protected Class<?> objectType
-
objectTypeName
protected String objectTypeName
-
addToAttributeOnlyConversionValueStrings
protected Map<String,String> addToAttributeOnlyConversionValueStrings
-
mapping
protected DatabaseMapping mapping
-
fieldToAttributeValues
protected transient Map fieldToAttributeValues
-
attributeToFieldValues
protected Map attributeToFieldValues
-
defaultAttributeValue
protected transient Object defaultAttributeValue
-
defaultAttributeValueString
protected String defaultAttributeValueString
-
fieldClassification
protected transient Class<?> fieldClassification
-
fieldClassificationName
protected transient String fieldClassificationName
-
-
Constructor Detail
-
ObjectTypeConverter
public ObjectTypeConverter()
PUBLIC: Default constructor.
-
ObjectTypeConverter
public ObjectTypeConverter(DatabaseMapping mapping)
PUBLIC: Default constructor.
-
-
Method Detail
-
addConversionValue
public void addConversionValue(Object fieldValue, 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.
-
addConversionValueStrings
public void addConversionValueStrings(String dataValue, String objectValue)
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.
-
addToAttributeOnlyConversionValue
public void addToAttributeOnlyConversionValue(Object fieldValue, 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.
-
addToAttributeOnlyConversionValueStrings
public void addToAttributeOnlyConversionValueStrings(String dataValue, String objectValue)
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.
-
getAttributeToFieldValues
public Map getAttributeToFieldValues()
INTERNAL: Get the attribute to field mapping.
-
convertClassNamesToClasses
public void convertClassNamesToClasses(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.- Specified by:
convertClassNamesToClassesin interfaceClassNameConversionRequired
-
loadClass
protected Class<?> loadClass(String className, ClassLoader classLoader)
Load the given class name with the given loader.
-
convertDataValueToObjectValue
public Object convertDataValueToObjectValue(Object fieldValue, Session session)
INTERNAL: Returns the corresponding attribute value for the specified field value.- Specified by:
convertDataValueToObjectValuein interfaceConverter- Specified by:
convertDataValueToObjectValuein interfaceCoreConverter<DatabaseMapping,Session>
-
getDefaultAttributeValue
public 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.
-
setObjectTypeName
public void setObjectTypeName(String objectTypeName)
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.
-
getFieldClassification
public Class<?> getFieldClassification()
INTERNAL: Get the type of the field value to allow conversion from the database.
-
getFieldClassificationName
public String getFieldClassificationName()
-
getFieldClassification
public Class<?> getFieldClassification(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 Vector getFieldToAttributeValueAssociations()
INTERNAL: Return a collection of the field to attribute value associations.
-
getFieldToAttributeValues
public Map getFieldToAttributeValues()
INTERNAL: Get the field to attribute mapping.
-
convertObjectValueToDataValue
public Object convertObjectValueToDataValue(Object attributeValue, Session session)
INTERNAL: Convert to the data value.- Specified by:
convertObjectValueToDataValuein interfaceConverter- Specified by:
convertObjectValueToDataValuein interfaceCoreConverter<DatabaseMapping,Session>
-
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 map.- Throws:
DescriptorException
-
initialize
public void initialize(DatabaseMapping mapping, Session session)
INTERNAL: Set the mapping.- Specified by:
initializein interfaceConverter- Specified by:
initializein interfaceCoreConverter<DatabaseMapping,Session>
-
setAttributeToFieldValues
public void setAttributeToFieldValues(Map attributeToFieldValues)
INTERNAL: Set the attribute to field mapping.
-
setConverterName
public void setConverterName(String converterName)
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.
-
setDataTypeName
public void setDataTypeName(String dataTypeName)
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.
-
setDefaultAttributeValue
public void setDefaultAttributeValue(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.
-
setDefaultAttributeValueString
public void setDefaultAttributeValueString(String defaultAttributeValueString)
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.
-
setFieldClassification
public void setFieldClassification(Class<?> fieldClassification)
INTERNAL: Set the type of the field value to allow conversion from the database.
-
setFieldClassificationName
public void setFieldClassificationName(String fieldClassificationName)
-
setFieldToAttributeValueAssociations
public void setFieldToAttributeValueAssociations(Vector fieldToAttributeValueAssociations)
INTERNAL: Set a collection of the field to attribute value associations.
-
setFieldToAttributeValues
public void setFieldToAttributeValues(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.
-
-