com.triactive.jdo.store.adapter
Class TypeInfo

java.lang.Object
  extended bycom.triactive.jdo.store.adapter.TypeInfo
All Implemented Interfaces:
java.lang.Comparable

public class TypeInfo
extends java.lang.Object
implements java.lang.Comparable

Represents the metadata of a specific JDBC data type. This class is basically a data structure that makes accessing the JDBC type metadata easier. Each of the items returned by DatabaseMetaData.getTypeInfo() is represented by a public field in this class.

Subclasses of TypeInfo can be used by specific DatabaseAdapters to supply missing metadata or correct faulty metadata obtained from the JDBC driver.

Author:
Mike Martin
See Also:
DatabaseAdapter.getTypeInfo(int), DatabaseAdapter.newTypeInfo(java.sql.ResultSet, int), DatabaseMetaData.getTypeInfo()

Field Summary
 boolean autoIncrement
          true indicates the type automatically increments for each new row inserted, false otherwise.
 boolean caseSensitive
          true indicates this data type is case-sensitive in comparisons, false otherwise.
 java.lang.String createParams
          Indicates the parameters used in defining columns of this type.
 short dataType
          The JDBC (SQL) data type number of this data type.
 boolean fixedPrecScale
          true indicates the type can be assigned a fixed scale value, such as for decimal or currency types, false otherwise.
 java.lang.String literalPrefix
          The prefix used to quote a literal of this data type; may be null.
 java.lang.String literalSuffix
          The suffix used to quote a literal of this data type; may be null.
 java.lang.String localTypeName
          Localized version of the DBMS-specific type name of this data type.
 short maximumScale
          The maximum supported scale value for this data type.
 short minimumScale
          The minimum supported scale value for this data type.
 int nullable
          Indicates whether null values are allowed for this data type.
 int numPrecRadix
          Indicates the numeric radix of this data type, which is usually 2 or 10.
 int originalRow
          The original row number of this type as returned by DatabaseMetaData.getTypeInfo().
 int precision
          The maximum precision/length allowed for this data type.
 short searchable
          Indicates searchability of this data type in terms of the kinds of SQL WHERE clauses that are allowed.
 java.lang.String typeName
          The DBMS-specific name for this data type.
 boolean unsignedAttribute
          true indicates the type is unsigned, false otherwise.
 
Constructor Summary
TypeInfo(java.sql.ResultSet rs, int row)
          Constructs a type information object from the current row of the given result set.
TypeInfo(java.lang.String typeName, short dataType, int precision, java.lang.String literalPrefix, java.lang.String literalSuffix, java.lang.String createParams, int nullable, boolean caseSensitive, short searchable, boolean unsignedAttribute, boolean fixedPrecScale, boolean autoIncrement, java.lang.String localTypeName, short minimumScale, short maximumScale, int numPrecRadix)
          Constructs a type information object from its individual attributes.
 
Method Summary
protected  int compareBooleanCapabilities(TypeInfo ti)
          Compares this type with another for order with respect to capabilities relevant to boolean types.
protected  int compareDateOrTimeCapabilities(TypeInfo ti)
          Compares this type with another for order with respect to capabilities relevant to date, time, or timestamp types.
protected  int compareIntegerCapabilities(TypeInfo ti)
          Compares this type with another for order with respect to capabilities relevant to integral types.
protected  int compareMaxPrecision(TypeInfo ti)
          Compares this type with another for order with respect to size capacity.
protected  int compareNullabilityAndSearchability(TypeInfo ti)
          Compares this type with another for order with respect to nullability and searchability.
protected  int compareNumberCapabilities(TypeInfo ti)
          Compares this type with another for order with respect to capabilities relevant to non-integer number types.
protected  int compareNumericSizeCapacity(TypeInfo ti)
          Compares this numeric type with another for order with respect to size capacity.
protected  int compareScaleRange(TypeInfo ti)
          Compares this type with another for order with respect to range of scale.
protected  int compareStringCapabilities(TypeInfo ti)
          Compares this type with another for order with respect to capabilities relevant to string types, character or binary.
 int compareTo(java.lang.Object o)
          Compares this type with the specified type for order.
 boolean equals(java.lang.Object obj)
          Indicates whether some object is "equal to" this one.
static java.lang.String getJDBCTypeName(int type)
          Returns the string name of the Java constant that equals the given JDBC type number type.
static java.lang.String getJDBCTypeNames(int[] types)
          Returns a string containing a series of Java constant names for the JDBC type numbers in types.
 int hashCode()
          Returns a hash code value for this object.
 boolean isBinaryType()
          Indicates whether this type is a binary type.
 boolean isCompatibleWith(ColumnInfo ci)
          Indicates whether the type of a given database column is "compatible" with this type.
 boolean isNationalStringType()
          Indicates whether this string type uses the alternate "national" character set.
 boolean isNumberType()
          Indicates whether this type is a number type, whether integer, floating-point, or decimal.
 boolean isStringType()
          Indicates whether this type is a character string type.
 java.lang.String toString()
          Returns the string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

originalRow

public final int originalRow
The original row number of this type as returned by DatabaseMetaData.getTypeInfo(). Zero if not obtained from getTypeInfo().


typeName

public java.lang.String typeName
The DBMS-specific name for this data type.


dataType

public short dataType
The JDBC (SQL) data type number of this data type.


precision

public int precision
The maximum precision/length allowed for this data type.


literalPrefix

public java.lang.String literalPrefix
The prefix used to quote a literal of this data type; may be null.


literalSuffix

public java.lang.String literalSuffix
The suffix used to quote a literal of this data type; may be null.


createParams

public java.lang.String createParams
Indicates the parameters used in defining columns of this type.


nullable

public int nullable
Indicates whether null values are allowed for this data type.

See Also:
DatabaseMetaData.typeNoNulls, DatabaseMetaData.typeNullable, DatabaseMetaData.typeNullableUnknown

caseSensitive

public boolean caseSensitive
true indicates this data type is case-sensitive in comparisons, false otherwise.


searchable

public short searchable
Indicates searchability of this data type in terms of the kinds of SQL WHERE clauses that are allowed.

See Also:
DatabaseMetaData.typePredNone, DatabaseMetaData.typePredChar, DatabaseMetaData.typePredBasic, DatabaseMetaData.typeSearchable

unsignedAttribute

public boolean unsignedAttribute
true indicates the type is unsigned, false otherwise.


fixedPrecScale

public boolean fixedPrecScale
true indicates the type can be assigned a fixed scale value, such as for decimal or currency types, false otherwise.


autoIncrement

public boolean autoIncrement
true indicates the type automatically increments for each new row inserted, false otherwise.


localTypeName

public java.lang.String localTypeName
Localized version of the DBMS-specific type name of this data type.


minimumScale

public short minimumScale
The minimum supported scale value for this data type.


maximumScale

public short maximumScale
The maximum supported scale value for this data type.


numPrecRadix

public int numPrecRadix
Indicates the numeric radix of this data type, which is usually 2 or 10.

Constructor Detail

TypeInfo

public TypeInfo(java.sql.ResultSet rs,
                int row)
         throws java.sql.SQLException
Constructs a type information object from the current row of the given result set. The result set must have been obtained from a call to DatabaseMetaData.getTypeInfo().

This method only retrieves the values from the current row; the caller is required to advance to the next row with ResultSet.next().

Parameters:
rs - The result set returned from DatabaseMetaData.getTypeInfo().
row - The current row number in the result set. The first row is 1.
Throws:
java.sql.SQLException - if a column of type information could not be retrieved from the result set.

TypeInfo

public TypeInfo(java.lang.String typeName,
                short dataType,
                int precision,
                java.lang.String literalPrefix,
                java.lang.String literalSuffix,
                java.lang.String createParams,
                int nullable,
                boolean caseSensitive,
                short searchable,
                boolean unsignedAttribute,
                boolean fixedPrecScale,
                boolean autoIncrement,
                java.lang.String localTypeName,
                short minimumScale,
                short maximumScale,
                int numPrecRadix)
Constructs a type information object from its individual attributes.

This can be useful to subclasses and/or custom DatabaseAdapters that need to modify and/or correct the metadata returned by the JDBC driver.

Method Detail

isCompatibleWith

public boolean isCompatibleWith(ColumnInfo ci)
Indicates whether the type of a given database column is "compatible" with this type.


isNumberType

public boolean isNumberType()
Indicates whether this type is a number type, whether integer, floating-point, or decimal.


isStringType

public boolean isStringType()
Indicates whether this type is a character string type.


isNationalStringType

public boolean isNationalStringType()
Indicates whether this string type uses the alternate "national" character set.


isBinaryType

public boolean isBinaryType()
Indicates whether this type is a binary type.


hashCode

public int hashCode()
Returns a hash code value for this object.


equals

public boolean equals(java.lang.Object obj)
Indicates whether some object is "equal to" this one. Two TypeInfo objects are considered equal only if all of their fields are equal.

Parameters:
obj - the reference object with which to compare
Returns:
true if this object is equal to the obj argument; false otherwise.

compareTo

public int compareTo(java.lang.Object o)
Compares this type with the specified type for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The order this method attempts to impose is as described in the docs for DatabaseMetaData.getTypeInfo():

They are ordered by DATA_TYPE and then by how closely the data type maps to the corresponding JDBC SQL type.

Specified by:
compareTo in interface java.lang.Comparable

compareBooleanCapabilities

protected int compareBooleanCapabilities(TypeInfo ti)
Compares this type with another for order with respect to capabilities relevant to boolean types. Returns a negative integer, zero, or a positive integer as this type is less suitable than, equal to, or more suitable than the other.


compareIntegerCapabilities

protected int compareIntegerCapabilities(TypeInfo ti)
Compares this type with another for order with respect to capabilities relevant to integral types. Returns a negative integer, zero, or a positive integer as this type is less suitable than, equal to, or more suitable than the other.


compareNumberCapabilities

protected int compareNumberCapabilities(TypeInfo ti)
Compares this type with another for order with respect to capabilities relevant to non-integer number types. Returns a negative integer, zero, or a positive integer as this type is less suitable than, equal to, or more suitable than the other.


compareStringCapabilities

protected int compareStringCapabilities(TypeInfo ti)
Compares this type with another for order with respect to capabilities relevant to string types, character or binary. Returns a negative integer, zero, or a positive integer as this type is less suitable than, equal to, or more suitable than the other.


compareDateOrTimeCapabilities

protected int compareDateOrTimeCapabilities(TypeInfo ti)
Compares this type with another for order with respect to capabilities relevant to date, time, or timestamp types. Returns a negative integer, zero, or a positive integer as this type is less suitable than, equal to, or more suitable than the other.


compareNullabilityAndSearchability

protected int compareNullabilityAndSearchability(TypeInfo ti)
Compares this type with another for order with respect to nullability and searchability. Returns a negative integer, zero, or a positive integer as this type is less capable than, equal to, or more capable than the other. Nullability is considered first, then searchability if both types are nullable.


compareNumericSizeCapacity

protected int compareNumericSizeCapacity(TypeInfo ti)
Compares this numeric type with another for order with respect to size capacity. Returns a negative integer, zero, or a positive integer as this type is less, equal, or more capacious than the other. Capacity is a combination of max precision and scale range, in that order.


compareMaxPrecision

protected int compareMaxPrecision(TypeInfo ti)
Compares this type with another for order with respect to size capacity. Returns a negative integer, zero, or a positive integer as this type is less, equal, or more capacious than the other.


compareScaleRange

protected int compareScaleRange(TypeInfo ti)
Compares this type with another for order with respect to range of scale. Returns a negative integer, zero, or a positive integer as this type has a smaller, equal, or larger scale range than the other.


toString

public java.lang.String toString()
Returns the string representation of this object.


getJDBCTypeNames

public static java.lang.String getJDBCTypeNames(int[] types)
Returns a string containing a series of Java constant names for the JDBC type numbers in types.

Parameters:
types - the JDBC type numbers.
Returns:
the string names of the corresponding constants from Types, comma-separated and enclosed in square brackets.
See Also:
getJDBCTypeName(int)

getJDBCTypeName

public static java.lang.String getJDBCTypeName(int type)
Returns the string name of the Java constant that equals the given JDBC type number type. JDBC type numbers are defined in Types.

If type is not equal to one of the known type numbers, the string "Types.(type)" is returned.

Parameters:
type - the JDBC type number
Returns:
the string name of the corresponding constant from Types.


Copyright 2001-2007 The TJDO Project All Rights Reserved.