Package org.teiid.core.types
Class DataTypeManager
- java.lang.Object
-
- org.teiid.core.types.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataTypeManager.DataTypeAliases
static class
DataTypeManager.DefaultDataClasses
static class
DataTypeManager.DefaultDataTypes
static class
DataTypeManager.DefaultTypeCodes
static class
DataTypeManager.WeakReferenceHashedValueCache<T>
-
Field Summary
Fields Modifier and Type Field Description static String
ARRAY_SUFFIX
static String
COLLATION_LOCALE
static String
DEFAULT_COLLATION
static int
MAX_LOB_MEMORY_BYTES
static int
MAX_STRING_LENGTH
static int
MAX_TYPE_CODE
static int
MAX_VARBINARY_BYTES
static boolean
PAD_SPACE
static boolean
USE_VALUE_CACHE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
convertToRuntimeType(Object value, boolean allConversions)
Convert the value to the probable runtime type.static Class<?>
determineDataTypeClass(Object value)
Take an object and determine the MetaMatrix data type.static Set<Class<?>>
getAllDataTypeClasses()
static Set<String>
getAllDataTypeNames()
Get a set of all data type names.static Class<?>
getArrayType(Class<?> classType)
static String
getCanonicalString(String value)
static <T> T
getCanonicalValue(T value)
static Class<?>
getClass(int code)
static String
getComponentType(String srcType)
static Class<?>
getDataTypeClass(String name)
Get data type class.static String
getDataTypeName(Class<?> typeClass)
static void
getImplicitConversions(String type, Collection<String> result)
static Class<?>
getRuntimeType(Class<?> c)
static Transform
getTransform(Class<?> sourceType, Class<?> targetType)
Get a data value transformation between the sourceType and the targetType.static Transform
getTransform(String sourceTypeName, String targetTypeName)
Get a data value transformation between the sourceType with given name and the targetType of given name.static int
getTypeCode(Class<?> source)
static boolean
hasLength(String typeName)
Return true if the type may be defined with a lengthstatic boolean
isArrayType(String name)
static boolean
isExplicitConversion(String srcType, String tgtType)
static boolean
isHashable(Class<?> type)
static boolean
isImplicitConversion(String srcType, String tgtType)
static boolean
isLOB(Class<?> type)
Is the supplied class type a LOB based data type?static boolean
isLOB(String type)
static boolean
isNonComparable(String type)
static boolean
isTransformable(Class<?> sourceType, Class<?> targetType)
Does a transformation exist between the source and target type?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.static boolean
isValueCacheEnabled()
static int
nextPowOf2(int val)
static void
setValueCacheEnabled(boolean enabled)
static Object
transformValue(Object value, Class<?> targetClass)
static Object
transformValue(Object value, Class<?> sourceType, Class<?> targetClass)
-
-
-
Field Detail
-
ARRAY_SUFFIX
public static final String ARRAY_SUFFIX
- See Also:
- Constant Field Values
-
USE_VALUE_CACHE
public static final boolean USE_VALUE_CACHE
-
PAD_SPACE
public static final boolean PAD_SPACE
-
DEFAULT_COLLATION
public static final String DEFAULT_COLLATION
- See Also:
- Constant Field Values
-
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
-
MAX_TYPE_CODE
public static final int MAX_TYPE_CODE
- See Also:
- Constant Field Values
-
-
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)
-
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)
-
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 typetargetType
- 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 nametargetTypeName
- 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 typetargetType
- 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 nametargetTypeName
- Outgoing value type name- Returns:
- True if a transform exists
-
getImplicitConversions
public static void getImplicitConversions(String type, Collection<String> result)
-
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
-
transformValue
public static Object transformValue(Object value, Class<?> targetClass) throws TransformationException
- Throws:
TransformationException
-
transformValue
public static Object transformValue(Object value, Class<?> sourceType, Class<?> targetClass) throws TransformationException
- Throws:
TransformationException
-
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)
-
isHashable
public static boolean isHashable(Class<?> type)
-
hasLength
public static boolean hasLength(String typeName)
Return true if the type may be defined with a length
-
-