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
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:
-
Field Summary
Modifier and TypeFieldDescriptionStore the list of Classes that can be converted to from the key.Store the list of Classes that can be converted from to the key.protected static ConversionManager
protected ClassLoader
protected boolean
This flag is here if the Conversion Manager should use the class loader on the thread when loading classes. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
clone()
INTERNAL:<T> Class
<T> convertClassNameToClass
(String className) PUBLIC: Resolve the given String className into a class using this ConversionManager's classloader.<T> T
convertObject
(Object sourceObject, Class<T> javaClass) Convert the object to the appropriate type by invoking the appropriate ConversionManager methodprotected BigDecimal
convertObjectToBigDecimal
(Object sourceObject) Build a valid instance of BigDecimal from the given sourceObjectprotected BigInteger
convertObjectToBigInteger
(Object sourceObject) Build a valid instance of BigInteger from the provided sourceObject.protected Boolean
convertObjectToBoolean
(Object sourceObject) Build a valid instance of Boolean from the source object.protected Byte
convertObjectToByte
(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 Calendar
convertObjectToCalendar
(Object sourceObject) Build a valid instance of java.util.Calendar from the given source object.protected Character
convertObjectToChar
(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 Date
convertObjectToDate
(Object sourceObject) Convert the object to an instance of java.sql.Date.protected Double
convertObjectToDouble
(Object sourceObject) Convert the object to an instance of Double.protected Float
convertObjectToFloat
(Object sourceObject) Build a valid Float instance from a String or another Number instance.protected Integer
convertObjectToInteger
(Object sourceObject) Build a valid Integer instance from a String or another Number instance.protected LocalDate
convertObjectToLocalDate
(Object sourceObject) INTERNAL: Build a valid instance of java.time.LocalDate from the given source object.protected LocalDateTime
convertObjectToLocalDateTime
(Object sourceObject) INTERNAL: Build a valid instance of java.time.LocalDateTime from the given source object.protected LocalTime
convertObjectToLocalTime
(Object sourceObject) INTERNAL: Build a valid instance of java.time.LocalTime from the given source object.protected Long
convertObjectToLong
(Object sourceObject) Build a valid Long instance from a String or another Number instance.protected BigDecimal
convertObjectToNumber
(Object sourceObject) INTERNAL: Build a valid BigDecimal instance from a String or another Number instance.protected OffsetDateTime
convertObjectToOffsetDateTime
(Object sourceObject) INTERNAL: Build a valid instance of java.time.OffsetDateTime from the given source object.protected OffsetTime
convertObjectToOffsetTime
(Object sourceObject) INTERNAL: Build a valid instance of java.time.OffsetTime from the given source object.protected Short
convertObjectToShort
(Object sourceObject) INTERNAL: Build a valid Short instance from a String or another Number instance.protected String
convertObjectToString
(Object sourceObject) INTERNAL: Converts objects to their string representations.protected Time
convertObjectToTime
(Object sourceObject) INTERNAL: Build a valid instance of java.sql.Time from the given source object.protected Timestamp
convertObjectToTimestamp
(Object sourceObject) INTERNAL: Build a valid instance of java.sql.Timestamp from the given source object.protected URL
convertObjectToUrl
(Object sourceObject) INTERNAL: Build a valid instance of java.net.URL from the given source object.protected Date
convertObjectToUtilDate
(Object sourceObject) INTERNAL: Build a valid instance of java.util.Date from the given source object.protected UUID
convertObjectToUUID
(Object sourceObject) INTERNAL: Build a valid instance of java.util.UUID from the given source object.getDataTypesConvertedFrom
(Class<?> javaClass) PUBLIC: Return the list of Classes that can be converted to from the passed in javaClass.getDataTypesConvertedTo
(Class<?> javaClass) PUBLIC: Return the list of Classes that can be converted from to the passed in javaClass.static ClassLoader
INTERNAL: Get the default class loader to use if no instance-level loader is setstatic ConversionManager
A singleton conversion manager is used to handle generic conversions.<T> T
getDefaultNullValue
(Class<T> theClass) INTERNAL: Allow for the null values for classes to be defaulted in one place.INTERNAL: Allow for the null values for classes to be defaulted in one place.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.boolean
INTERNALstatic <T> Class
<T> INTERNAL: Load the class using the default managers class loader.static void
setDefaultLoader
(ClassLoader classLoader) INTERNAL: Set the default class loader to use if no instance-level loader is setstatic void
setDefaultManager
(ConversionManager theManager) A singleton conversion manager is used to handle generic conversions.void
setDefaultNullValue
(Class<?> theClass, Object theValue) INTERNAL: Allow for the null values for classes to be defaulted in one place.void
setDefaultNullValues
(Map<Class<?>, Object> defaultNullValues) INTERNAL: Allow for the null values for classes to be defaulted in one place.void
setLoader
(ClassLoader classLoader) INTERNAL:void
setShouldUseClassLoaderFromCurrentThread
(boolean useCurrentThread) ADVANCED: This flag should be set if the current thread classLoader should be used.boolean
ADVANCED: This flag should be set if the current thread classLoader should be used.
-
Field Details
-
defaultNullValues
-
shouldUseClassLoaderFromCurrentThread
protected boolean shouldUseClassLoaderFromCurrentThreadThis flag is here if the Conversion Manager should use the class loader on the thread when loading classes. -
defaultManager
-
loader
-
dataTypesConvertedFromAClass
Store the list of Classes that can be converted to from the key. -
dataTypesConvertedToAClass
Store the list of Classes that can be converted from to the key.
-
-
Constructor Details
-
ConversionManager
public ConversionManager()
-
-
Method Details
-
clone
INTERNAL: -
convertObject
Convert the object to the appropriate type by invoking the appropriate ConversionManager method- Specified by:
convertObject
in 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
Build a valid instance of BigDecimal from the given sourceObject- Parameters:
sourceObject
- Valid instance of String, BigInteger, any Number- Throws:
ConversionException
-
convertObjectToBigInteger
Build a valid instance of BigInteger from the provided sourceObject.- Parameters:
sourceObject
- Valid instance of String, BigDecimal, or any Number- Throws:
ConversionException
-
convertObjectToBoolean
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
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
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
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
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
Build a valid instance of Character from the provided sourceObject.- Parameters:
sourceObject
- Valid instance of String or any Number- Throws:
ConversionException
-
convertObjectToCharacterArray
Build a valid instance of a Character array from the given object.- Throws:
ConversionException
-
convertObjectToCharArray
Build a valid instance of a char array from the given object.- Throws:
ConversionException
-
convertObjectToClass
Build a valid Class from the string that is passed in- Parameters:
sourceObject
- Valid instance of String- Throws:
ConversionException
-
convertObjectToDate
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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: Resolve the given String className into a class using this ConversionManager's classloader.- Throws:
ConversionException
-
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
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
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
INTERNAL:- Specified by:
getLoader
in classCoreConversionManager
-
hasDefaultNullValues
public boolean hasDefaultNullValues()INTERNAL -
loadClass
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
INTERNAL: This is used to determine the wrapper class for a primitive. -
getPrimitiveClass
INTERNAL: Returns a class based on the passed in string. -
setDefaultManager
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
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
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
INTERNAL: -
setDefaultLoader
INTERNAL: Set the default class loader to use if no instance-level loader is set -
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: 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: 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
-
buildNumberVec
-
buildDateTimeVec
-
buildDataTypesConvertedFromAClass
protected void buildDataTypesConvertedFromAClass() -
buildFromBooleanVec
-
buildFromNumberVec
-
buildFromBigDecimalVec
-
buildFromBigIntegerVec
-
buildFromIntegerVec
-
buildFromFloatVec
-
buildFromDoubleVec
-
buildFromShortVec
-
buildFromByteVec
-
buildFromLongVec
-
buildFromStringVec
-
buildFromCharacterVec
-
buildFromByteArrayVec
-
buildFromClobVec
-
buildFromBlobVec
-
buildFromUtilDateVec
-
buildFromTimestampVec
-
buildFromCalendarVec
-
buildFromDateVec
-
buildFromTimeVec
-
buildFromByteObjectArraryVec
-
buildFromCharArrayVec
-
buildFromCharacterArrayVec
-
buildDataTypesConvertedToAClass
protected void buildDataTypesConvertedToAClass() -
buildAllTypesToAClassVec
-
buildToBigDecimalVec
-
buildToBigIntegerVec
-
buildToBooleanVec
-
buildToByteVec
-
buildToDoubleVec
-
buildToFloatVec
-
buildToIntegerVec
-
buildToLongVec
-
buildToNumberVec
-
buildToShortVec
-
buildToByteArrayVec
-
buildToByteObjectArrayVec
-
buildToCharacterVec
-
buildToCharacterArrayVec
-
buildToCharArrayVec
-
buildToStringVec
-
buildToCalendarVec
-
buildToTimestampVec
-
buildToUtilDateVec
-
buildToDateVec
-
buildToTimeVec
-
buildToBlobVec
-
buildToClobVec
-