Class EnumTypeConverter
- java.lang.Object
-
- org.eclipse.persistence.mappings.converters.ObjectTypeConverter
-
- org.eclipse.persistence.mappings.converters.EnumTypeConverter
-
- All Implemented Interfaces:
Serializable
,CoreConverter<DatabaseMapping,Session>
,ClassNameConversionRequired
,Converter
public class EnumTypeConverter extends ObjectTypeConverter
Purpose: Object type converter is used to match a fixed number of database data values to a Java enum 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.1.4RI
- Author:
- Guy Pelletier
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.eclipse.persistence.mappings.converters.ObjectTypeConverter
addToAttributeOnlyConversionValueStrings, attributeToFieldValues, conversionValueStrings, converterName, dataType, dataTypeName, defaultAttributeValue, defaultAttributeValueString, fieldClassification, fieldClassificationName, fieldToAttributeValues, mapping, objectType, objectTypeName
-
-
Constructor Summary
Constructors Constructor Description EnumTypeConverter(DatabaseMapping mapping, Class enumClass, boolean useOrdinalValues)
PUBLIC: Creating an enum converter this way will create the conversion values for you using ordinal or name values.EnumTypeConverter(DatabaseMapping mapping, String enumClassName)
PUBLIC: Creating an enum converter this way expects that you will provide the conversion values separately.EnumTypeConverter(DatabaseMapping mapping, String enumClassName, boolean useOrdinalValues)
PUBLIC: Creating an enum converter this way will create the conversion values for you using ordinal or name values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
convertClassNamesToClasses(ClassLoader classLoader)
INTERNAL: Convert all the class-name-based settings in this converter to actual class-based settings.Object
convertDataValueToObjectValue(Object fieldValue, Session session)
INTERNAL: Returns the corresponding attribute value for the specified field value.Object
convertObjectValueToDataValue(Object attributeValue, Session session)
INTERNAL: Convert Enum object to the data value.Class
getEnumClass()
String
getEnumClassName()
protected void
initializeConversions(Class enumClass)
-
Methods inherited from class org.eclipse.persistence.mappings.converters.ObjectTypeConverter
addConversionValue, addConversionValueStrings, addToAttributeOnlyConversionValue, addToAttributeOnlyConversionValueStrings, getAttributeToFieldValues, getDefaultAttributeValue, getFieldClassification, getFieldClassification, getFieldClassificationName, getFieldToAttributeValueAssociations, getFieldToAttributeValues, getMapping, initialize, initializeFieldClassification, isMutable, loadClass, mapBooleans, mapGenders, mapResponses, setAttributeToFieldValues, setConverterName, setDataTypeName, setDefaultAttributeValue, setDefaultAttributeValueString, setFieldClassification, setFieldClassificationName, setFieldToAttributeValueAssociations, setFieldToAttributeValues, setMapping, setObjectTypeName, throwInitObjectException
-
-
-
-
Constructor Detail
-
EnumTypeConverter
public EnumTypeConverter(DatabaseMapping mapping, Class enumClass, boolean useOrdinalValues)
PUBLIC: Creating an enum converter this way will create the conversion values for you using ordinal or name values.
-
EnumTypeConverter
public EnumTypeConverter(DatabaseMapping mapping, String enumClassName, boolean useOrdinalValues)
PUBLIC: Creating an enum converter this way will create the conversion values for you using ordinal or name values.
-
EnumTypeConverter
public EnumTypeConverter(DatabaseMapping mapping, String enumClassName)
PUBLIC: Creating an enum converter this way expects that you will provide the conversion values separately.
-
-
Method Detail
-
initializeConversions
protected void initializeConversions(Class enumClass)
-
getEnumClass
public Class getEnumClass()
-
getEnumClassName
public String getEnumClassName()
-
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:
convertClassNamesToClasses
in interfaceClassNameConversionRequired
- Overrides:
convertClassNamesToClasses
in classObjectTypeConverter
- Parameters:
classLoader
-
-
convertDataValueToObjectValue
public Object convertDataValueToObjectValue(Object fieldValue, Session session)
INTERNAL: Returns the corresponding attribute value for the specified field value. Wraps the super method to return an Enum type from the string conversion.- Specified by:
convertDataValueToObjectValue
in interfaceConverter
- Specified by:
convertDataValueToObjectValue
in interfaceCoreConverter<DatabaseMapping,Session>
- Overrides:
convertDataValueToObjectValue
in classObjectTypeConverter
-
convertObjectValueToDataValue
public Object convertObjectValueToDataValue(Object attributeValue, Session session)
INTERNAL: Convert Enum object to the data value. Internal enums are stored as strings (names) so this method wraps the super method in that if breaks down the enum to a string name before converting it.- Specified by:
convertObjectValueToDataValue
in interfaceConverter
- Specified by:
convertObjectValueToDataValue
in interfaceCoreConverter<DatabaseMapping,Session>
- Overrides:
convertObjectValueToDataValue
in classObjectTypeConverter
-
-