Class ObjectTypeConverter
java.lang.Object
org.eclipse.persistence.mappings.converters.ObjectTypeConverter
- All Implemented Interfaces:
Serializable
,CoreConverter<DatabaseMapping,
,Session> org.eclipse.persistence.internal.descriptors.ClassNameConversionRequired
,Converter
- Direct Known Subclasses:
EnumTypeConverter
,JAXBEnumTypeConverter
public class ObjectTypeConverter
extends Object
implements Converter, org.eclipse.persistence.internal.descriptors.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.
- See Also:
- Author:
- James Sutherland
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPUBLIC: Default constructor.ObjectTypeConverter
(DatabaseMapping mapping) PUBLIC: Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConversionValue
(Object fieldValue, Object attributeValue) PUBLIC: A type conversion value is a two-way mapping from the database to the object.void
addConversionValueStrings
(String dataValue, String objectValue) INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.void
addToAttributeOnlyConversionValue
(Object fieldValue, Object attributeValue) PUBLIC: An attribute only conversion value is a one-way mapping from the database to the object.void
addToAttributeOnlyConversionValueStrings
(String dataValue, String objectValue) INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.void
convertClassNamesToClasses
(ClassLoader classLoader) INTERNAL: Convert all the class-name-based settings in this converter to actual class-based settings.convertDataValueToObjectValue
(Object fieldValue, Session session) INTERNAL: Returns the corresponding attribute value for the specified field value.convertObjectValueToDataValue
(Object attributeValue, Session session) INTERNAL: Convert to the data value.INTERNAL: Get the attribute to field mapping.PUBLIC: The default value can be used if the database can possibly store additional values then those that have been mapped.INTERNAL: Get the type of the field value to allow conversion from the database.getFieldClassification
(org.eclipse.persistence.internal.helper.DatabaseField fieldToClassify) INTERNAL: Return the classifiction for the field contained in the mapping.INTERNAL: Return a collection of the field to attribute value associations.INTERNAL: Get the field to attribute mapping.protected DatabaseMapping
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 map.boolean
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.void
PUBLIC: This is a very specific protocol which maps fieldValues "T" and "F" to true and false respectively.void
PUBLIC: This is a very specific protocol which maps fieldValues "F" and "M" to "Female" and "Male" respectively.void
PUBLIC: This is a very specific protocol which maps fieldValues "Y" and "N" to "Yes" and "No" respectively.void
setAttributeToFieldValues
(Map attributeToFieldValues) INTERNAL: Set the attribute to field mapping.void
setConverterName
(String converterName) INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.void
setDataTypeName
(String dataTypeName) INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.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.void
setDefaultAttributeValueString
(String defaultAttributeValueString) INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.void
setFieldClassification
(Class fieldClassification) INTERNAL: Set the type of the field value to allow conversion from the database.void
setFieldClassificationName
(String fieldClassificationName) void
setFieldToAttributeValueAssociations
(Vector fieldToAttributeValueAssociations) INTERNAL: Set a collection of the field to attribute value associations.void
setFieldToAttributeValues
(Map fieldToAttributeValues) INTERNAL: Set the field to attribute mapping.protected void
setMapping
(DatabaseMapping mapping) INTERNAL: Set the mapping.void
setObjectTypeName
(String objectTypeName) INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts.protected void
throwInitObjectException
(Exception exception, Class type, String value, boolean isData) INTERNAL:
-
Field Details
-
converterName
-
dataType
-
dataTypeName
-
objectType
-
objectTypeName
-
conversionValueStrings
-
addToAttributeOnlyConversionValueStrings
-
mapping
-
fieldToAttributeValues
-
attributeToFieldValues
-
defaultAttributeValue
-
defaultAttributeValueString
-
fieldClassification
-
fieldClassificationName
-
-
Constructor Details
-
ObjectTypeConverter
public ObjectTypeConverter()PUBLIC: Default constructor. -
ObjectTypeConverter
PUBLIC: Default constructor.
-
-
Method Details
-
addConversionValue
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
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts. -
addToAttributeOnlyConversionValue
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
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts. -
getAttributeToFieldValues
INTERNAL: Get the attribute to field mapping. -
convertClassNamesToClasses
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:
convertClassNamesToClasses
in interfaceorg.eclipse.persistence.internal.descriptors.ClassNameConversionRequired
- Parameters:
classLoader
-
-
loadClass
Load the given class name with the given loader. -
convertDataValueToObjectValue
INTERNAL: Returns the corresponding attribute value for the specified field value.- Specified by:
convertDataValueToObjectValue
in interfaceConverter
- Specified by:
convertDataValueToObjectValue
in interfaceCoreConverter<DatabaseMapping,
Session>
-
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
INTERNAL: Return the mapping. -
setMapping
INTERNAL: Set the mapping. -
setObjectTypeName
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts. -
getFieldClassification
INTERNAL: Get the type of the field value to allow conversion from the database. -
getFieldClassificationName
-
getFieldClassification
public 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
INTERNAL: Return a collection of the field to attribute value associations. -
getFieldToAttributeValues
INTERNAL: Get the field to attribute mapping. -
convertObjectValueToDataValue
INTERNAL: Convert to the data value.- Specified by:
convertObjectValueToDataValue
in interfaceConverter
- Specified by:
convertObjectValueToDataValue
in 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
INTERNAL: Set the field classification through searching the fields map.- Throws:
DescriptorException
-
initialize
INTERNAL: Set the mapping.- Specified by:
initialize
in interfaceConverter
- Specified by:
initialize
in interfaceCoreConverter<DatabaseMapping,
Session>
-
setAttributeToFieldValues
INTERNAL: Set the attribute to field mapping. -
setConverterName
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts. -
setDataTypeName
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts. -
setDefaultAttributeValue
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
INTERNAL: Set from JPA processing where we deal with strings only to avoid class loader conflicts. -
setFieldClassification
INTERNAL: Set the type of the field value to allow conversion from the database. -
setFieldClassificationName
-
setFieldToAttributeValueAssociations
INTERNAL: Set a collection of the field to attribute value associations. -
setFieldToAttributeValues
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. -
throwInitObjectException
protected void throwInitObjectException(Exception exception, Class type, String value, boolean isData) INTERNAL:
-