Class DataTypeManager


  • public class DataTypeManager
    extends Object

    This class manages data type, conversions between data types, and comparators for data types. In the future other data type information may be managed here.

    In general, methods are provided to refer to types either by Class, or by Class name. The benefit of the Class name option is that the user does not need to load the Class object, which may not be in the classpath. The advantage of the Class option is speed. TODO: refactor the string/class/code into an enum

    • Field Detail

      • USE_VALUE_CACHE

        public static final boolean USE_VALUE_CACHE
      • PAD_SPACE

        public static final boolean PAD_SPACE
      • COLLATION_LOCALE

        public static final String COLLATION_LOCALE
      • MAX_STRING_LENGTH

        public static final int MAX_STRING_LENGTH
      • MAX_VARBINARY_BYTES

        public static final int MAX_VARBINARY_BYTES
      • MAX_LOB_MEMORY_BYTES

        public static final int MAX_LOB_MEMORY_BYTES
    • Method Detail

      • nextPowOf2

        public static int nextPowOf2​(int val)
      • getTypeCode

        public static int getTypeCode​(Class<?> source)
      • getClass

        public static Class<?> getClass​(int code)
      • getAllDataTypeNames

        public static Set<String> getAllDataTypeNames()
        Get a set of all data type names.
        Returns:
        Set of data type names (String)
      • getAllDataTypeClasses

        public static Set<Class<?>> getAllDataTypeClasses()
      • getDataTypeClass

        public static Class<?> getDataTypeClass​(String name)
        Get data type class.
        IMPORTANT: only valid for default runtime types
        Parameters:
        name - Data type name
        Returns:
        Data type class
      • isArrayType

        public static boolean isArrayType​(String name)
      • getDataTypeName

        public static String getDataTypeName​(Class<?> typeClass)
      • determineDataTypeClass

        public static Class<?> determineDataTypeClass​(Object value)
        Take an object and determine the MetaMatrix data type. In most cases, this is simply the class of the object. Some special cases are when the value is of type Object or Null.
      • getTransform

        public static Transform getTransform​(Class<?> sourceType,
                                             Class<?> targetType)
        Get a data value transformation between the sourceType and the targetType.
        Parameters:
        sourceType - Incoming value type
        targetType - Outgoing value type
        Returns:
        A transform if one exists, null otherwise
      • getTransform

        public static Transform getTransform​(String sourceTypeName,
                                             String targetTypeName)
        Get a data value transformation between the sourceType with given name and the targetType of given name. The Class for source and target type are not needed to do this lookup.
        Parameters:
        sourceTypeName - Incoming value type name
        targetTypeName - Outgoing value type name
        Returns:
        A transform if one exists, null otherwise
      • isTransformable

        public static boolean isTransformable​(Class<?> sourceType,
                                              Class<?> targetType)
        Does a transformation exist between the source and target type?
        Parameters:
        sourceType - Incoming value type
        targetType - Outgoing value type
        Returns:
        True if a transform exists
      • isTransformable

        public static boolean isTransformable​(String sourceTypeName,
                                              String targetTypeName)
        Does a transformation exist between the source and target type of given names? The Class for source and target type are not needed to do this lookup.
        Parameters:
        sourceTypeName - Incoming value type name
        targetTypeName - Outgoing value type name
        Returns:
        True if a transform exists
      • getImplicitConversions

        public static void getImplicitConversions​(String type,
                                                  Collection<String> result)
      • isImplicitConversion

        public static boolean isImplicitConversion​(String srcType,
                                                   String tgtType)
      • getComponentType

        public static String getComponentType​(String srcType)
      • isExplicitConversion

        public static boolean isExplicitConversion​(String srcType,
                                                   String tgtType)
      • isLOB

        public static boolean isLOB​(Class<?> type)
        Is the supplied class type a LOB based data type?
        Parameters:
        type -
        Returns:
        true if yes; false otherwise
      • isLOB

        public static boolean isLOB​(String type)
      • convertToRuntimeType

        public static Object convertToRuntimeType​(Object value,
                                                  boolean allConversions)
        Convert the value to the probable runtime type.
        Parameters:
        allConversions - if false only lob conversions will be used
      • getRuntimeType

        public static Class<?> getRuntimeType​(Class<?> c)
      • isNonComparable

        public static boolean isNonComparable​(String type)
      • setValueCacheEnabled

        public static void setValueCacheEnabled​(boolean enabled)
      • isValueCacheEnabled

        public static final boolean isValueCacheEnabled()
      • getCanonicalValue

        public static final <T> T getCanonicalValue​(T value)
      • getCanonicalString

        public static final String getCanonicalString​(String value)
      • isHashable

        public static boolean isHashable​(Class<?> type)
      • getArrayType

        public static Class<?> getArrayType​(Class<?> classType)
      • hasLength

        public static boolean hasLength​(String typeName)
        Return true if the type may be defined with a length