Package com.mckoi.database

## Class TType

- java.lang.Object
- - com.mckoi.database.TType

All Implemented Interfaces:
  `java.io.Serializable`

Direct Known Subclasses:
  `TArrayType`, `TBinaryType`, `TBooleanType`, `TDateType`, `TJavaObjectType`, `TNullType`, `TNumericType`, `TQueryPlanType`, `TStringType`

    public abstract class TType
    extends java.lang.Object
    implements java.io.Serializable

A TType object represents a type in a database engine. For example, an implementation might represent a STRING or a NUMBER. This is an immutable class. See implementations of this object for further examples.

Author:
  Tobias Downer
See Also:
  Serialized Form

### Field Summary

Fields
`static TArrayType` `ARRAY_TYPE` A type that represents an array.
`static TBinaryType` `BINARY_TYPE` A default binary (SQL BLOB) type of unlimited maximum size.
`static TBooleanType` `BOOLEAN_TYPE` A default boolean (SQL BIT) type.
`static TDateType` `DATE_TYPE` A default date (SQL TIMESTAMP) type.
`static TNullType` `NULL_TYPE` A default NULL type.
`static TNumericType` `NUMERIC_TYPE` A default numeric (SQL NUMERIC) type of unlimited size and scale.
`static TQueryPlanType` `QUERY_PLAN_TYPE` A type that represents a query plan (sub-select).
`static TStringType` `STRING_TYPE` A default string (SQL VARCHAR) type of unlimited maximum size and null locale.

### Constructor Summary

Constructors
`protected` `TType​(int sql_type)` Constructs the type object.

### Method Summary

All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
`static java.lang.String` `asEncodedString​(TType type)` Encodes a TType into a string which is a useful way to serialize a TType.
`static java.lang.String` `asEncodedString​(TType[] types)` Given an array of TType, returns a String that that is the encoded form of the array and that can be later decoded back into an array of TType.
`java.lang.String` `asSQLString()` Returns this TType as a fully parsable declared SQL type.
`static TType` `binaryType​(int sql_type, int size)` Returns a TBinaryType object.
`static TType` `booleanType​(int sql_type)` Returns a TBooleanType object.
`abstract int` `calculateApproximateMemoryUse​(java.lang.Object ob)` Calculates the approximate memory usage of an object of this type in bytes.
`static java.lang.Object` `castObjectToTType​(java.lang.Object ob, TType type)` Casts the given Java object to the given type.
`abstract boolean` `comparableTypes​(TType type)` Returns true if the type of this object is logically comparable to the type of the given object.
`abstract int` `compareObs​(java.lang.Object ob1, java.lang.Object ob2)` Compares two objects that are logically comparable under this type.
`static TType` `dateType​(int sql_type)` Returns a TDateType object.
`static TType` `decodeString​(java.lang.String encoded_str)` Decodes a String that has been encoded with the 'asEncodedString' method and returns a TType that represented the type.
`static TType[]` `decodeTypes​(java.lang.String encoded_str)` Decodes a list (or array) of TType objects that was previously encoded with the 'asEncodedString(Type[])' method.
`static TType` `fromClass​(java.lang.Class c)` Given a java class, this will return a default TType object that can encapsulate Java objects of this type.
`int` `getSQLType()` Returns the SQL type of this.
`static TType` `getWidestType​(TType t1, TType t2)` Assuming that the two types are numeric types, this will return the 'widest' of the two types.
`abstract java.lang.Class` `javaClass()` Returns the Java Class that is used to represent this type of object.
`static TType` `javaObjectType​(java.lang.String class_name)` Returns a TBinaryType constrained for the given class.
`static TType` `numericType​(int sql_type, int size, int scale)` Returns a TNumericType object of the given size and scale.
`static TType` `stringType​(int sql_type, int size, java.lang.String locale, int strength, int decomposition)` Returns a TStringType object of the given size and locale information.

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

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

### Field Detail

#### BOOLEAN_TYPE

    public static final TBooleanType BOOLEAN_TYPE

A default boolean (SQL BIT) type.

#### STRING_TYPE

    public static final TStringType STRING_TYPE

A default string (SQL VARCHAR) type of unlimited maximum size and null locale.

#### NUMERIC_TYPE

    public static final TNumericType NUMERIC_TYPE

A default numeric (SQL NUMERIC) type of unlimited size and scale.

#### DATE_TYPE

    public static final TDateType DATE_TYPE

A default date (SQL TIMESTAMP) type.

#### BINARY_TYPE

    public static final TBinaryType BINARY_TYPE

A default binary (SQL BLOB) type of unlimited maximum size.

#### NULL_TYPE

    public static final TNullType NULL_TYPE

A default NULL type.

#### QUERY_PLAN_TYPE

    public static final TQueryPlanType QUERY_PLAN_TYPE

A type that represents a query plan (sub-select).

#### ARRAY_TYPE

    public static final TArrayType ARRAY_TYPE

A type that represents an array.

### Constructor Detail

#### TType

    protected TType​(int sql_type)

Constructs the type object.

### Method Detail

#### getSQLType

    public int getSQLType()

Returns the SQL type of this.

#### asSQLString

    public java.lang.String asSQLString()

Returns this TType as a fully parsable declared SQL type. For example, if this represents a string we might return "VARCHAR(30) COLLATE 'jpJP'" This method is used for debugging and display purposes only and we would not expect to actually feed this back into an SQL parser.

#### comparableTypes

    public abstract boolean comparableTypes​(TType type)

Returns true if the type of this object is logically comparable to the type of the given object. For example, VARCHAR and LONGVARCHAR are comparable types. DOUBLE and FLOAT are comparable types. DOUBLE and VARCHAR are not comparable types.

#### compareObs

    public abstract int compareObs​(java.lang.Object ob1,
                                   java.lang.Object ob2)

Compares two objects that are logically comparable under this type. Returns 0 if the values are equal, >1 if ob1 is greater than ob2, and <1 if ob1 is less than ob2. It is illegal to pass NULL values for ob1 or ob2 into this method.

#### calculateApproximateMemoryUse

    public abstract int calculateApproximateMemoryUse​(java.lang.Object ob)

Calculates the approximate memory usage of an object of this type in bytes.

#### javaClass

    public abstract java.lang.Class javaClass()

Returns the Java Class that is used to represent this type of object. For example, string types would return String.class.

#### asEncodedString

    public static java.lang.String asEncodedString​(TType type)

Encodes a TType into a string which is a useful way to serialize a TType. The encoded string should be understandable when read.

#### asEncodedString

    public static java.lang.String asEncodedString​(TType[] types)

Given an array of TType, returns a String that that is the encoded form of the array and that can be later decoded back into an array of TType. Useful for serializing a list of TType information.

#### decodeString

    public static TType decodeString​(java.lang.String encoded_str)

Decodes a String that has been encoded with the 'asEncodedString' method and returns a TType that represented the type.

#### decodeTypes

    public static TType[] decodeTypes​(java.lang.String encoded_str)

Decodes a list (or array) of TType objects that was previously encoded with the 'asEncodedString(Type[])' method.

#### javaObjectType

    public static TType javaObjectType​(java.lang.String class_name)

Returns a TBinaryType constrained for the given class.

#### stringType

    public static TType stringType​(int sql_type,
                                   int size,
                                   java.lang.String locale,
                                   int strength,
                                   int decomposition)

Returns a TStringType object of the given size and locale information. If locale is null then collation is lexicographical.

#### numericType

    public static TType numericType​(int sql_type,
                                    int size,
                                    int scale)

Returns a TNumericType object of the given size and scale.

#### booleanType

    public static TType booleanType​(int sql_type)

Returns a TBooleanType object.

#### dateType

    public static TType dateType​(int sql_type)

Returns a TDateType object.

#### binaryType

    public static TType binaryType​(int sql_type,
                                   int size)

Returns a TBinaryType object.

#### castObjectToTType

    public static java.lang.Object castObjectToTType​(java.lang.Object ob,
                                                     TType type)

Casts the given Java object to the given type. For example, given a BigNumber object and STRING_TYPE, this would return the number as a string.

#### fromClass

    public static TType fromClass​(java.lang.Class c)

Given a java class, this will return a default TType object that can encapsulate Java objects of this type. For example, given java.lang.String, this will return a TStringType with no locale and maximum size.

Note that using this method is generally not recommended unless you really can't determine more type information than from the Java object itself.

#### getWidestType

    public static TType getWidestType​(TType t1,
                                      TType t2)

Assuming that the two types are numeric types, this will return the 'widest' of the two types. For example, an INTEGER is a wider type than a SHORT, and a FLOAT is wider than an INTEGER.

Code by Jim McBeath.