com.akiban.sql.types
Class DataTypeDescriptor

java.lang.Object
  extended by com.akiban.sql.types.DataTypeDescriptor

public final class DataTypeDescriptor
extends Object

DataTypeDescriptor describes a runtime SQL type. It consists of a catalog type (TypeDescriptor) and runtime attributes. The list of runtime attributes is:

A DataTypeDescriptor is immutable.


Field Summary
static DataTypeDescriptor INTEGER
          Runtime INTEGER type that is nullable.
static DataTypeDescriptor INTEGER_NOT_NULL
          Runtime INTEGER type that is not nullable.
static int MAXIMUM_WIDTH_UNKNOWN
           
static DataTypeDescriptor MEDIUMINT
           
static DataTypeDescriptor MEDIUMINT_NOT_NULL
           
static DataTypeDescriptor SMALLINT
          Runtime SMALLINT type that is nullable.
static DataTypeDescriptor SMALLINT_NOT_NULL
          Runtime INTEGER type that is not nullable.
 
Constructor Summary
DataTypeDescriptor(DataTypeDescriptor source, CharacterTypeAttributes characterAttributes)
           
DataTypeDescriptor(TypeId typeId, boolean isNullable)
           
DataTypeDescriptor(TypeId typeId, boolean isNullable, int maximumWidth)
          Constructor for use with non-numeric types
DataTypeDescriptor(TypeId typeId, boolean isNullable, int maximumWidth, CharacterTypeAttributes characterAttributes)
           
DataTypeDescriptor(TypeId typeId, int precision, int scale, boolean isNullable, int maximumWidth)
          Constructor for use with numeric types
 
Method Summary
 boolean comparable(DataTypeDescriptor compareWithDTD, boolean forEquals)
          Check if this type is comparable with the passed type.
static int computeMaxWidth(int precision, int scale)
          Compute the maximum width (column display width) of a decimal or numeric data value, given its precision and scale.
 boolean equals(Object other)
          Compare if two DataTypeDescriptors are exactly the same
static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType)
          Get a descriptor that corresponds to a nullable builtin JDBC type.
static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType, boolean isNullable)
          Get a descriptor that corresponds to a builtin JDBC type.
static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType, boolean isNullable, int maxLength)
          Get a descriptor that corresponds to a builtin JDBC type.
static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType, int length)
          Get a descriptor that corresponds to a nullable builtin variable length JDBC type.
static DataTypeDescriptor getBuiltInDataTypeDescriptor(String sqlTypeName)
          Get a DataTypeDescriptor that corresponds to a nullable builtin SQL type.
static DataTypeDescriptor getBuiltInDataTypeDescriptor(String sqlTypeName, int length)
          Get a DataTypeDescriptor that corresponds to a builtin SQL type Collation type will be UCS_BASIC and derivation IMPLICIT.
 CharacterTypeAttributes getCharacterAttributes()
           
 DataTypeDescriptor getDominantType(DataTypeDescriptor otherDTS)
          Get the dominant type (DataTypeDescriptor) of the 2.
 String getFullSQLTypeName()
          Return the SQL type name and, if applicable, scale/precision/length for this DataTypeDescriptor.
 int getJDBCTypeId()
          Get the jdbc type id for this type.
 int getMaximumWidth()
          Get maximum width.
 DataTypeDescriptor getNullabilityType(boolean isNullable)
          Return a type descriptor identical to the this type with the exception of its nullability.
 int getPrecision()
          Returns the number of decimal digits for the datatype, if applicable.
static DataTypeDescriptor getRowMultiSet(String[] columnNames, DataTypeDescriptor[] columnTypes)
          Get a catalog type that corresponds to a SQL Row Multiset
 int getScale()
          Returns the number of digits to the right of the decimal for the datatype, if applicable.
static DataTypeDescriptor getSQLDataTypeDescriptor(String javaTypeName)
          Get a DataTypeDescriptor that corresponds to a Java type
static DataTypeDescriptor getSQLDataTypeDescriptor(String javaTypeName, boolean isNullable)
          Get a DataTypeDescriptor that corresponds to a Java type
static DataTypeDescriptor getSQLDataTypeDescriptor(String javaTypeName, int precision, int scale, boolean isNullable, int maximumWidth)
          Get a DataTypeDescriptor that corresponds to a Java type
 String getSQLstring()
          Converts this data type descriptor (including length/precision) to a string.
 TypeId getTypeId()
          Gets the TypeId for the datatype.
 String getTypeName()
          Gets the name of this datatype.
 DataTypeDescriptor getUnsigned()
           
static int intervalMaxWidth(TypeId typeId, int precision, int scale)
           
static boolean isAsciiStreamAssignable(int jdbcType)
          Determine if an ASCII stream can be inserted into a column or parameter of type jdbcType.
static boolean isBinaryStreamAssignable(int jdbcType)
          Determine if a binary stream can be inserted into a column or parameter of type jdbcType.
static boolean isCharacterStreamAssignable(int jdbcType)
          Determine if a character stream can be inserted into a column or parameter of type jdbcType.
static boolean isJDBCTypeEquivalent(int existingType, int jdbcTypeId)
          Compare JdbcTypeIds to determine if they represent equivalent SQL types.
 boolean isNullable()
          Returns TRUE if the datatype can contain NULL, FALSE if not.
static boolean isNumericType(int jdbcType)
           
 boolean isRowMultiSet()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAXIMUM_WIDTH_UNKNOWN

public static final int MAXIMUM_WIDTH_UNKNOWN
See Also:
Constant Field Values

MEDIUMINT

public static final DataTypeDescriptor MEDIUMINT

MEDIUMINT_NOT_NULL

public static final DataTypeDescriptor MEDIUMINT_NOT_NULL

INTEGER

public static final DataTypeDescriptor INTEGER
Runtime INTEGER type that is nullable.


INTEGER_NOT_NULL

public static final DataTypeDescriptor INTEGER_NOT_NULL
Runtime INTEGER type that is not nullable.


SMALLINT

public static final DataTypeDescriptor SMALLINT
Runtime SMALLINT type that is nullable.


SMALLINT_NOT_NULL

public static final DataTypeDescriptor SMALLINT_NOT_NULL
Runtime INTEGER type that is not nullable.

Constructor Detail

DataTypeDescriptor

public DataTypeDescriptor(TypeId typeId,
                          int precision,
                          int scale,
                          boolean isNullable,
                          int maximumWidth)
Constructor for use with numeric types

Parameters:
typeId - The typeId of the type being described
precision - The number of decimal digits.
scale - The number of digits after the decimal point.
isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
maximumWidth - The maximum number of bytes for this datatype

DataTypeDescriptor

public DataTypeDescriptor(TypeId typeId,
                          boolean isNullable,
                          int maximumWidth)
Constructor for use with non-numeric types

Parameters:
typeId - The typeId of the type being described
isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
maximumWidth - The maximum number of bytes for this datatype

DataTypeDescriptor

public DataTypeDescriptor(TypeId typeId,
                          boolean isNullable)

DataTypeDescriptor

public DataTypeDescriptor(TypeId typeId,
                          boolean isNullable,
                          int maximumWidth,
                          CharacterTypeAttributes characterAttributes)

DataTypeDescriptor

public DataTypeDescriptor(DataTypeDescriptor source,
                          CharacterTypeAttributes characterAttributes)
Method Detail

getBuiltInDataTypeDescriptor

public static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType)
Get a descriptor that corresponds to a nullable builtin JDBC type. If a variable length type then the size information will be set to the maximum possible. Collation type will be UCS_BASIC and derivation IMPLICIT. For well known types code may also use the pre-defined runtime types that are fields of this class, such as INTEGER.

Parameters:
jdbcType - The int type of the JDBC type for which to get a corresponding SQL DataTypeDescriptor
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type

getBuiltInDataTypeDescriptor

public static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType,
                                                              int length)
Get a descriptor that corresponds to a nullable builtin variable length JDBC type. Collation type will be UCS_BASIC and derivation IMPLICIT.

Parameters:
jdbcType - The int type of the JDBC type for which to get a corresponding SQL DataTypeDescriptor
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type

getBuiltInDataTypeDescriptor

public static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType,
                                                              boolean isNullable)
Get a descriptor that corresponds to a builtin JDBC type. For well known types code may also use the pre-defined runtime types that are fields of this class, such as INTEGER. E.g. using DataTypeDescriptor.INTEGER is preferred to DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.INTEGER, true) (both will return the same immutable object).

Parameters:
jdbcType - The int type of the JDBC type for which to get a corresponding SQL DataTypeDescriptor
isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type

getBuiltInDataTypeDescriptor

public static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType,
                                                              boolean isNullable,
                                                              int maxLength)
Get a descriptor that corresponds to a builtin JDBC type. Collation type will be UCS_BASIC and derivation IMPLICIT.

Parameters:
jdbcType - The int type of the JDBC type for which to get a corresponding SQL DataTypeDescriptor
isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type

getBuiltInDataTypeDescriptor

public static DataTypeDescriptor getBuiltInDataTypeDescriptor(String sqlTypeName)
Get a DataTypeDescriptor that corresponds to a nullable builtin SQL type. Collation type will be UCS_BASIC and derivation IMPLICIT.

Parameters:
sqlTypeName - The name of the type for which to get a corresponding SQL DataTypeDescriptor
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type (only for 'char')

getBuiltInDataTypeDescriptor

public static DataTypeDescriptor getBuiltInDataTypeDescriptor(String sqlTypeName,
                                                              int length)
Get a DataTypeDescriptor that corresponds to a builtin SQL type Collation type will be UCS_BASIC and derivation IMPLICIT.

Parameters:
sqlTypeName - The name of the type for which to get a corresponding SQL DataTypeDescriptor
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type (only for 'char')

getSQLDataTypeDescriptor

public static DataTypeDescriptor getSQLDataTypeDescriptor(String javaTypeName)
                                                   throws StandardException
Get a DataTypeDescriptor that corresponds to a Java type

Parameters:
javaTypeName - The name of the Java type for which to get a corresponding SQL DataTypeDescriptor
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type (only for 'char')
Throws:
StandardException

getSQLDataTypeDescriptor

public static DataTypeDescriptor getSQLDataTypeDescriptor(String javaTypeName,
                                                          boolean isNullable)
                                                   throws StandardException
Get a DataTypeDescriptor that corresponds to a Java type

Parameters:
javaTypeName - The name of the Java type for which to get a corresponding SQL DataTypeDescriptor
isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type (only for 'char')
Throws:
StandardException

getSQLDataTypeDescriptor

public static DataTypeDescriptor getSQLDataTypeDescriptor(String javaTypeName,
                                                          int precision,
                                                          int scale,
                                                          boolean isNullable,
                                                          int maximumWidth)
                                                   throws StandardException
Get a DataTypeDescriptor that corresponds to a Java type

Parameters:
javaTypeName - The name of the Java type for which to get a corresponding SQL DataTypeDescriptor
precision - The number of decimal digits
scale - The number of digits after the decimal point
isNullable - TRUE means it could contain NULL, FALSE means it definitely cannot contain NULL.
maximumWidth - The maximum width of a data value represented by this type.
Returns:
A new DataTypeDescriptor that corresponds to the Java type. A null return value means there is no corresponding SQL type.
Throws:
StandardException

getRowMultiSet

public static DataTypeDescriptor getRowMultiSet(String[] columnNames,
                                                DataTypeDescriptor[] columnTypes)
Get a catalog type that corresponds to a SQL Row Multiset

Parameters:
columnNames - Names of the columns in the Row Muliset
catalogTypes - Types of the columns in the Row Muliset
Returns:
A new DataTypeDescriptor describing the SQL Row Multiset

getDominantType

public DataTypeDescriptor getDominantType(DataTypeDescriptor otherDTS)
                                   throws StandardException
Get the dominant type (DataTypeDescriptor) of the 2. For variable length types, the resulting type will have the biggest max length of the 2. If either side is nullable, then the result will also be nullable.

Parameters:
otherDTS - DataTypeDescriptor to compare with.
Returns:
DataTypeDescriptor DTS for dominant type
Throws:
StandardException - Thrown on error

getMaximumWidth

public int getMaximumWidth()
Get maximum width.


getTypeId

public TypeId getTypeId()
Gets the TypeId for the datatype.

Returns:
The TypeId for the datatype.

getTypeName

public String getTypeName()
Gets the name of this datatype.

Returns:
the name of this datatype

getJDBCTypeId

public int getJDBCTypeId()
Get the jdbc type id for this type. JDBC type can be found in java.sql.Types.

Returns:
a jdbc type, e.g. java.sql.Types.DECIMAL
See Also:
Types

getPrecision

public int getPrecision()
Returns the number of decimal digits for the datatype, if applicable.

Returns:
The number of decimal digits for the datatype. Returns zero for non-numeric datatypes.
See Also:
TypeDescriptor#getPrecision()

getScale

public int getScale()
Returns the number of digits to the right of the decimal for the datatype, if applicable.

Returns:
The number of digits to the right of the decimal for the datatype. Returns zero for non-numeric datatypes.
See Also:
TypeDescriptor#getScale()

isNullable

public boolean isNullable()
Returns TRUE if the datatype can contain NULL, FALSE if not. JDBC supports a return value meaning "nullability unknown" - I assume we will never have columns where the nullability is unknown.

Returns:
TRUE if the datatype can contain NULL, FALSE if not.

isRowMultiSet

public boolean isRowMultiSet()

getNullabilityType

public DataTypeDescriptor getNullabilityType(boolean isNullable)
Return a type descriptor identical to the this type with the exception of its nullability. If the nullablity required matches the nullability of this then this is returned.

Parameters:
isNullable - True to return a nullable type, false otherwise.

getCharacterAttributes

public CharacterTypeAttributes getCharacterAttributes()

equals

public boolean equals(Object other)
Compare if two DataTypeDescriptors are exactly the same

Overrides:
equals in class Object
Parameters:
other - the type to compare to.

comparable

public boolean comparable(DataTypeDescriptor compareWithDTD,
                          boolean forEquals)
Check if this type is comparable with the passed type.

Parameters:
compareWithDTD - the type of the instance to compare with this type.
forEquals - True if this is an = or <> comparison, false otherwise.
Returns:
true if compareWithDTD is comparable to this type, else false.

getSQLstring

public String getSQLstring()
Converts this data type descriptor (including length/precision) to a string. E.g. VARCHAR(30) or java.util.Hashtable

Returns:
String version of datatype, suitable for running through the Parser.

isJDBCTypeEquivalent

public static boolean isJDBCTypeEquivalent(int existingType,
                                           int jdbcTypeId)
Compare JdbcTypeIds to determine if they represent equivalent SQL types. For example Types.NUMERIC and Types.DECIMAL are equivalent

Parameters:
existingType - JDBC type id of Derby data type
jdbcTypeId - JDBC type id passed in from application.
Returns:
boolean true if types are equivalent, false if not

isNumericType

public static boolean isNumericType(int jdbcType)

isAsciiStreamAssignable

public static boolean isAsciiStreamAssignable(int jdbcType)
Determine if an ASCII stream can be inserted into a column or parameter of type jdbcType.

Parameters:
jdbcType - JDBC type of column or parameter
Returns:
true if an ASCII stream can be inserted; false otherwise

isBinaryStreamAssignable

public static boolean isBinaryStreamAssignable(int jdbcType)
Determine if a binary stream can be inserted into a column or parameter of type jdbcType.

Parameters:
jdbcType - JDBC type of column or parameter
Returns:
true if a binary stream can be inserted; false otherwise

isCharacterStreamAssignable

public static boolean isCharacterStreamAssignable(int jdbcType)
Determine if a character stream can be inserted into a column or parameter of type jdbcType.

Parameters:
jdbcType - JDBC type of column or parameter
Returns:
true if a character stream can be inserted; false otherwise

toString

public String toString()
Overrides:
toString in class Object

getFullSQLTypeName

public String getFullSQLTypeName()
Return the SQL type name and, if applicable, scale/precision/length for this DataTypeDescriptor. Note that we want the values from *this* object specifically, not the max values defined on this.typeId.


computeMaxWidth

public static int computeMaxWidth(int precision,
                                  int scale)
Compute the maximum width (column display width) of a decimal or numeric data value, given its precision and scale.

Parameters:
precision - The precision (number of digits) of the data value.
scale - The number of fractional digits (digits to the right of the decimal point).
Returns:
The maximum number of characters needed to display the value.

getUnsigned

public DataTypeDescriptor getUnsigned()
                               throws StandardException
Throws:
StandardException

intervalMaxWidth

public static int intervalMaxWidth(TypeId typeId,
                                   int precision,
                                   int scale)


Copyright © 2013 Akiban Technologies, Inc. All rights reserved.