org.apache.derby.iapi.types
Class DataTypeDescriptor

java.lang.Object
  extended byorg.apache.derby.iapi.types.DataTypeDescriptor
All Implemented Interfaces:
java.io.Externalizable, Formatable, java.io.Serializable, TypeDescriptor, TypedFormat

public final class DataTypeDescriptor
extends java.lang.Object
implements TypeDescriptor, Formatable

This is an implementation of DataTypeDescriptor from the generic language datatype module interface.

Version:
1.0
Author:
Jeff Lichtman
See Also:
Serialized Form

Field Summary
private  TypeDescriptorImpl typeDescriptor
           
private  TypeId typeId
           
 
Fields inherited from interface org.apache.derby.catalog.TypeDescriptor
MAXIMUM_WIDTH_UNKNOWN
 
Constructor Summary
DataTypeDescriptor()
          Public niladic constructor.
DataTypeDescriptor(DataTypeDescriptor source, boolean isNullable)
           
DataTypeDescriptor(DataTypeDescriptor source, boolean isNullable, int maximumWidth)
          Constructor for internal uses only
DataTypeDescriptor(DataTypeDescriptor source, int precision, int scale, boolean isNullable, int maximumWidth)
          Constructor for internal uses only.
DataTypeDescriptor(TypeDescriptorImpl source, TypeId typeId)
          Constructor for use in reconstructing a DataTypeDescriptor from a TypeDescriptorImpl and a TypeId
DataTypeDescriptor(TypeId typeId, boolean isNullable)
           
DataTypeDescriptor(TypeId typeId, boolean isNullable, int maximumWidth)
          Constructor for use with non-numeric types
DataTypeDescriptor(TypeId typeId, int precision, int scale, boolean isNullable, int maximumWidth)
          Constructor for use with numeric types
 
Method Summary
 boolean equals(java.lang.Object aTypeDescriptor)
          Compare if two TypeDescriptors are exactly the same
 double estimatedMemoryUsage()
          Get the estimated memory usage for this type descriptor.
static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType)
          Get a descriptor that corresponds to a 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)
           
static DataTypeDescriptor getBuiltInDataTypeDescriptor(java.lang.String sqlTypeName)
          Get a DataTypeServices that corresponds to a builtin SQL type
static DataTypeDescriptor getBuiltInDataTypeDescriptor(java.lang.String sqlTypeName, int length)
          Get a DataTypeServices that corresponds to a builtin SQL type
 TypeDescriptorImpl getCatalogType()
          Get the simplified type descriptor that is intended to be stored in the system tables.
 DataTypeDescriptor getDominantType(DataTypeDescriptor otherDTS, ClassFactory cf)
          Get the dominant type (DataTypeDescriptor) of the 2.
 int getJDBCTypeId()
          Get the jdbc type id for this type.
 int getMaximumWidth()
          Returns the maximum width of the type.
 int getMaximumWidthInBytes()
          Returns the maximum width of the type IN BYTES.
 DataValueDescriptor getNull()
          Get a Null for this type.
 int getPrecision()
          Returns the number of decimal digits for the datatype, if applicable.
 int getScale()
          Returns the number of digits to the right of the decimal for the datatype, if applicable.
static DataTypeDescriptor getSQLDataTypeDescriptor(java.lang.String javaTypeName)
          Get a DataTypeServices that corresponds to a Java type
static DataTypeDescriptor getSQLDataTypeDescriptor(java.lang.String javaTypeName, boolean isNullable)
          Get a DataTypeServices that corresponds to a Java type
static DataTypeDescriptor getSQLDataTypeDescriptor(java.lang.String javaTypeName, int precision, int scale, boolean isNullable, int maximumWidth)
          Get a DataTypeDescriptor that corresponds to a Java type
 java.lang.String getSQLstring()
          Converts this data type descriptor (including length/precision) to a string.
 int getTypeFormatId()
          Get the formatID which corresponds to this class.
 TypeId getTypeId()
          Gets the TypeId for the datatype.
 java.lang.String getTypeName()
          Gets the name of this datatype.
private static boolean isBinaryType(int jdbcType)
           
private static boolean isCharacterType(int jdbcType)
           
 boolean isExactTypeAndLengthMatch(DataTypeDescriptor otherDTS)
          Check whether or not the 2 types (DataTypeDescriptor) have the same type and length.
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)
           
 DataValueDescriptor normalize(DataValueDescriptor source, DataValueDescriptor cachedDest)
           
 void readExternal(java.io.ObjectInput in)
          Read this object from a stream of stored objects.
 void setNullability(boolean nullable)
          Set the nullability of the datatype described by this descriptor
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
          Write this object to a stream of stored objects.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

typeDescriptor

private TypeDescriptorImpl typeDescriptor

typeId

private TypeId typeId
Constructor Detail

DataTypeDescriptor

public DataTypeDescriptor()
Public niladic constructor. Needed for Formatable interface to work.


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(DataTypeDescriptor source,
                          boolean isNullable)

DataTypeDescriptor

public DataTypeDescriptor(DataTypeDescriptor source,
                          int precision,
                          int scale,
                          boolean isNullable,
                          int maximumWidth)
Constructor for internal uses only. (This is useful when the precision and scale are potentially wider than those in the source, like when determining the dominant data type.)

Parameters:
source - The DTSI to copy
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(DataTypeDescriptor source,
                          boolean isNullable,
                          int maximumWidth)
Constructor for internal uses only

Parameters:
source - The DTSI to copy
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(TypeDescriptorImpl source,
                          TypeId typeId)
Constructor for use in reconstructing a DataTypeDescriptor from a TypeDescriptorImpl and a TypeId

Parameters:
source - The TypeDescriptorImpl to construct this DTSI from
Method Detail

getBuiltInDataTypeDescriptor

public static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType)
Get a descriptor that corresponds to a builtin JDBC type.

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)

getBuiltInDataTypeDescriptor

public static DataTypeDescriptor getBuiltInDataTypeDescriptor(int jdbcType,
                                                              boolean isNullable)
Get a descriptor that corresponds to a builtin JDBC type.

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.

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(java.lang.String sqlTypeName)
Get a DataTypeServices that corresponds to a builtin SQL type

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(java.lang.String sqlTypeName,
                                                              int length)
Get a DataTypeServices that corresponds to a builtin SQL type

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(java.lang.String javaTypeName)
Get a DataTypeServices 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')

getSQLDataTypeDescriptor

public static DataTypeDescriptor getSQLDataTypeDescriptor(java.lang.String javaTypeName,
                                                          boolean isNullable)
Get a DataTypeServices 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')

getSQLDataTypeDescriptor

public static DataTypeDescriptor getSQLDataTypeDescriptor(java.lang.String javaTypeName,
                                                          int precision,
                                                          int scale,
                                                          boolean isNullable,
                                                          int maximumWidth)
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.

normalize

public DataValueDescriptor normalize(DataValueDescriptor source,
                                     DataValueDescriptor cachedDest)
                              throws StandardException
Throws:
StandardException

getDominantType

public DataTypeDescriptor getDominantType(DataTypeDescriptor otherDTS,
                                          ClassFactory cf)
                                   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.
cf - A ClassFactory
Returns:
DataTypeDescriptor DTS for dominant type
Throws:
StandardException - Thrown on error

isExactTypeAndLengthMatch

public boolean isExactTypeAndLengthMatch(DataTypeDescriptor otherDTS)
Check whether or not the 2 types (DataTypeDescriptor) have the same type and length. This is useful for UNION when trying to decide whether a NormalizeResultSet is required.

Parameters:
otherDTS - DataTypeDescriptor to compare with.
Returns:
boolean Whether or not the 2 DTSs have the same type and length.

getMaximumWidth

public int getMaximumWidth()
Description copied from interface: TypeDescriptor
Returns the maximum width of the type. This may have different meanings for different types. For example, with char, it means the maximum number of characters, while with int, it is the number of bytes (i.e. 4).

Specified by:
getMaximumWidth in interface TypeDescriptor
Returns:
the maximum length of this Type; -1 means "unknown/no max length"
See Also:
TypeDescriptor.getMaximumWidth()

getMaximumWidthInBytes

public int getMaximumWidthInBytes()
Description copied from interface: TypeDescriptor
Returns the maximum width of the type IN BYTES. This is the maximum number of bytes that could be returned for this type if the corresponding getXXX() method is used. For example, if we have a CHAR type, then we want the number of bytes that would be returned by a ResultSet.getString() call.

Specified by:
getMaximumWidthInBytes in interface TypeDescriptor
Returns:
the maximum length of this Type IN BYTES; -1 means "unknown/no max length"
See Also:
TypeDescriptor.getMaximumWidthInBytes()

getTypeId

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

Returns:
The TypeId for the datatype.

getNull

public DataValueDescriptor getNull()
Get a Null for this type.


getTypeName

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

Specified by:
getTypeName in interface TypeDescriptor
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.

Specified by:
getJDBCTypeId in interface TypeDescriptor
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.

Specified by:
getPrecision in interface TypeDescriptor
Returns:
The number of decimal digits for the datatype. Returns zero for non-numeric datatypes.

getScale

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

Specified by:
getScale in interface TypeDescriptor
Returns:
The number of digits to the right of the decimal for the datatype. Returns zero for non-numeric datatypes.

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.

Specified by:
isNullable in interface TypeDescriptor
Returns:
TRUE if the datatype can contain NULL, FALSE if not.

setNullability

public void setNullability(boolean nullable)
Set the nullability of the datatype described by this descriptor

Parameters:
nullable - TRUE means set nullability to TRUE, FALSE means set it to FALSE
Returns:
Nothing

equals

public boolean equals(java.lang.Object aTypeDescriptor)
Compare if two TypeDescriptors are exactly the same


getSQLstring

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

Specified by:
getSQLstring in interface TypeDescriptor
Returns:
String version of datatype, suitable for running through the Parser.

getCatalogType

public TypeDescriptorImpl getCatalogType()
Get the simplified type descriptor that is intended to be stored in the system tables.


estimatedMemoryUsage

public double estimatedMemoryUsage()
Get the estimated memory usage for this type descriptor.


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 Cloudscape data type
Returns:
boolean true if types are equivalent, false if not

isNumericType

public static boolean isNumericType(int jdbcType)

isCharacterType

private static boolean isCharacterType(int jdbcType)

isBinaryType

private static boolean isBinaryType(int jdbcType)

toString

public java.lang.String toString()

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Read this object from a stream of stored objects.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - read this.
Throws:
java.io.IOException - thrown on error
java.lang.ClassNotFoundException - thrown on error

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Write this object to a stream of stored objects.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - write bytes here.
Throws:
java.io.IOException - thrown on error

getTypeFormatId

public int getTypeFormatId()
Get the formatID which corresponds to this class.

Specified by:
getTypeFormatId in interface TypedFormat
Returns:
the formatID of this class

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.