org.apache.derby.iapi.types
Class DataTypeDescriptor

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

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

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.

See Also:
Serialized Form

Field Summary
private  int collationDerivation
          Derivation of this type.
static DataTypeDescriptor INTEGER
          Runtime INTEGER type that is nullable.
static DataTypeDescriptor INTEGER_NOT_NULL
          Runtime INTEGER type that is not nullable.
static DataTypeDescriptor SMALLINT
          Runtime SMALLINT type that is nullable.
static DataTypeDescriptor SMALLINT_NOT_NULL
          Runtime INTEGER type that is not nullable.
private  TypeDescriptorImpl typeDescriptor
           
private  TypeId typeId
           
 
Constructor Summary
  DataTypeDescriptor()
          Public niladic constructor.
private DataTypeDescriptor(DataTypeDescriptor source, boolean isNullable)
           
  DataTypeDescriptor(DataTypeDescriptor source, boolean isNullable, int maximumWidth)
          Constructor for internal uses only
private DataTypeDescriptor(DataTypeDescriptor source, int collationType, int collationDerivation)
           
  DataTypeDescriptor(DataTypeDescriptor source, int precision, int scale, boolean isNullable, int maximumWidth)
          Constructor for internal uses only.
private 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
  DataTypeDescriptor(TypeId typeId, int precision, int scale, boolean isNullable, int maximumWidth, int collationType, int collationDerivation)
          Constructor to use when the caller doesn't know if it is requesting numeric or no-numeric DTD.
 
Method Summary
 boolean comparable(DataTypeDescriptor compareWithDTD, boolean forEquals, ClassFactory cf)
          Check if this type is comparable with the passed type.
 boolean compareCollationInfo(DataTypeDescriptor compareWithDTD)
          Compare the collation info on this DTD with the passed DTD.
 boolean equals(java.lang.Object other)
          Compare if two DataTypeDescriptors 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 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(java.lang.String sqlTypeName)
          Get a DataTypeServices that corresponds to a nullable builtin SQL type.
static DataTypeDescriptor getBuiltInDataTypeDescriptor(java.lang.String sqlTypeName, int length)
          Get a DataTypeServices that corresponds to a builtin SQL type Collation type will be UCS_BASIC and derivation IMPLICIT.
 TypeDescriptor getCatalogType()
          Get the simplified type descriptor that is intended to be stored in the system tables.
static TypeDescriptor getCatalogType(int jdbcType)
          Return a nullable catalog type for a fixed length JDBC builtin type.
static TypeDescriptor getCatalogType(int jdbcType, int length)
          Return a nullable catalog type for a JDBC builtin type and length.
static TypeDescriptor getCatalogType(TypeDescriptor catalogType, int collationType)
          Get a catlog type identical to the passed in type exception that the collationType is set to the passed in value.
 DataTypeDescriptor getCollatedType(int collationType, int collationDerivation)
          Return a type description identical to this type with the exception that its collation information is taken from the passed in information.
 int getCollationDerivation()
          Get the collation derivation for this type.
 java.lang.String getCollationName()
          Gets the name of the collation type in this descriptor if the collation derivation is not NONE.
static java.lang.String getCollationName(int collationType)
          Gets the name of the specified collation type.
 int getCollationType()
          Obtain the collation type of the underlying catalog type.
static int getCollationType(java.lang.String collationName)
          Obtain the collation type from a collation property value.
 DataTypeDescriptor getDominantType(DataTypeDescriptor otherDTS, ClassFactory cf)
          Get the dominant type (DataTypeDescriptor) of the 2.
 java.lang.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()
          Shorthand method for getCatalogType().getMaximumWidth().
 DataValueDescriptor getNull()
          Get a Null for this type.
 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 TypeDescriptor getRowMultiSet(java.lang.String[] columnNames, TypeDescriptor[] catalogTypes)
          Get a catalog type that corresponds to a SQL Row Multiset
private static TypeDescriptor getRowMultiSetCollation(TypeDescriptor catalogType, int collationType)
          For a row multi set type return an identical type with the collation type changed.
 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.
 java.lang.String getSQLTypeNameWithCollation()
           
static DataTypeDescriptor getType(TypeDescriptor catalogType)
          Return a runtime type for a catalog type.
 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.
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.
private static boolean isBinaryType(int jdbcType)
          Check whether a JDBC type is compatible with the Java type byte[].
static boolean isCharacterStreamAssignable(int jdbcType)
          Determine if a character stream can be inserted into a column or parameter of type jdbcType.
private static boolean isCharacterType(int jdbcType)
          Check whether a JDBC type is one of the character types that are compatible with the Java type String.
 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)
           
 boolean isUserCreatableType()
          Check to make sure that this type id is something a user can create him/herself directly through an SQL CREATE TABLE statement.
 DataValueDescriptor normalize(DataValueDescriptor source, DataValueDescriptor cachedDest)
           
 void readExternal(java.io.ObjectInput in)
          Read this object from a stream of stored objects.
 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

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.


typeDescriptor

private TypeDescriptorImpl typeDescriptor

typeId

private TypeId typeId

collationDerivation

private int collationDerivation
Derivation of this type. All catalog types are by definition implicit.

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,
                          int precision,
                          int scale,
                          boolean isNullable,
                          int maximumWidth,
                          int collationType,
                          int collationDerivation)
Constructor to use when the caller doesn't know if it is requesting numeric or no-numeric DTD. For instance, when dealing with MAX/MIN aggregrate operators, AggregateNode.bindExpression could be dealing with a character string operand or a numeric operand. The result of MAX/MIN will depend on the type of it's operand. And hence when this constructor gets called by AggregateNode.bindExpression, we don't know what type we are constructing and hence this constructor supports arguments for both numeric and non-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
collationType - The collation type of a string data type
collationDerivation - Collation Derivation of a string data type

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

private DataTypeDescriptor(DataTypeDescriptor source,
                           boolean isNullable)

DataTypeDescriptor

private DataTypeDescriptor(DataTypeDescriptor source,
                           int collationType,
                           int collationDerivation)

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

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

getType

public static DataTypeDescriptor getType(TypeDescriptor catalogType)
Return a runtime type for a catalog type.


getCatalogType

public static TypeDescriptor getCatalogType(int jdbcType,
                                            int length)
Return a nullable catalog type for a JDBC builtin type and length.


getCatalogType

public static TypeDescriptor getCatalogType(int jdbcType)
Return a nullable catalog type for a fixed length JDBC builtin type.


getCatalogType

public static TypeDescriptor getCatalogType(TypeDescriptor catalogType,
                                            int collationType)
Get a catlog type identical to the passed in type exception that the collationType is set to the passed in value.

Parameters:
catalogType - Type to be based upon.
collationType - Collation type of returned type.
Returns:
catalogType if it already has the correct collation, otherwise a new TypeDescriptor with the correct collation.

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(java.lang.String sqlTypeName)
Get a DataTypeServices 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(java.lang.String sqlTypeName,
                                                              int length)
Get a DataTypeServices 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(java.lang.String javaTypeName)
                                                   throws StandardException
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')
Throws:
StandardException

getSQLDataTypeDescriptor

public static DataTypeDescriptor getSQLDataTypeDescriptor(java.lang.String javaTypeName,
                                                          boolean isNullable)
                                                   throws StandardException
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')
Throws:
StandardException

getSQLDataTypeDescriptor

public static DataTypeDescriptor getSQLDataTypeDescriptor(java.lang.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 TypeDescriptor getRowMultiSet(java.lang.String[] columnNames,
                                            TypeDescriptor[] catalogTypes)
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

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. If dealing with character string types, then make sure to set the collation info on the dominant type. Following algorithm will be used for dominant DTD's collation determination. Each of the steps of the algorithm have been numbered in the comments below and those same numbers are used in the actual algorithm below so it is easier to understand and maintain. Step 1 If the DTD for "this" node has the same collation derivation as the otherDTS, then check if their collation types match too. If the collation types match too, then DTD for dominant type will get the same collation derivation and type. Step 2 If the collation derivation for DTD for "this" node and otherDTS do not match, then check if one of them has the collation derivation of NONE. If that is the case, then dominant DTD will get the collation type and derivation of DTD whose collation derivation is not NONE. Step 3 If the collation derivation for DTD for "this" node and otherDTS do not match, and none of them have the derivation of NONE then it means that we are dealing with collation derivation of IMPLICIT and EXPLICIT and hence the dominant DTD should get collation derivation of NONE. This is not a possibility in Derby 10.3 because the only 2 possible collation derivation supported are IMPLICIT and NONE. Step 4 If the collation derivation for DTD for "this" node and otherDTS match, then check if the collation types match too. If not, then the dominant DTD should get collation derivation of NONE.

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()
Shorthand method for getCatalogType().getMaximumWidth().

See Also:
TypeDescriptor.getMaximumWidth()

getTypeId

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

Returns:
The TypeId for the datatype.

getNull

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

Throws:
StandardException

getTypeName

public java.lang.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. Shorthand method for getCatalogType().getJDBCTypeId().

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. Shorthand method for getCatalogType().getPrecision().

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. Shorthand method for getCatalogType().getScale().

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

getCollationType

public int getCollationType()
Obtain the collation type of the underlying catalog type. Shorthand method for getCatalogType().getCollationType().

See Also:
TypeDescriptor.getCollationType()

getCollationType

public static int getCollationType(java.lang.String collationName)
Obtain the collation type from a collation property value.

Returns:
The collation type, or -1 if not recognized.

getCollationName

public java.lang.String getCollationName()
Gets the name of the collation type in this descriptor if the collation derivation is not NONE. If the collation derivation is NONE, then this method will return "NONE".

This method is used for generating error messages which will use correct string describing collation type/derivation.

Returns:
the name of the collation being used in this type.

getCollationName

public static java.lang.String getCollationName(int collationType)
Gets the name of the specified collation type.

Parameters:
collationType - The collation type.
Returns:
The name, e g "TERRITORY_BASED:PRIMARY".

getCollationDerivation

public int getCollationDerivation()
Get the collation derivation for this type. This applies only for character string types. For the other types, this api should be ignored. SQL spec talks about character string types having collation type and collation derivation associated with them (SQL spec Section 4.2.2 Comparison of character strings). If collation derivation says explicit or implicit, then it means that there is a valid collation type associated with the charcter string type. If the collation derivation is none, then it means that collation type can't be established for the character string type. 1)Collation derivation will be explicit if SQL COLLATE clause has been used for character string type (this is not a possibility for Derby 10.3 because we are not planning to support SQL COLLATE clause in the 10.3 release). 2)Collation derivation will be implicit if the collation can be determined w/o the COLLATE clause eg CREATE TABLE t1(c11 char(4)) then c11 will have collation of USER character set. Another eg, TRIM(c11) then the result character string of TRIM operation will have collation of the operand, c11. 3)Collation derivation will be none if the aggregate methods are dealing with character strings with different collations (Section 9.3 Data types of results of aggregations Syntax Rule 3aii). Collation derivation will be initialized to COLLATION_DERIVATION_IMPLICIT if not explicitly set.

Returns:
Should be COLLATION_DERIVATION_NONE or COLLATION_DERIVATION_IMPLICIT
See Also:
StringDataValue.COLLATION_DERIVATION_NONE, StringDataValue.COLLATION_DERIVATION_IMPLICIT, StringDataValue.COLLATION_DERIVATION_EXPLICIT

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. Shorthand method for getCatalogType().isNullable();

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

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.

getCollatedType

public DataTypeDescriptor getCollatedType(int collationType,
                                          int collationDerivation)
Return a type description identical to this type with the exception that its collation information is taken from the passed in information. If the type does not represent a string type then the collation will be unchanged and this is returned.

Returns:
This if collation would be unchanged otherwise a new type.

getRowMultiSetCollation

private static TypeDescriptor getRowMultiSetCollation(TypeDescriptor catalogType,
                                                      int collationType)
For a row multi set type return an identical type with the collation type changed. Note that since row types are only ever catalog types the derivation is not used (since derivation is a property of runtime types).

Parameters:
collationType -
Returns:
this will be returned if no changes are required (e.g. no string types or collation is already correct), otherwise a new instance is returned (leaving this unchanged).

equals

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

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

comparable

public boolean comparable(DataTypeDescriptor compareWithDTD,
                          boolean forEquals,
                          ClassFactory cf)
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.
cf - A ClassFactory
Returns:
true if compareWithDTD is comparable to this type, else false.

compareCollationInfo

public boolean compareCollationInfo(DataTypeDescriptor compareWithDTD)
Compare the collation info on this DTD with the passed DTD. The rules for comparison are as follows (these are as per SQL standard 2003 Section 9.13) 1)If both the DTDs have collation derivation of NONE, then they can't be compared and we return false. 2)If both the DTDs have same collation derivation (which in Derby's case at this point will mean collation derivation of IMPLICIT), then check the collation types. If they match, then return true. If they do not match, then they can't be compared and hence return false. 3)If one DTD has collation derivation of IMPLICIT and other DTD has collation derivation of NONE, then 2 DTDs are comparable using the collation type of DTD with collation derivation of IMPLICIT. Derby does not implement this rule currently and it is being traked as DERBY-2678. Derby's current behavior is to throw an exception if both the DTDs involved in collation operation do not have collation derivation of IMPLICIT. This behavior is a subset of SQL standard. 4)Derby currently does not support collation derivation of EXPLICIT and hence we do not have the code to enforce rules as mentioned in Section 9.13 of SQL spec for collation derivation of EXPLICIT. When we implement collation derivation of EXPLICIT, we should make sure that we follow the rules as specified in the SQL spec for comparability.

Parameters:
compareWithDTD - compare this DTD's collation info
Returns:
value depends on the algorithm above.

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

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

getCatalogType

public TypeDescriptor 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 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)

isCharacterType

private static boolean isCharacterType(int jdbcType)
Check whether a JDBC type is one of the character types that are compatible with the Java type String.

Note: CLOB is not compatible with String. See tables B-4, B-5 and B-6 in the JDBC 3.0 Specification.

There are some non-character types that are compatible with String (examples: numeric types, binary types and time-related types), but they are not covered by this method.

Parameters:
jdbcType - a JDBC type
Returns:
true iff jdbcType is a character type and compatible with String
See Also:
Types

isBinaryType

private static boolean isBinaryType(int jdbcType)
Check whether a JDBC type is compatible with the Java type byte[].

Note: BLOB is not compatible with byte[]. See tables B-4, B-5 and B-6 in the JDBC 3.0 Specification.

Parameters:
jdbcType - a JDBC type
Returns:
true iff jdbcType is compatible with byte[]
See Also:
Types

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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

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

isUserCreatableType

public boolean isUserCreatableType()
                            throws StandardException
Check to make sure that this type id is something a user can create him/herself directly through an SQL CREATE TABLE statement. This method is used for CREATE TABLE AS ... WITH [NO] DATA binding because it's possible for the query to return types which are not actually creatable for a user. DERBY-2605. Three examples are: BOOLEAN: A user can select boolean columns from system tables, but s/he is not allowed to create such a column him/herself. JAVA_OBJECT: A user can select columns of various java object types from system tables, but s/he is not allowed to create such a column him/herself. DECIMAL: A user can specify a VALUES clause with a constant that has a precision of greater than 31. Derby can apparently handle such a value internally, but the user is not supposed to be able create such a column him/herself.

Returns:
True if the type associated with this DTD can be created via the CREATE TABLE syntax; false otherwise.
Throws:
StandardException

getFullSQLTypeName

public java.lang.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.


getSQLTypeNameWithCollation

public java.lang.String getSQLTypeNameWithCollation()

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.