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:
  • Field Details

    • defaultNullValues

      protected Map<Class<?>,Object> defaultNullValues
    • 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.
    • dataTypesConvertedToAClass

      protected Map<Class<?>,List<Class<?>>> dataTypesConvertedToAClass
      Store the list of Classes that can be converted from to the key.
  • Constructor Details

    • ConversionManager

      public ConversionManager()
  • Method Details

    • clone

      public Object clone()
      INTERNAL:
      Overrides:
      clone in class Object
    • 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:
      convertObject in class CoreConversionManager
      Parameters:
      sourceObject - the object that must be converted
      javaClass - 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:
      getLoader in class CoreConversionManager
    • 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
    • buildNumberVec

      protected List<Class<?>> buildNumberVec()
    • buildDateTimeVec

      protected List<Class<?>> buildDateTimeVec()
    • buildDataTypesConvertedFromAClass

      protected void buildDataTypesConvertedFromAClass()
    • buildFromBooleanVec

      protected List<Class<?>> buildFromBooleanVec()
    • buildFromNumberVec

      protected List<Class<?>> buildFromNumberVec()
    • buildFromBigDecimalVec

      protected List<Class<?>> buildFromBigDecimalVec()
    • buildFromBigIntegerVec

      protected List<Class<?>> buildFromBigIntegerVec()
    • buildFromIntegerVec

      protected List<Class<?>> buildFromIntegerVec()
    • buildFromFloatVec

      protected List<Class<?>> buildFromFloatVec()
    • buildFromDoubleVec

      protected List<Class<?>> buildFromDoubleVec()
    • buildFromShortVec

      protected List<Class<?>> buildFromShortVec()
    • buildFromByteVec

      protected List<Class<?>> buildFromByteVec()
    • buildFromLongVec

      protected List<Class<?>> buildFromLongVec()
    • buildFromStringVec

      protected List<Class<?>> buildFromStringVec()
    • buildFromCharacterVec

      protected List<Class<?>> buildFromCharacterVec()
    • buildFromByteArrayVec

      protected List<Class<?>> buildFromByteArrayVec()
    • buildFromClobVec

      protected List<Class<?>> buildFromClobVec()
    • buildFromBlobVec

      protected List<Class<?>> buildFromBlobVec()
    • buildFromUtilDateVec

      protected List<Class<?>> buildFromUtilDateVec()
    • buildFromTimestampVec

      protected List<Class<?>> buildFromTimestampVec()
    • buildFromCalendarVec

      protected List<Class<?>> buildFromCalendarVec()
    • buildFromDateVec

      protected List<Class<?>> buildFromDateVec()
    • buildFromTimeVec

      protected List<Class<?>> buildFromTimeVec()
    • buildFromByteObjectArraryVec

      protected List<Class<?>> buildFromByteObjectArraryVec()
    • buildFromCharArrayVec

      protected List<Class<?>> buildFromCharArrayVec()
    • buildFromCharacterArrayVec

      protected List<Class<?>> buildFromCharacterArrayVec()
    • buildDataTypesConvertedToAClass

      protected void buildDataTypesConvertedToAClass()
    • buildAllTypesToAClassVec

      protected List<Class<?>> buildAllTypesToAClassVec()
    • buildToBigDecimalVec

      protected List<Class<?>> buildToBigDecimalVec()
    • buildToBigIntegerVec

      protected List<Class<?>> buildToBigIntegerVec()
    • buildToBooleanVec

      protected List<Class<?>> buildToBooleanVec()
    • buildToByteVec

      protected List<Class<?>> buildToByteVec()
    • buildToDoubleVec

      protected List<Class<?>> buildToDoubleVec()
    • buildToFloatVec

      protected List<Class<?>> buildToFloatVec()
    • buildToIntegerVec

      protected List<Class<?>> buildToIntegerVec()
    • buildToLongVec

      protected List<Class<?>> buildToLongVec()
    • buildToNumberVec

      protected List<Class<?>> buildToNumberVec()
    • buildToShortVec

      protected List<Class<?>> buildToShortVec()
    • buildToByteArrayVec

      protected List<Class<?>> buildToByteArrayVec()
    • buildToByteObjectArrayVec

      protected List<Class<?>> buildToByteObjectArrayVec()
    • buildToCharacterVec

      protected List<Class<?>> buildToCharacterVec()
    • buildToCharacterArrayVec

      protected List<Class<?>> buildToCharacterArrayVec()
    • buildToCharArrayVec

      protected List<Class<?>> buildToCharArrayVec()
    • buildToStringVec

      protected List<Class<?>> buildToStringVec()
    • buildToCalendarVec

      protected List<Class<?>> buildToCalendarVec()
    • buildToTimestampVec

      protected List<Class<?>> buildToTimestampVec()
    • buildToUtilDateVec

      protected List<Class<?>> buildToUtilDateVec()
    • buildToDateVec

      protected List<Class<?>> buildToDateVec()
    • buildToTimeVec

      protected List<Class<?>> buildToTimeVec()
    • buildToBlobVec

      protected List<Class<?>> buildToBlobVec()
    • buildToClobVec

      protected List<Class<?>> buildToClobVec()