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 classDataTypeManager.DataTypeAliasesstatic classDataTypeManager.DefaultDataClassesstatic classDataTypeManager.DefaultDataTypesstatic classDataTypeManager.DefaultTypeCodesstatic classDataTypeManager.WeakReferenceHashedValueCache<T>
-
Field Summary
Fields Modifier and Type Field Description static StringARRAY_SUFFIXstatic StringCOLLATION_LOCALEstatic StringDEFAULT_COLLATIONstatic intMAX_LOB_MEMORY_BYTESstatic intMAX_STRING_LENGTHstatic intMAX_TYPE_CODEstatic intMAX_VARBINARY_BYTESstatic booleanPAD_SPACEstatic booleanUSE_VALUE_CACHE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectconvertToRuntimeType(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 StringgetCanonicalString(String value)static <T> TgetCanonicalValue(T value)static Class<?>getClass(int code)static StringgetComponentType(String srcType)static Class<?>getDataTypeClass(String name)Get data type class.static StringgetDataTypeName(Class<?> typeClass)static voidgetImplicitConversions(String type, Collection<String> result)static Class<?>getRuntimeType(Class<?> c)static TransformgetTransform(Class<?> sourceType, Class<?> targetType)Get a data value transformation between the sourceType and the targetType.static TransformgetTransform(String sourceTypeName, String targetTypeName)Get a data value transformation between the sourceType with given name and the targetType of given name.static intgetTypeCode(Class<?> source)static booleanhasLength(String typeName)Return true if the type may be defined with a lengthstatic booleanisArrayType(String name)static booleanisExplicitConversion(String srcType, String tgtType)static booleanisHashable(Class<?> type)static booleanisImplicitConversion(String srcType, String tgtType)static booleanisLOB(Class<?> type)Is the supplied class type a LOB based data type?static booleanisLOB(String type)static booleanisNonComparable(String type)static booleanisTransformable(Class<?> sourceType, Class<?> targetType)Does a transformation exist between the source and target type?static booleanisTransformable(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 booleanisValueCacheEnabled()static intnextPowOf2(int val)static voidsetValueCacheEnabled(boolean enabled)static ObjecttransformValue(Object value, Class<?> targetClass)static ObjecttransformValue(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
-
-