org.h2.value

## Class DataType

- java.lang.Object
- - org.h2.value.DataType

    public class DataType
    extends java.lang.Object

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

### Field Summary

Fields
`boolean` `autoIncrement` If this is an autoincrement type.
`boolean` `caseSensitive` If this data type is an autoincrement type.
`boolean` `decimal` If this is a numeric type.
`int` `defaultDisplaySize` The default display size.
`long` `defaultPrecision` The default precision.
`int` `defaultScale` The default scale.
`static java.lang.Class<?>` `GEOMETRY_CLASS` The Geometry class.
`boolean` `hidden` If this data type should not be listed in the database meta data.
`long` `maxPrecision` The maximum supported precision.
`int` `maxScale` The highest possible scale.
`int` `memory` The number of bytes required for an object.
`int` `minScale` The lowest possible scale.
`java.lang.String` `name` The data type name.
`java.lang.String` `params` The list of parameters used in the column definition.
`java.lang.String` `prefix` The prefix required for the SQL literal representation.
`int` `sqlType` The SQL type.
`int` `sqlTypePos` How closely the data type maps to the corresponding JDBC SQL type (low is best).
`java.lang.String` `suffix` The suffix required for the SQL literal representation.
`boolean` `supportsPrecision` If the precision parameter is supported.
`boolean` `supportsScale` If the scale parameter is supported.
`int` `type` The value type of this data type.
`static int` `TYPE_RESULT_SET` This constant is used to represent the type of a ResultSet.

### Constructor Summary

Constructors
Constructor and Description
`DataType()`

### Method Summary

Methods
`static int` `convertSQLTypeToValueType(int sqlType)` Convert a SQL type to a value type.
`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.
`static java.lang.Object` `convertTo(JdbcConnection conn, Value v, java.lang.Class<?> paramClass)` Convert a value to the specified class.
`static Value` `convertToValue(SessionInterface session, java.lang.Object x, int type)` Convert a Java object to a value.
`static int` `convertTypeToSQLType(int type)` Convert a value type to a SQL type.
`static int` `getAddProofType(int type)` Get the data type that will not overflow when calling 'add' 2 billion times.
`static DataType` `getDataType(int type)` Get the data type object for the given value type.
`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.
`static DataType` `getTypeByName(java.lang.String s, Mode mode)` Get a data type object from a type name.
`static java.lang.String` `getTypeClassName(int type)` Get the name of the Java class for the given value type.
`static int` `getTypeFromClass(java.lang.Class<?> x)` Get the value type for the given Java class.
`static java.util.ArrayList<DataType>` `getTypes()` Get the list of data types.
`static int` `getValueTypeFromResultSet(java.sql.ResultSetMetaData meta, int columnIndex)` Get the SQL type from the result set meta data for the given column.
`static boolean` `isGeometry(java.lang.Object x)` Check whether a given object is a Geometry object.
`static boolean` `isGeometryClass(java.lang.Class<?> x)` Check whether a given class matches the Geometry class.
`static boolean` `isLargeObject(int type)` Check if the given value type is a large object (BLOB or CLOB).
`static boolean` `isStringType(int type)` Check if the given value type is a String (VARCHAR,...).
`static Value` `readValue(SessionInterface session, java.sql.ResultSet rs, int columnIndex, int type)` Read a value from the given result set.
`static boolean` `supportsAdd(int type)` Check if the given value type supports the add operation.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### TYPE_RESULT_SET

    public static final int TYPE_RESULT_SET

This constant is used to represent the type of a ResultSet. There is no equivalent java.sql.Types value, but Oracle uses it to represent a ResultSet (OracleTypes.CURSOR = -10).

See Also:
  Constant Field Values

#### GEOMETRY_CLASS

    public static final java.lang.Class<?> GEOMETRY_CLASS

The Geometry class. This object is null if the jts jar file is not in the classpath.

#### type

    public int type

The value type of this data type.

#### name

    public java.lang.String name

The data type name.

#### sqlType

    public int sqlType

The SQL type.

#### sqlTypePos

    public int sqlTypePos

How closely the data type maps to the corresponding JDBC SQL type (low is best).

#### maxPrecision

    public long maxPrecision

The maximum supported precision.

#### minScale

    public int minScale

The lowest possible scale.

#### maxScale

    public int maxScale

The highest possible scale.

#### decimal

    public boolean decimal

If this is a numeric type.

#### 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.

#### autoIncrement

    public boolean autoIncrement

If this is an autoincrement type.

#### caseSensitive

    public boolean caseSensitive

If this data type is an autoincrement type.

#### 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.

#### defaultDisplaySize

    public int defaultDisplaySize

The default display size.

#### hidden

    public boolean hidden

If this data type should not be listed in the database meta data.

#### memory

    public int memory

The number of bytes required for an object.

### Constructor Detail

#### DataType

    public DataType()

### Method Detail

#### getTypes

    public static java.util.ArrayList<DataType> getTypes()

Get the list of data types.

Returns:
  the list

#### readValue

    public static Value readValue(SessionInterface session,
                  java.sql.ResultSet rs,
                  int columnIndex,
                  int type)

Read a value from the given result set.

Parameters:
  `session` - the session
  `rs` - the result set
  `columnIndex` - the column index (1 based)
  `type` - the data type
Returns:
  the value

#### getTypeClassName

    public static java.lang.String getTypeClassName(int type)

Get the name of the Java class for the given value type.

Parameters:
  `type` - the value type
Returns:
  the class name

#### 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(int type)

Convert a value type to a SQL type.

Parameters:
  `type` - the value 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 type
  `sqlTypeName` - the SQL type name
Returns:
  the value type

#### getValueTypeFromResultSet

    public static int getValueTypeFromResultSet(java.sql.ResultSetMetaData meta,
                                int columnIndex)
                                         throws java.sql.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` - the meta data
  `columnIndex` - the column index (1, 2,...)
Returns:
  the value type
Throws:
  `java.sql.SQLException`

#### convertSQLTypeToValueType

    public static int convertSQLTypeToValueType(int sqlType)

Convert a SQL type to a value type.

Parameters:
  `sqlType` - the SQL type
Returns:
  the value type

#### getTypeFromClass

    public static int getTypeFromClass(java.lang.Class<?> x)

Get the value type for the given Java class.

Parameters:
  `x` - the Java class
Returns:
  the value type

#### convertToValue

    public static Value convertToValue(SessionInterface session,
                       java.lang.Object x,
                       int type)

Convert a Java object to a value.

Parameters:
  `session` - the session
  `x` - the value
  `type` - the value type
Returns:
  the value

#### isGeometryClass

    public static boolean isGeometryClass(java.lang.Class<?> x)

Check whether a given class matches the Geometry class.

Parameters:
  `x` - the class
Returns:
  true if it is a Geometry class

#### isGeometry

    public static boolean isGeometry(java.lang.Object x)

Check whether a given object is a Geometry object.

Parameters:
  `x` - the the object
Returns:
  true if it is a Geometry object

#### getTypeByName

    public static DataType getTypeByName(java.lang.String s,
                         Mode mode)

Get a data type object from a type name.

Parameters:
  `s` - the type name
  `mode` - database mode
Returns:
  the data type object

#### 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

#### 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

#### supportsAdd

    public static boolean supportsAdd(int type)

Check if the given value type supports the add operation.

Parameters:
  `type` - the value type
Returns:
  true if add is supported

#### getAddProofType

    public static int getAddProofType(int type)

Get the data type that will not overflow when calling 'add' 2 billion times.

Parameters:
  `type` - the value type
Returns:
  the data type that supports adding

#### 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

#### convertTo

    public static java.lang.Object convertTo(JdbcConnection conn,
                             Value v,
                             java.lang.Class<?> paramClass)

Convert a value to the specified class.

Parameters:
  `conn` - the database connection
  `v` - the value
  `paramClass` - the target class
Returns:
  the converted object