Class ConversionManager

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    JPAConversionManager, XMLConversionManager

    public class ConversionManager
    extends CoreConversionManager
    implements java.io.Serializable, java.lang.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 Detail

      • defaultNullValues

        protected java.util.Map defaultNullValues
      • shouldUseClassLoaderFromCurrentThread

        protected boolean shouldUseClassLoaderFromCurrentThread
        This flag is here if the Conversion Manager should use the class loader on the thread when loading classes.
      • loader

        protected java.lang.ClassLoader loader
      • dataTypesConvertedFromAClass

        protected java.util.Hashtable dataTypesConvertedFromAClass
        Store the list of Classes that can be converted to from the key.
      • dataTypesConvertedToAClass

        protected java.util.Hashtable dataTypesConvertedToAClass
        Store the list of Classes that can be converted from to the key.
    • Constructor Detail

      • ConversionManager

        public ConversionManager()
    • Method Detail

      • clone

        public java.lang.Object clone()
        INTERNAL:
        Overrides:
        clone in class java.lang.Object
      • convertObject

        public java.lang.Object convertObject​(java.lang.Object sourceObject,
                                              java.lang.Class javaClass)
                                       throws ConversionException
        Convert the object to the appropriate type by invoking the appropriate ConversionManager method
        Specified by:
        convertObject in class CoreConversionManager
        Parameters:
        object - - the object that must be converted
        javaClass - - the class that the object must be converted to
        Returns:
        - the newly converted object
        Throws:
        ConversionException
      • convertObjectToBigDecimal

        protected java.math.BigDecimal convertObjectToBigDecimal​(java.lang.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 java.math.BigInteger convertObjectToBigInteger​(java.lang.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 java.lang.Boolean convertObjectToBoolean​(java.lang.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 java.lang.Byte convertObjectToByte​(java.lang.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
      • convertObjectToByteArray

        protected byte[] convertObjectToByteArray​(java.lang.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 java.lang.Byte[] convertObjectToByteObjectArray​(java.lang.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 java.util.Calendar convertObjectToCalendar​(java.lang.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 java.lang.Character convertObjectToChar​(java.lang.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 java.lang.Character[] convertObjectToCharacterArray​(java.lang.Object sourceObject)
                                                               throws ConversionException
        Build a valid instance of a Character array from the given object.
        Throws:
        ConversionException
      • convertObjectToCharArray

        protected char[] convertObjectToCharArray​(java.lang.Object sourceObject)
                                           throws ConversionException
        Build a valid instance of a char array from the given object.
        Throws:
        ConversionException
      • convertObjectToClass

        protected java.lang.Class convertObjectToClass​(java.lang.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 java.sql.Date convertObjectToDate​(java.lang.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 java.lang.Double convertObjectToDouble​(java.lang.Object sourceObject)
                                                  throws ConversionException
        Convert the object to an instance of Double.
        Parameters:
        sourceObject - Object of type String or Number.
        Throws:
        ConversionException
      • convertObjectToFloat

        protected java.lang.Float convertObjectToFloat​(java.lang.Object sourceObject)
                                                throws ConversionException
        Build a valid Float instance from a String or another Number instance.
        Throws:
        ConversionException
      • convertObjectToInteger

        protected java.lang.Integer convertObjectToInteger​(java.lang.Object sourceObject)
                                                    throws ConversionException
        Build a valid Integer instance from a String or another Number instance.
        Throws:
        ConversionException
      • convertObjectToLong

        protected java.lang.Long convertObjectToLong​(java.lang.Object sourceObject)
                                              throws ConversionException
        Build a valid Long instance from a String or another Number instance.
        Throws:
        ConversionException
      • convertObjectToNumber

        protected java.math.BigDecimal convertObjectToNumber​(java.lang.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
      • convertObjectToShort

        protected java.lang.Short convertObjectToShort​(java.lang.Object sourceObject)
                                                throws ConversionException
        INTERNAL: Build a valid Short instance from a String or another Number instance.
        Throws:
        ConversionException
      • convertObjectToString

        protected java.lang.String convertObjectToString​(java.lang.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 java.sql.Time convertObjectToTime​(java.lang.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 java.sql.Timestamp convertObjectToTimestamp​(java.lang.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 java.time.LocalDate convertObjectToLocalDate​(java.lang.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 java.time.LocalTime convertObjectToLocalTime​(java.lang.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 java.time.LocalDateTime convertObjectToLocalDateTime​(java.lang.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 java.time.OffsetDateTime convertObjectToOffsetDateTime​(java.lang.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 java.time.OffsetTime convertObjectToOffsetTime​(java.lang.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 java.net.URL convertObjectToUrl​(java.lang.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
      • convertObjectToUtilDate

        protected java.util.Date convertObjectToUtilDate​(java.lang.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 java.lang.Class convertClassNameToClass​(java.lang.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 java.lang.Object getDefaultNullValue​(java.lang.Class 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 java.util.Map 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.
      • hasDefaultNullValues

        public boolean hasDefaultNullValues()
        INTERNAL
      • loadClass

        public static java.lang.Class loadClass​(java.lang.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 java.lang.Class getObjectClass​(java.lang.Class javaClass)
        INTERNAL: This is used to determine the wrapper class for a primitive.
      • getPrimitiveClass

        public static java.lang.Class getPrimitiveClass​(java.lang.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​(java.lang.Class theClass,
                                        java.lang.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​(java.util.Map 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​(java.lang.ClassLoader classLoader)
        INTERNAL:
      • setDefaultLoader

        public static void setDefaultLoader​(java.lang.ClassLoader classLoader)
        INTERNAL: Set the default class loader to use if no instance-level loader is set
      • getDefaultLoader

        public static java.lang.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 java.util.Vector getDataTypesConvertedFrom​(java.lang.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 java.util.Vector getDataTypesConvertedTo​(java.lang.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 java.util.Vector buildNumberVec()
      • buildDateTimeVec

        protected java.util.Vector buildDateTimeVec()
      • buildDataTypesConvertedFromAClass

        protected void buildDataTypesConvertedFromAClass()
      • buildFromBooleanVec

        protected java.util.Vector buildFromBooleanVec()
      • buildFromNumberVec

        protected java.util.Vector buildFromNumberVec()
      • buildFromBigDecimalVec

        protected java.util.Vector buildFromBigDecimalVec()
      • buildFromBigIntegerVec

        protected java.util.Vector buildFromBigIntegerVec()
      • buildFromIntegerVec

        protected java.util.Vector buildFromIntegerVec()
      • buildFromFloatVec

        protected java.util.Vector buildFromFloatVec()
      • buildFromDoubleVec

        protected java.util.Vector buildFromDoubleVec()
      • buildFromShortVec

        protected java.util.Vector buildFromShortVec()
      • buildFromByteVec

        protected java.util.Vector buildFromByteVec()
      • buildFromLongVec

        protected java.util.Vector buildFromLongVec()
      • buildFromStringVec

        protected java.util.Vector buildFromStringVec()
      • buildFromCharacterVec

        protected java.util.Vector buildFromCharacterVec()
      • buildFromByteArrayVec

        protected java.util.Vector buildFromByteArrayVec()
      • buildFromClobVec

        protected java.util.Vector buildFromClobVec()
      • buildFromBlobVec

        protected java.util.Vector buildFromBlobVec()
      • buildFromUtilDateVec

        protected java.util.Vector buildFromUtilDateVec()
      • buildFromTimestampVec

        protected java.util.Vector buildFromTimestampVec()
      • buildFromCalendarVec

        protected java.util.Vector buildFromCalendarVec()
      • buildFromDateVec

        protected java.util.Vector buildFromDateVec()
      • buildFromTimeVec

        protected java.util.Vector buildFromTimeVec()
      • buildFromByteObjectArraryVec

        protected java.util.Vector buildFromByteObjectArraryVec()
      • buildFromCharArrayVec

        protected java.util.Vector buildFromCharArrayVec()
      • buildFromCharacterArrayVec

        protected java.util.Vector buildFromCharacterArrayVec()
      • buildDataTypesConvertedToAClass

        protected void buildDataTypesConvertedToAClass()
      • buildAllTypesToAClassVec

        protected java.util.Vector buildAllTypesToAClassVec()
      • buildToBigDecimalVec

        protected java.util.Vector buildToBigDecimalVec()
      • buildToBigIntegerVec

        protected java.util.Vector buildToBigIntegerVec()
      • buildToBooleanVec

        protected java.util.Vector buildToBooleanVec()
      • buildToByteVec

        protected java.util.Vector buildToByteVec()
      • buildToDoubleVec

        protected java.util.Vector buildToDoubleVec()
      • buildToFloatVec

        protected java.util.Vector buildToFloatVec()
      • buildToIntegerVec

        protected java.util.Vector buildToIntegerVec()
      • buildToLongVec

        protected java.util.Vector buildToLongVec()
      • buildToNumberVec

        protected java.util.Vector buildToNumberVec()
      • buildToShortVec

        protected java.util.Vector buildToShortVec()
      • buildToByteArrayVec

        protected java.util.Vector buildToByteArrayVec()
      • buildToByteObjectArrayVec

        protected java.util.Vector buildToByteObjectArrayVec()
      • buildToCharacterVec

        protected java.util.Vector buildToCharacterVec()
      • buildToCharacterArrayVec

        protected java.util.Vector buildToCharacterArrayVec()
      • buildToCharArrayVec

        protected java.util.Vector buildToCharArrayVec()
      • buildToStringVec

        protected java.util.Vector buildToStringVec()
      • buildToCalendarVec

        protected java.util.Vector buildToCalendarVec()
      • buildToTimestampVec

        protected java.util.Vector buildToTimestampVec()
      • buildToUtilDateVec

        protected java.util.Vector buildToUtilDateVec()
      • buildToDateVec

        protected java.util.Vector buildToDateVec()
      • buildToTimeVec

        protected java.util.Vector buildToTimeVec()
      • buildToBlobVec

        protected java.util.Vector buildToBlobVec()
      • buildToClobVec

        protected java.util.Vector buildToClobVec()