Module org.eclipse.persistence.core
Class ConversionManager
- java.lang.Object
-
- org.eclipse.persistence.internal.core.helper.CoreConversionManager
-
- org.eclipse.persistence.internal.helper.ConversionManager
-
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
JPAConversionManager,XMLConversionManager
public class ConversionManager extends CoreConversionManager implements Serializable, Cloneable
Purpose: Contains the conversion routines for some common classes in the system. Primarily used to convert objects from a given database type to a different type in Java. Uses a singleton instance, this is also used from the platform.
Responsibilities:
- Execute the appropriate conversion routine.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Object,List<Class<?>>>dataTypesConvertedFromAClassStore the list of Classes that can be converted to from the key.protected Map<Class<?>,List<Class<?>>>dataTypesConvertedToAClassStore the list of Classes that can be converted from to the key.protected static ConversionManagerdefaultManagerprotected Map<Class<?>,Object>defaultNullValuesprotected ClassLoaderloaderprotected booleanshouldUseClassLoaderFromCurrentThreadThis flag is here if the Conversion Manager should use the class loader on the thread when loading classes.
-
Constructor Summary
Constructors Constructor Description ConversionManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected List<Class<?>>buildAllTypesToAClassVec()protected voidbuildDataTypesConvertedFromAClass()protected voidbuildDataTypesConvertedToAClass()protected List<Class<?>>buildDateTimeVec()protected List<Class<?>>buildFromBigDecimalVec()protected List<Class<?>>buildFromBigIntegerVec()protected List<Class<?>>buildFromBlobVec()protected List<Class<?>>buildFromBooleanVec()protected List<Class<?>>buildFromByteArrayVec()protected List<Class<?>>buildFromByteObjectArraryVec()protected List<Class<?>>buildFromByteVec()protected List<Class<?>>buildFromCalendarVec()protected List<Class<?>>buildFromCharacterArrayVec()protected List<Class<?>>buildFromCharacterVec()protected List<Class<?>>buildFromCharArrayVec()protected List<Class<?>>buildFromClobVec()protected List<Class<?>>buildFromDateVec()protected List<Class<?>>buildFromDoubleVec()protected List<Class<?>>buildFromFloatVec()protected List<Class<?>>buildFromIntegerVec()protected List<Class<?>>buildFromLongVec()protected List<Class<?>>buildFromNumberVec()protected List<Class<?>>buildFromShortVec()protected List<Class<?>>buildFromStringVec()protected List<Class<?>>buildFromTimestampVec()protected List<Class<?>>buildFromTimeVec()protected List<Class<?>>buildFromUtilDateVec()protected List<Class<?>>buildNumberVec()protected List<Class<?>>buildToBigDecimalVec()protected List<Class<?>>buildToBigIntegerVec()protected List<Class<?>>buildToBlobVec()protected List<Class<?>>buildToBooleanVec()protected List<Class<?>>buildToByteArrayVec()protected List<Class<?>>buildToByteObjectArrayVec()protected List<Class<?>>buildToByteVec()protected List<Class<?>>buildToCalendarVec()protected List<Class<?>>buildToCharacterArrayVec()protected List<Class<?>>buildToCharacterVec()protected List<Class<?>>buildToCharArrayVec()protected List<Class<?>>buildToClobVec()protected List<Class<?>>buildToDateVec()protected List<Class<?>>buildToDoubleVec()protected List<Class<?>>buildToFloatVec()protected List<Class<?>>buildToIntegerVec()protected List<Class<?>>buildToLongVec()protected List<Class<?>>buildToNumberVec()protected List<Class<?>>buildToShortVec()protected List<Class<?>>buildToStringVec()protected List<Class<?>>buildToTimestampVec()protected List<Class<?>>buildToTimeVec()protected List<Class<?>>buildToUtilDateVec()Objectclone()INTERNAL:<T> Class<T>convertClassNameToClass(String className)PUBLIC: Resolve the given String className into a class using this ConversionManager's classloader.<T> TconvertObject(Object sourceObject, Class<T> javaClass)Convert the object to the appropriate type by invoking the appropriate ConversionManager methodprotected BigDecimalconvertObjectToBigDecimal(Object sourceObject)Build a valid instance of BigDecimal from the given sourceObjectprotected BigIntegerconvertObjectToBigInteger(Object sourceObject)Build a valid instance of BigInteger from the provided sourceObject.protected BooleanconvertObjectToBoolean(Object sourceObject)Build a valid instance of Boolean from the source object.protected ByteconvertObjectToByte(Object sourceObject)Build a valid instance of Byte from the provided sourceObjectprotected byte[]convertObjectToByteArray(Object sourceObject)Build a valid instance of a byte array from the given object.protected Byte[]convertObjectToByteObjectArray(Object sourceObject)Build a valid instance of a Byte array from the given object.protected CalendarconvertObjectToCalendar(Object sourceObject)Build a valid instance of java.util.Calendar from the given source object.protected CharacterconvertObjectToChar(Object sourceObject)Build a valid instance of Character from the provided sourceObject.protected Character[]convertObjectToCharacterArray(Object sourceObject)Build a valid instance of a Character array from the given object.protected char[]convertObjectToCharArray(Object sourceObject)Build a valid instance of a char array from the given object.protected <T> Class<T>convertObjectToClass(Object sourceObject)Build a valid Class from the string that is passed inprotected DateconvertObjectToDate(Object sourceObject)Convert the object to an instance of java.sql.Date.protected DoubleconvertObjectToDouble(Object sourceObject)Convert the object to an instance of Double.protected FloatconvertObjectToFloat(Object sourceObject)Build a valid Float instance from a String or another Number instance.protected IntegerconvertObjectToInteger(Object sourceObject)Build a valid Integer instance from a String or another Number instance.protected LocalDateconvertObjectToLocalDate(Object sourceObject)INTERNAL: Build a valid instance of java.time.LocalDate from the given source object.protected LocalDateTimeconvertObjectToLocalDateTime(Object sourceObject)INTERNAL: Build a valid instance of java.time.LocalDateTime from the given source object.protected LocalTimeconvertObjectToLocalTime(Object sourceObject)INTERNAL: Build a valid instance of java.time.LocalTime from the given source object.protected LongconvertObjectToLong(Object sourceObject)Build a valid Long instance from a String or another Number instance.protected BigDecimalconvertObjectToNumber(Object sourceObject)INTERNAL: Build a valid BigDecimal instance from a String or another Number instance.protected OffsetDateTimeconvertObjectToOffsetDateTime(Object sourceObject)INTERNAL: Build a valid instance of java.time.OffsetDateTime from the given source object.protected OffsetTimeconvertObjectToOffsetTime(Object sourceObject)INTERNAL: Build a valid instance of java.time.OffsetTime from the given source object.protected ShortconvertObjectToShort(Object sourceObject)INTERNAL: Build a valid Short instance from a String or another Number instance.protected StringconvertObjectToString(Object sourceObject)INTERNAL: Converts objects to their string representations.protected TimeconvertObjectToTime(Object sourceObject)INTERNAL: Build a valid instance of java.sql.Time from the given source object.protected TimestampconvertObjectToTimestamp(Object sourceObject)INTERNAL: Build a valid instance of java.sql.Timestamp from the given source object.protected URLconvertObjectToUrl(Object sourceObject)INTERNAL: Build a valid instance of java.net.URL from the given source object.protected DateconvertObjectToUtilDate(Object sourceObject)INTERNAL: Build a valid instance of java.util.Date from the given source object.protected UUIDconvertObjectToUUID(Object sourceObject)INTERNAL: Build a valid instance of java.util.UUID from the given source object.List<Class<?>>getDataTypesConvertedFrom(Class<?> javaClass)PUBLIC: Return the list of Classes that can be converted to from the passed in javaClass.List<Class<?>>getDataTypesConvertedTo(Class<?> javaClass)PUBLIC: Return the list of Classes that can be converted from to the passed in javaClass.static ClassLoadergetDefaultLoader()INTERNAL: Get the default class loader to use if no instance-level loader is setstatic ConversionManagergetDefaultManager()A singleton conversion manager is used to handle generic conversions.<T> TgetDefaultNullValue(Class<T> theClass)INTERNAL: Allow for the null values for classes to be defaulted in one place.Map<Class<?>,Object>getDefaultNullValues()INTERNAL: Allow for the null values for classes to be defaulted in one place.ClassLoadergetLoader()INTERNAL:static <T> Class<T>getObjectClass(Class<?> javaClass)INTERNAL: This is used to determine the wrapper class for a primitive.static <T> Class<T>getPrimitiveClass(String classType)INTERNAL: Returns a class based on the passed in string.booleanhasDefaultNullValues()INTERNALstatic <T> Class<T>loadClass(String className)INTERNAL: Load the class using the default managers class loader.static voidsetDefaultLoader(ClassLoader classLoader)INTERNAL: Set the default class loader to use if no instance-level loader is setstatic voidsetDefaultManager(ConversionManager theManager)A singleton conversion manager is used to handle generic conversions.voidsetDefaultNullValue(Class<?> theClass, Object theValue)INTERNAL: Allow for the null values for classes to be defaulted in one place.voidsetDefaultNullValues(Map<Class<?>,Object> defaultNullValues)INTERNAL: Allow for the null values for classes to be defaulted in one place.voidsetLoader(ClassLoader classLoader)INTERNAL:voidsetShouldUseClassLoaderFromCurrentThread(boolean useCurrentThread)ADVANCED: This flag should be set if the current thread classLoader should be used.booleanshouldUseClassLoaderFromCurrentThread()ADVANCED: This flag should be set if the current thread classLoader should be used.
-
-
-
Field Detail
-
shouldUseClassLoaderFromCurrentThread
protected boolean shouldUseClassLoaderFromCurrentThread
This flag is here if the Conversion Manager should use the class loader on the thread when loading classes.
-
defaultManager
protected static ConversionManager defaultManager
-
loader
protected ClassLoader loader
-
dataTypesConvertedFromAClass
protected Map<Object,List<Class<?>>> dataTypesConvertedFromAClass
Store the list of Classes that can be converted to from the key.
-
-
Method Detail
-
convertObject
public <T> T convertObject(Object sourceObject, Class<T> javaClass) throws ConversionException
Convert the object to the appropriate type by invoking the appropriate ConversionManager method- Specified by:
convertObjectin classCoreConversionManager- Parameters:
sourceObject- the object that must be convertedjavaClass- the class that the object must be converted to- Returns:
- the newly converted object
- Throws:
ConversionException- all exceptions will be thrown as this type.
-
convertObjectToBigDecimal
protected BigDecimal convertObjectToBigDecimal(Object sourceObject) throws ConversionException
Build a valid instance of BigDecimal from the given sourceObject- Parameters:
sourceObject- Valid instance of String, BigInteger, any Number- Throws:
ConversionException
-
convertObjectToBigInteger
protected BigInteger convertObjectToBigInteger(Object sourceObject) throws ConversionException
Build a valid instance of BigInteger from the provided sourceObject.- Parameters:
sourceObject- Valid instance of String, BigDecimal, or any Number- Throws:
ConversionException
-
convertObjectToBoolean
protected Boolean convertObjectToBoolean(Object sourceObject)
Build a valid instance of Boolean from the source object. 't', 'T', "true", "TRUE", 1,'1' -> Boolean(true) 'f', 'F', "false", "FALSE", 0 ,'0' -> Boolean(false)
-
convertObjectToByte
protected Byte convertObjectToByte(Object sourceObject) throws ConversionException
Build a valid instance of Byte from the provided sourceObject- Parameters:
sourceObject- Valid instance of String or any Number- Throws:
ConversionException- The Byte(String) constructor throws a NumberFormatException if the String does not contain a parsable byte.
-
convertObjectToByteArray
protected byte[] convertObjectToByteArray(Object sourceObject) throws ConversionException
Build a valid instance of a byte array from the given object. This method does hex conversion of the string values. Some databases have problems with storing blobs unless the blob is stored as a hex string.- Throws:
ConversionException
-
convertObjectToByteObjectArray
protected Byte[] convertObjectToByteObjectArray(Object sourceObject) throws ConversionException
Build a valid instance of a Byte array from the given object. This method does hex conversion of the string values. Some databases have problems with storing blobs unless the blob is stored as a hex string.- Throws:
ConversionException
-
convertObjectToCalendar
protected Calendar convertObjectToCalendar(Object sourceObject) throws ConversionException
Build a valid instance of java.util.Calendar from the given source object.- Parameters:
sourceObject- Valid instance of java.util.Date, String, java.sql.Timestamp, or Long- Throws:
ConversionException
-
convertObjectToChar
protected Character convertObjectToChar(Object sourceObject) throws ConversionException
Build a valid instance of Character from the provided sourceObject.- Parameters:
sourceObject- Valid instance of String or any Number- Throws:
ConversionException
-
convertObjectToCharacterArray
protected Character[] convertObjectToCharacterArray(Object sourceObject) throws ConversionException
Build a valid instance of a Character array from the given object.- Throws:
ConversionException
-
convertObjectToCharArray
protected char[] convertObjectToCharArray(Object sourceObject) throws ConversionException
Build a valid instance of a char array from the given object.- Throws:
ConversionException
-
convertObjectToClass
protected <T> Class<T> convertObjectToClass(Object sourceObject) throws ConversionException
Build a valid Class from the string that is passed in- Parameters:
sourceObject- Valid instance of String- Throws:
ConversionException
-
convertObjectToDate
protected Date convertObjectToDate(Object sourceObject) throws ConversionException
Convert the object to an instance of java.sql.Date.- Parameters:
sourceObject- Object of type java.sql.Timestamp, java.util.Date, String or Long- Throws:
ConversionException
-
convertObjectToDouble
protected Double convertObjectToDouble(Object sourceObject) throws ConversionException
Convert the object to an instance of Double.- Parameters:
sourceObject- Object of type String or Number.- Throws:
ConversionException- The Double(String) constructor throws a NumberFormatException if the String does not contain a parsable double.
-
convertObjectToFloat
protected Float convertObjectToFloat(Object sourceObject) throws ConversionException
Build a valid Float instance from a String or another Number instance.- Throws:
ConversionException- The Float(String) constructor throws a NumberFormatException if the String does not contain a parsable Float.
-
convertObjectToInteger
protected Integer convertObjectToInteger(Object sourceObject) throws ConversionException
Build a valid Integer instance from a String or another Number instance.- Throws:
ConversionException- The Integer(String) constructor throws a NumberFormatException if the String does not contain a parsable integer.
-
convertObjectToLong
protected Long convertObjectToLong(Object sourceObject) throws ConversionException
Build a valid Long instance from a String or another Number instance.- Throws:
ConversionException- The Long(String) constructor throws a NumberFormatException if the String does not contain a parsable long.
-
convertObjectToNumber
protected BigDecimal convertObjectToNumber(Object sourceObject) throws ConversionException
INTERNAL: Build a valid BigDecimal instance from a String or another Number instance. BigDecimal is the most general type so is must be returned when an object is converted to a number.- Throws:
ConversionException- The BigDecimal(String) constructor throws a NumberFormatException if the String does not contain a parsable BigDecimal.
-
convertObjectToShort
protected Short convertObjectToShort(Object sourceObject) throws ConversionException
INTERNAL: Build a valid Short instance from a String or another Number instance.- Throws:
ConversionException- The Short(String) constructor throws a NumberFormatException if the String does not contain a parsable short.
-
convertObjectToString
protected String convertObjectToString(Object sourceObject) throws ConversionException
INTERNAL: Converts objects to their string representations. java.util.Date is converted to a timestamp first and then to a string. An array of bytes is converted to a hex string.- Throws:
ConversionException
-
convertObjectToTime
protected Time convertObjectToTime(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.sql.Time from the given source object.- Parameters:
sourceObject- Valid instance of java.sql.Time, String, java.util.Date, java.sql.Timestamp, or Long- Throws:
ConversionException
-
convertObjectToTimestamp
protected Timestamp convertObjectToTimestamp(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.sql.Timestamp from the given source object.- Parameters:
sourceObject- Valid object of class java.sql.Timestamp, String, java.util.Date, or Long- Throws:
ConversionException
-
convertObjectToLocalDate
protected LocalDate convertObjectToLocalDate(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.time.LocalDate from the given source object.- Parameters:
sourceObject- Valid object of class java.sql.Timestamp, String, java.util.Date, or Long- Throws:
ConversionException
-
convertObjectToLocalTime
protected LocalTime convertObjectToLocalTime(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.time.LocalTime from the given source object.- Parameters:
sourceObject- Valid object of class java.sql.Timestamp, String, java.util.Date, or Long- Throws:
ConversionException
-
convertObjectToLocalDateTime
protected LocalDateTime convertObjectToLocalDateTime(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.time.LocalDateTime from the given source object.- Parameters:
sourceObject- Valid object of class java.sql.Timestamp, String, java.util.Date, or Long- Throws:
ConversionException
-
convertObjectToOffsetDateTime
protected OffsetDateTime convertObjectToOffsetDateTime(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.time.OffsetDateTime from the given source object.- Parameters:
sourceObject- Valid object of class java.sql.Timestamp, String, java.util.Date, or Long- Throws:
ConversionException
-
convertObjectToOffsetTime
protected OffsetTime convertObjectToOffsetTime(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.time.OffsetTime from the given source object.- Parameters:
sourceObject- Valid object of class java.sql.Timestamp, String, java.util.Date, or Long- Throws:
ConversionException
-
convertObjectToUrl
protected URL convertObjectToUrl(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.net.URL from the given source object.- Parameters:
sourceObject- Valid instance of java.net.URL, or String- Throws:
ConversionException
-
convertObjectToUUID
protected UUID convertObjectToUUID(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.util.UUID from the given source object.- Parameters:
sourceObject- Valid instance of java.util.UUID, or String- Throws:
ConversionException
-
convertObjectToUtilDate
protected Date convertObjectToUtilDate(Object sourceObject) throws ConversionException
INTERNAL: Build a valid instance of java.util.Date from the given source object.- Parameters:
sourceObject- Valid instance of java.util.Date, String, java.sql.Timestamp, or Long- Throws:
ConversionException
-
convertClassNameToClass
public <T> Class<T> convertClassNameToClass(String className) throws ConversionException
PUBLIC: Resolve the given String className into a class using this ConversionManager's classloader.- Throws:
ConversionException
-
getDefaultManager
public static ConversionManager getDefaultManager()
A singleton conversion manager is used to handle generic conversions. This should not be used for conversion under the session context, these must go through the platform. This allows for the singleton to be customized through setting the default to a user defined subclass.
-
getDefaultNullValue
public <T> T getDefaultNullValue(Class<T> theClass)
INTERNAL: Allow for the null values for classes to be defaulted in one place. Any nulls read from the database to be converted to the class will be given the specified null value.
-
getDefaultNullValues
public Map<Class<?>,Object> getDefaultNullValues()
INTERNAL: Allow for the null values for classes to be defaulted in one place. Any nulls read from the database to be converted to the class will be given the specified null value.
-
getLoader
public ClassLoader getLoader()
INTERNAL:- Specified by:
getLoaderin classCoreConversionManager
-
hasDefaultNullValues
public boolean hasDefaultNullValues()
INTERNAL
-
loadClass
public static <T> Class<T> loadClass(String className)
INTERNAL: Load the class using the default managers class loader. This is a thread based class loader by default. This should be used to load all classes as Class.forName can only see classes on the same classpath as the eclipselink.jar.
-
getObjectClass
public static <T> Class<T> getObjectClass(Class<?> javaClass)
INTERNAL: This is used to determine the wrapper class for a primitive.
-
getPrimitiveClass
public static <T> Class<T> getPrimitiveClass(String classType)
INTERNAL: Returns a class based on the passed in string.
-
setDefaultManager
public static void setDefaultManager(ConversionManager theManager)
A singleton conversion manager is used to handle generic conversions. This should not be used for conversion under the session context, these must go through the platform. This allows for the singleton to be customized through setting the default to a user defined subclass.
-
setDefaultNullValue
public void setDefaultNullValue(Class<?> theClass, Object theValue)
INTERNAL: Allow for the null values for classes to be defaulted in one place. Any nulls read from the database to be converted to the class will be given the specified null value. Primitive null values should be set to the wrapper class.
-
setDefaultNullValues
public void setDefaultNullValues(Map<Class<?>,Object> defaultNullValues)
INTERNAL: Allow for the null values for classes to be defaulted in one place. Any nulls read from the database to be converted to the class will be given the specified null value.
-
setLoader
public void setLoader(ClassLoader classLoader)
INTERNAL:
-
setDefaultLoader
public static void setDefaultLoader(ClassLoader classLoader)
INTERNAL: Set the default class loader to use if no instance-level loader is set
-
getDefaultLoader
public static ClassLoader getDefaultLoader()
INTERNAL: Get the default class loader to use if no instance-level loader is set- Returns:
- java.lang.ClassLoader
-
setShouldUseClassLoaderFromCurrentThread
public void setShouldUseClassLoaderFromCurrentThread(boolean useCurrentThread)
ADVANCED: This flag should be set if the current thread classLoader should be used. This is the case in certain Application Servers were the class loader must be retrieved from the current Thread. If classNotFoundExceptions are being thrown then set this flag. In certain cases it will resolve the problem
-
shouldUseClassLoaderFromCurrentThread
public boolean shouldUseClassLoaderFromCurrentThread()
ADVANCED: This flag should be set if the current thread classLoader should be used. This is the case in certain Application Servers were the class loader must be retrieved from the current Thread. If classNotFoundExceptions are being thrown then set this flag. In certain cases it will resolve the problem
-
getDataTypesConvertedFrom
public List<Class<?>> getDataTypesConvertedFrom(Class<?> javaClass)
PUBLIC: Return the list of Classes that can be converted to from the passed in javaClass.- Parameters:
javaClass- - the class that is converted from- Returns:
- - a vector of classes
-
getDataTypesConvertedTo
public List<Class<?>> getDataTypesConvertedTo(Class<?> javaClass)
PUBLIC: Return the list of Classes that can be converted from to the passed in javaClass.- Parameters:
javaClass- - the class that is converted to- Returns:
- - a vector of classes
-
buildDataTypesConvertedFromAClass
protected void buildDataTypesConvertedFromAClass()
-
buildDataTypesConvertedToAClass
protected void buildDataTypesConvertedToAClass()
-
-