Top Description Fields Constructors Methods
org.h2.value

public Class DataType

extends Object
Class Inheritance
Imports
java.sql.JDBCType, .ResultSetMetaData, .SQLException, .SQLType, .Types, java.util.HashMap, .Map, org.h2.api.ErrorCode, .H2Type, .IntervalQualifier, org.h2.engine.Constants, .Mode, org.h2.message.DbException, org.h2.util.StringUtils

This class contains meta data information about data types, and can convert between Java objects and Values.

Field Summary

Modifier and TypeField and Description
public boolean
caseSensitive

If this data type is case sensitive.

public long
defaultPrecision

The default precision.

public int
defaultScale

The default scale.

public long
maxPrecision

The maximum supported precision.

public int
maxScale

The highest possible scale.

public long
minPrecision

The minimum supported precision.

public int
minScale

The lowest possible scale.

public String
params

The list of parameters used in the column definition.

public String
prefix

The prefix required for the SQL literal representation.

public boolean
specialPrecisionScale

If precision and scale have non-standard default values.

public int
sqlType

The SQL type.

public String
suffix

The suffix required for the SQL literal representation.

public boolean
supportsPrecision

If the precision parameter is supported.

public boolean
supportsScale

If the scale parameter is supported.

public int
type

The value type of this data type.

private static final HashMap<String, DataType>
TYPES_BY_NAME

The map of types.

pack-priv static final DataType[]
TYPES_BY_VALUE_TYPE

Mapping from Value type numbers to DataType.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
add(int type, int sqlType, DataType dataType, String... names)

private static void
addInterval(int type)

public static long

Returns:

the sum of summands, or Long#MAX_VALUE if either argument is negative or sum is out of range
addPrecision
(long
the first summand
p1
,
long
the second summand
p2
)

Performs saturated addition of precision values.

public static boolean

Returns:

are values have session-independent compare results
areStableComparable
(TypeInfo
the first data type
type1
,
TypeInfo
the second data type
type2
)

Returns whether values of the specified data types have session-independent compare results.

public static int

Returns:

the value type
convertSQLTypeToValueType
(int
the SQL type
sqlType
,
String
the SQL type name
sqlTypeName
)

Convert a SQL type to a value type using SQL type name, in order to manage SQL type extension mechanism.

public static int

Returns:

the value type
convertSQLTypeToValueType
(SQLType
the SQL type
sqlType
)

Convert a SQL type to a value type.

public static int

Returns:

the value type
convertSQLTypeToValueType
(int
the SQL type
sqlType
)

Convert a SQL type to a value type.

public static int

Returns:

the SQL type
convertTypeToSQLType
(TypeInfo
the type
type
)

Convert a value type to a SQL type.

private static DataType
createBinary(boolean fixedLength)

public static DataType

Returns:

data type
createDate
(int
maximum supported precision
maxPrecision
,
int
default precision
precision
,
String
the prefix for SQL literal representation
prefix
,
boolean
whether the scale parameter is supported
supportsScale
,
int
default scale
scale
,
int
highest possible scale
maxScale
)

Create a date-time data type.

private static DataType
private static DataType
createLob(boolean clob)

public static DataType

Returns:

data type
createNumeric
(int
precision
precision
,
int
scale
scale
)

Create a numeric data type without parameters.

private static DataType
createString(boolean caseSensitive, boolean fixedLength)

private static DataType
createString(boolean caseSensitive, boolean fixedLength, String prefix, String suffix)

public static DataType

Returns:

the data type object
getDataType
(int
the value type
type
)

Get the data type object for the given value type.

public static Object

Returns:

the default object
getDefaultForPrimitiveType
(Class<?>
the Java class
clazz
)

Get the default value in the form of a Java object for the given Java class.

public static DataType

Returns:

the data type object
getTypeByName
(String
the type name
s
,
Mode
database mode
mode
)

Get a data type object from a type name.

public static int

Returns:

the value type
getValueTypeFromResultSet
(ResultSetMetaData
the meta data
meta
,
int
the column index (1, 2,...)
columnIndex
)

Get the SQL type from the result set meta data for the given column.

public static boolean

Returns:

true if the value type has total ordering
hasTotalOrdering
(int
the value type
type
)

Check if the given type has total ordering.

public static boolean

Returns:

true if column needs the binary representation, false otherwise
isBinaryColumn
(ResultSetMetaData
metadata
meta
,
int
column index
column
)

Check whether the specified column needs the binary representation.

public static boolean

Returns:

true if the value type is a binary string type or a compatible special data type
isBinaryStringOrSpecialBinaryType
(int
the value type
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.

public static boolean

Returns:

true if the value type is a binary string type
isBinaryStringType
(int
the value type
type
)

Check if the given value type is a binary string type.

public static boolean

Returns:

true if the value type is a character string type
isCharacterStringType
(int
the value type
type
)

Check if the given value type is a character string type.

public static boolean

Returns:

true if the value type is a date-time type
isDateTimeType
(int
the value type
type
)

Check if the given value type is a date-time type (TIME, DATE, TIMESTAMP, TIMESTAMP_TZ).

public static boolean

Returns:

whether an index is allowed
isIndexable
(TypeInfo
the data type
type
)

Returns whether columns with the specified data type may have an index.

public static boolean

Returns:

true if the value type is an interval type
isIntervalType
(int
the value type
type
)

Check if the given value type is an interval type.

public static boolean

Returns:

true if the value type is a lob type
isLargeObject
(int
the value type
type
)

Check if the given value type is a large object (BLOB or CLOB).

public static boolean

Returns:

true if the value type is a numeric type
isNumericType
(int
the value type
type
)

Check if the given value type is a numeric type.

public static boolean

Returns:

true if the value type is a String type
isStringType
(int
the value type
type
)

Check if the given value type is a String (VARCHAR,...).

public static boolean

Returns:

true if the value type is a year-month interval type
isYearMonthIntervalType
(int
the value type
type
)

Check if the given value type is a year-month interval type.

public static String

Returns:

the textual representation
sqlTypeToString
(SQLType
the SQL type
sqlType
)

Convert a SQL type to a debug string.

private static StringBuilder
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

caseSensitiveback to summary
public boolean caseSensitive

If this data type is case sensitive.

defaultPrecisionback to summary
public long defaultPrecision

The default precision.

defaultScaleback to summary
public int defaultScale

The default scale.

maxPrecisionback to summary
public long maxPrecision

The maximum supported precision.

maxScaleback to summary
public int maxScale

The highest possible scale.

minPrecisionback to summary
public long minPrecision

The minimum supported precision.

minScaleback to summary
public int minScale

The lowest possible scale.

paramsback to summary
public String params

The list of parameters used in the column definition.

prefixback to summary
public String prefix

The prefix required for the SQL literal representation.

specialPrecisionScaleback to summary
public boolean specialPrecisionScale

If precision and scale have non-standard default values.

sqlTypeback to summary
public int sqlType

The SQL type.

suffixback to summary
public String suffix

The suffix required for the SQL literal representation.

supportsPrecisionback to summary
public boolean supportsPrecision

If the precision parameter is supported.

supportsScaleback to summary
public boolean supportsScale

If the scale parameter is supported.

typeback to summary
public int type

The value type of this data type.

TYPES_BY_NAMEback to summary
private static final HashMap<String, DataType> TYPES_BY_NAME

The map of types.

TYPES_BY_VALUE_TYPEback to summary
pack-priv static final DataType[] TYPES_BY_VALUE_TYPE

Mapping from Value type numbers to DataType.

Constructor Detail

DataTypeback to summary
public DataType()

Method Detail

addback to summary
private static void add(int type, int sqlType, DataType dataType, String... names)
addIntervalback to summary
private static void addInterval(int type)
addPrecisionback to summary
public static long addPrecision(long p1, long p2)

Performs saturated addition of precision values.

Parameters
p1:long

the first summand

p2:long

the second summand

Returns:long

the sum of summands, or Long#MAX_VALUE if either argument is negative or sum is out of range

areStableComparableback to summary
public static boolean areStableComparable(TypeInfo type1, TypeInfo type2)

Returns whether values of the specified data types have session-independent compare results.

Parameters
type1:TypeInfo

the first data type

type2:TypeInfo

the second data type

Returns:boolean

are values have session-independent compare results

convertSQLTypeToValueTypeback to summary
public static int convertSQLTypeToValueType(int sqlType, String sqlTypeName)

Convert a SQL type to a value type using SQL type name, in order to manage SQL type extension mechanism.

Parameters
sqlType:int

the SQL type

sqlTypeName:String

the SQL type name

Returns:int

the value type

convertSQLTypeToValueTypeback to summary
public static int convertSQLTypeToValueType(SQLType sqlType)

Convert a SQL type to a value type.

Parameters
sqlType:SQLType

the SQL type

Returns:int

the value type

convertSQLTypeToValueTypeback to summary
public static int convertSQLTypeToValueType(int sqlType)

Convert a SQL type to a value type.

Parameters
sqlType:int

the SQL type

Returns:int

the value type

convertTypeToSQLTypeback to summary
public static int convertTypeToSQLType(TypeInfo type)

Convert a value type to a SQL type.

Parameters
type:TypeInfo

the type

Returns:int

the SQL type

createBinaryback to summary
private static DataType createBinary(boolean fixedLength)
createDateback to summary
public static DataType createDate(int maxPrecision, int precision, String prefix, boolean supportsScale, int scale, int maxScale)

Create a date-time data type.

Parameters
maxPrecision:int

maximum supported precision

precision:int

default precision

prefix:String

the prefix for SQL literal representation

supportsScale:boolean

whether the scale parameter is supported

scale:int

default scale

maxScale:int

highest possible scale

Returns:DataType

data type

createGeometryback to summary
private static DataType createGeometry()
createLobback to summary
private static DataType createLob(boolean clob)
createNumericback to summary
public static DataType createNumeric(int precision, int scale)

Create a numeric data type without parameters.

Parameters
precision:int

precision

scale:int

scale

Returns:DataType

data type

createStringback to summary
private static DataType createString(boolean caseSensitive, boolean fixedLength)
createStringback to summary
private static DataType createString(boolean caseSensitive, boolean fixedLength, String prefix, String suffix)
getDataTypeback to summary
public static DataType getDataType(int type)

Get the data type object for the given value type.

Parameters
type:int

the value type

Returns:DataType

the data type object

getDefaultForPrimitiveTypeback to summary
public static Object getDefaultForPrimitiveType(Class<?> clazz)

Get the default value in the form of a Java object for the given Java class.

Parameters
clazz:Class<?>

the Java class

Returns:Object

the default object

getTypeByNameback to summary
public static DataType getTypeByName(String s, Mode mode)

Get a data type object from a type name.

Parameters
s:String

the type name

mode:Mode

database mode

Returns:DataType

the data type object

getValueTypeFromResultSetback to summary
public static int getValueTypeFromResultSet(ResultSetMetaData meta, int columnIndex) throws SQLException

Get the SQL type from the result set meta data for the given column. This method uses the SQL type and type name.

Parameters
meta:ResultSetMetaData

the meta data

columnIndex:int

the column index (1, 2,...)

Returns:int

the value type

Exceptions
SQLException:
on failure
hasTotalOrderingback to summary
public static boolean hasTotalOrdering(int type)

Check if the given type has total ordering.

Parameters
type:int

the value type

Returns:boolean

true if the value type has total ordering

isBinaryColumnback to summary
public static boolean isBinaryColumn(ResultSetMetaData meta, int column) throws SQLException

Check whether the specified column needs the binary representation.

Parameters
meta:ResultSetMetaData

metadata

column:int

column index

Returns:boolean

true if column needs the binary representation, false otherwise

Exceptions
SQLException:
on SQL exception
isBinaryStringOrSpecialBinaryTypeback to summary
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:int

the value type

Returns:boolean

true if the value type is a binary string type or a compatible special data type

isBinaryStringTypeback to summary
public static boolean isBinaryStringType(int type)

Check if the given value type is a binary string type.

Parameters
type:int

the value type

Returns:boolean

true if the value type is a binary string type

isCharacterStringTypeback to summary
public static boolean isCharacterStringType(int type)

Check if the given value type is a character string type.

Parameters
type:int

the value type

Returns:boolean

true if the value type is a character string type

isDateTimeTypeback to summary
public static boolean isDateTimeType(int type)

Check if the given value type is a date-time type (TIME, DATE, TIMESTAMP, TIMESTAMP_TZ).

Parameters
type:int

the value type

Returns:boolean

true if the value type is a date-time type

isIndexableback to summary
public static boolean isIndexable(TypeInfo type)

Returns whether columns with the specified data type may have an index.

Parameters
type:TypeInfo

the data type

Returns:boolean

whether an index is allowed

isIntervalTypeback to summary
public static boolean isIntervalType(int type)

Check if the given value type is an interval type.

Parameters
type:int

the value type

Returns:boolean

true if the value type is an interval type

isLargeObjectback to summary
public static boolean isLargeObject(int type)

Check if the given value type is a large object (BLOB or CLOB).

Parameters
type:int

the value type

Returns:boolean

true if the value type is a lob type

isNumericTypeback to summary
public static boolean isNumericType(int type)

Check if the given value type is a numeric type.

Parameters
type:int

the value type

Returns:boolean

true if the value type is a numeric type

isStringTypeback to summary
public static boolean isStringType(int type)

Check if the given value type is a String (VARCHAR,...).

Parameters
type:int

the value type

Returns:boolean

true if the value type is a String type

isYearMonthIntervalTypeback to summary
public static boolean isYearMonthIntervalType(int type)

Check if the given value type is a year-month interval type.

Parameters
type:int

the value type

Returns:boolean

true if the value type is a year-month interval type

sqlTypeToStringback to summary
public static String sqlTypeToString(SQLType sqlType)

Convert a SQL type to a debug string.

Parameters
sqlType:SQLType

the SQL type

Returns:String

the textual representation

unknownSqlTypeToStringback to summary
private static StringBuilder unknownSqlTypeToString(StringBuilder builder, SQLType sqlType)