Package org.h2.value
Class DataType
- java.lang.Object
-
- org.h2.value.DataType
-
public class DataType extends java.lang.ObjectThis class contains meta data information about data types, and can convert between Java objects and Values.
-
-
Field Summary
Fields Modifier and Type Field Description booleancaseSensitiveIf this data type is case sensitive.longdefaultPrecisionThe default precision.intdefaultScaleThe default scale.longmaxPrecisionThe maximum supported precision.intmaxScaleThe highest possible scale.longminPrecisionThe minimum supported precision.intminScaleThe lowest possible scale.java.lang.StringparamsThe list of parameters used in the column definition.java.lang.StringprefixThe prefix required for the SQL literal representation.booleanspecialPrecisionScaleIf precision and scale have non-standard default values.intsqlTypeThe SQL type.java.lang.StringsuffixThe suffix required for the SQL literal representation.booleansupportsPrecisionIf the precision parameter is supported.booleansupportsScaleIf the scale parameter is supported.inttypeThe value type of this data type.private static java.util.HashMap<java.lang.String,DataType>TYPES_BY_NAMEThe map of types.(package private) static DataType[]TYPES_BY_VALUE_TYPEMapping from Value type numbers to DataType.
-
Constructor Summary
Constructors Constructor Description DataType()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidadd(int type, int sqlType, DataType dataType, java.lang.String... names)private static voidaddInterval(int type)static longaddPrecision(long p1, long p2)Performs saturated addition of precision values.static booleanareStableComparable(TypeInfo type1, TypeInfo type2)Returns whether values of the specified data types have session-independent compare results.static intconvertSQLTypeToValueType(int sqlType)Convert a SQL type to a value type.static intconvertSQLTypeToValueType(int sqlType, java.lang.String sqlTypeName)Convert a SQL type to a value type using SQL type name, in order to manage SQL type extension mechanism.static intconvertSQLTypeToValueType(java.sql.SQLType sqlType)Convert a SQL type to a value type.static intconvertTypeToSQLType(TypeInfo type)Convert a value type to a SQL type.private static DataTypecreateBinary(boolean fixedLength)static DataTypecreateDate(int maxPrecision, int precision, java.lang.String prefix, boolean supportsScale, int scale, int maxScale)Create a date-time data type.private static DataTypecreateGeometry()private static DataTypecreateLob(boolean clob)static DataTypecreateNumeric(int precision, int scale)Create a numeric data type without parameters.private static DataTypecreateString(boolean caseSensitive, boolean fixedLength)private static DataTypecreateString(boolean caseSensitive, boolean fixedLength, java.lang.String prefix, java.lang.String suffix)static DataTypegetDataType(int type)Get the data type object for the given value type.static java.lang.ObjectgetDefaultForPrimitiveType(java.lang.Class<?> clazz)Get the default value in the form of a Java object for the given Java class.static DataTypegetTypeByName(java.lang.String s, Mode mode)Get a data type object from a type name.static intgetValueTypeFromResultSet(java.sql.ResultSetMetaData meta, int columnIndex)Get the SQL type from the result set meta data for the given column.static booleanhasTotalOrdering(int type)Check if the given type has total ordering.static booleanisBinaryColumn(java.sql.ResultSetMetaData meta, int column)Check whether the specified column needs the binary representation.static booleanisBinaryStringOrSpecialBinaryType(int type)Check if the given value type is a binary string type or a compatible special data type such as Java object, UUID, geometry object, or JSON.static booleanisBinaryStringType(int type)Check if the given value type is a binary string type.static booleanisCharacterStringType(int type)Check if the given value type is a character string type.static booleanisDateTimeType(int type)Check if the given value type is a date-time type (TIME, DATE, TIMESTAMP, TIMESTAMP_TZ).static booleanisIndexable(TypeInfo type)Returns whether columns with the specified data type may have an index.static booleanisIntervalType(int type)Check if the given value type is an interval type.static booleanisLargeObject(int type)Check if the given value type is a large object (BLOB or CLOB).static booleanisNumericType(int type)Check if the given value type is a numeric type.static booleanisStringType(int type)Check if the given value type is a String (VARCHAR,...).static booleanisYearMonthIntervalType(int type)Check if the given value type is a year-month interval type.static java.lang.StringsqlTypeToString(java.sql.SQLType sqlType)Convert a SQL type to a debug string.private static java.lang.StringBuilderunknownSqlTypeToString(java.lang.StringBuilder builder, java.sql.SQLType sqlType)
-
-
-
Field Detail
-
TYPES_BY_NAME
private static final java.util.HashMap<java.lang.String,DataType> TYPES_BY_NAME
The map of types.
-
TYPES_BY_VALUE_TYPE
static final DataType[] TYPES_BY_VALUE_TYPE
Mapping from Value type numbers to DataType.
-
type
public int type
The value type of this data type.
-
sqlType
public int sqlType
The SQL type.
-
minPrecision
public long minPrecision
The minimum supported precision.
-
maxPrecision
public long maxPrecision
The maximum supported precision.
-
minScale
public int minScale
The lowest possible scale.
-
maxScale
public int maxScale
The highest possible scale.
-
prefix
public java.lang.String prefix
The prefix required for the SQL literal representation.
-
suffix
public java.lang.String suffix
The suffix required for the SQL literal representation.
-
params
public java.lang.String params
The list of parameters used in the column definition.
-
caseSensitive
public boolean caseSensitive
If this data type is case sensitive.
-
supportsPrecision
public boolean supportsPrecision
If the precision parameter is supported.
-
supportsScale
public boolean supportsScale
If the scale parameter is supported.
-
defaultPrecision
public long defaultPrecision
The default precision.
-
defaultScale
public int defaultScale
The default scale.
-
specialPrecisionScale
public boolean specialPrecisionScale
If precision and scale have non-standard default values.
-
-
Method Detail
-
addInterval
private static void addInterval(int type)
-
add
private static void add(int type, int sqlType, DataType dataType, java.lang.String... names)
-
createNumeric
public static DataType createNumeric(int precision, int scale)
Create a numeric data type without parameters.- Parameters:
precision- precisionscale- scale- Returns:
- data type
-
createDate
public static DataType createDate(int maxPrecision, int precision, java.lang.String prefix, boolean supportsScale, int scale, int maxScale)
Create a date-time data type.- Parameters:
maxPrecision- maximum supported precisionprecision- default precisionprefix- the prefix for SQL literal representationsupportsScale- whether the scale parameter is supportedscale- default scalemaxScale- highest possible scale- Returns:
- data type
-
createString
private static DataType createString(boolean caseSensitive, boolean fixedLength)
-
createBinary
private static DataType createBinary(boolean fixedLength)
-
createString
private static DataType createString(boolean caseSensitive, boolean fixedLength, java.lang.String prefix, java.lang.String suffix)
-
createLob
private static DataType createLob(boolean clob)
-
createGeometry
private static DataType createGeometry()
-
getDataType
public static DataType getDataType(int type)
Get the data type object for the given value type.- Parameters:
type- the value type- Returns:
- the data type object
-
convertTypeToSQLType
public static int convertTypeToSQLType(TypeInfo type)
Convert a value type to a SQL type.- Parameters:
type- the type- Returns:
- the SQL type
-
convertSQLTypeToValueType
public static int convertSQLTypeToValueType(int sqlType, java.lang.String sqlTypeName)Convert a SQL type to a value type using SQL type name, in order to manage SQL type extension mechanism.- Parameters:
sqlType- the SQL typesqlTypeName- the SQL type name- Returns:
- the value type
-
getValueTypeFromResultSet
public static int getValueTypeFromResultSet(java.sql.ResultSetMetaData meta, int columnIndex) throws java.sql.SQLExceptionGet the SQL type from the result set meta data for the given column. This method uses the SQL type and type name.- Parameters:
meta- the meta datacolumnIndex- the column index (1, 2,...)- Returns:
- the value type
- Throws:
java.sql.SQLException- on failure
-
isBinaryColumn
public static boolean isBinaryColumn(java.sql.ResultSetMetaData meta, int column) throws java.sql.SQLExceptionCheck whether the specified column needs the binary representation.- Parameters:
meta- metadatacolumn- column index- Returns:
trueif column needs the binary representation,falseotherwise- Throws:
java.sql.SQLException- on SQL exception
-
convertSQLTypeToValueType
public static int convertSQLTypeToValueType(java.sql.SQLType sqlType)
Convert a SQL type to a value type.- Parameters:
sqlType- the SQL type- Returns:
- the value type
-
convertSQLTypeToValueType
public static int convertSQLTypeToValueType(int sqlType)
Convert a SQL type to a value type.- Parameters:
sqlType- the SQL type- Returns:
- the value type
-
sqlTypeToString
public static java.lang.String sqlTypeToString(java.sql.SQLType sqlType)
Convert a SQL type to a debug string.- Parameters:
sqlType- the SQL type- Returns:
- the textual representation
-
unknownSqlTypeToString
private static java.lang.StringBuilder unknownSqlTypeToString(java.lang.StringBuilder builder, java.sql.SQLType sqlType)
-
getTypeByName
public static DataType getTypeByName(java.lang.String s, Mode mode)
Get a data type object from a type name.- Parameters:
s- the type namemode- database mode- Returns:
- the data type object
-
isIndexable
public static boolean isIndexable(TypeInfo type)
Returns whether columns with the specified data type may have an index.- Parameters:
type- the data type- Returns:
- whether an index is allowed
-
areStableComparable
public static boolean areStableComparable(TypeInfo type1, TypeInfo type2)
Returns whether values of the specified data types have session-independent compare results.- Parameters:
type1- the first data typetype2- the second data type- Returns:
- are values have session-independent compare results
-
isDateTimeType
public static boolean isDateTimeType(int type)
Check if the given value type is a date-time type (TIME, DATE, TIMESTAMP, TIMESTAMP_TZ).- Parameters:
type- the value type- Returns:
- true if the value type is a date-time type
-
isIntervalType
public static boolean isIntervalType(int type)
Check if the given value type is an interval type.- Parameters:
type- the value type- Returns:
- true if the value type is an interval type
-
isYearMonthIntervalType
public static boolean isYearMonthIntervalType(int type)
Check if the given value type is a year-month interval type.- Parameters:
type- the value type- Returns:
- true if the value type is a year-month interval type
-
isLargeObject
public static boolean isLargeObject(int type)
Check if the given value type is a large object (BLOB or CLOB).- Parameters:
type- the value type- Returns:
- true if the value type is a lob type
-
isNumericType
public static boolean isNumericType(int type)
Check if the given value type is a numeric type.- Parameters:
type- the value type- Returns:
- true if the value type is a numeric type
-
isBinaryStringType
public static boolean isBinaryStringType(int type)
Check if the given value type is a binary string type.- Parameters:
type- the value type- Returns:
- true if the value type is a binary string type
-
isCharacterStringType
public static boolean isCharacterStringType(int type)
Check if the given value type is a character string type.- Parameters:
type- the value type- Returns:
- true if the value type is a character string type
-
isStringType
public static boolean isStringType(int type)
Check if the given value type is a String (VARCHAR,...).- Parameters:
type- the value type- Returns:
- true if the value type is a String type
-
isBinaryStringOrSpecialBinaryType
public static boolean isBinaryStringOrSpecialBinaryType(int type)
Check if the given value type is a binary string type or a compatible special data type such as Java object, UUID, geometry object, or JSON.- Parameters:
type- the value type- Returns:
- true if the value type is a binary string type or a compatible special data type
-
hasTotalOrdering
public static boolean hasTotalOrdering(int type)
Check if the given type has total ordering.- Parameters:
type- the value type- Returns:
- true if the value type has total ordering
-
addPrecision
public static long addPrecision(long p1, long p2)Performs saturated addition of precision values.- Parameters:
p1- the first summandp2- the second summand- Returns:
- the sum of summands, or
Long.MAX_VALUEif either argument is negative or sum is out of range
-
getDefaultForPrimitiveType
public static java.lang.Object getDefaultForPrimitiveType(java.lang.Class<?> clazz)
Get the default value in the form of a Java object for the given Java class.- Parameters:
clazz- the Java class- Returns:
- the default object
-
-