proper.database
Class Column

java.lang.Object
  extended by proper.database.Column
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, Assignable

public class Column
extends java.lang.Object
implements java.lang.Comparable, java.lang.Cloneable, Assignable

This class contains some static informations about a column, like name and type.

Version:
$Revision: 1.3 $
Author:
FracPete
See Also:
Types

Constructor Summary
Column(java.lang.String name)
          initializes the column
Column(java.lang.String name, int type)
          initializes the column
Column(java.lang.String name, int type, int size)
          initializes the column
Column(java.lang.String name, int type, java.lang.String typeName)
          initializes the column
Column(java.lang.String name, int type, java.lang.String typeName, int size)
          initializes the column
 
Method Summary
 void assign(java.lang.Object o)
          retrieves the inner state of the given object and updates its own state with those settings
 java.lang.Object clone()
          returns a copy of itself
 int compareTo(java.lang.Object o)
          compares the given object to itself
 boolean equals(java.lang.Object obj)
          checks whether the objects are the same
 java.lang.String getName()
          returns the name of the column
 int getSize()
          returns the display size of the column
 java.lang.String getTable()
          returns the name of the table this column is member of, can be null!
 int getType()
          returns the type of the column
 java.lang.String getTypeName()
          returns the type name (database specific) of the column
 boolean isBoolean()
          checks whether the column is of boolean type, i.e.
 boolean isDate()
          checks whether the column is date type, i.e.
 boolean isDecimal()
          checks whether the column is a decimal type, i.e.
 boolean isInteger()
          checks whether the column is an integer type, i.e.
 boolean isNominal()
          checks whether the column is of nominal type, i.e.
 boolean isNumerical()
          checks whether the value is either integer or float type
static void main(java.lang.String[] args)
          for testing only
 void setType(int type)
          sets the type of the column
 void setTypeName(java.lang.String typeName)
          sets the type name of the column (database specific)
 java.lang.String toString()
          just returns the name of the table
 java.lang.String typeToString()
          returns an SQL representation of the current type
static java.lang.String typeToString(int type)
          returns an SQL representation of the given type (very crude, only INT DOUBLE, DATE and VARCHAR(255) are returned), NULL if it cannot convert it
static java.lang.String typeToString(int type, int size)
          returns an SQL representation of the given type (very crude, only INT DOUBLE, DATE, CHAR(size) and VARCHAR(size) are returned), NULL if it cannot convert it
static java.lang.String typeToString(int type, java.lang.String typeName, int size)
          returns an SQL representation of the given type (very crude, only INT DOUBLE, DATE, CHAR(size) and VARCHAR(size) are returned), NULL if it cannot convert it
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Column

public Column(java.lang.String name)
initializes the column

Parameters:
name - the name of the column

Column

public Column(java.lang.String name,
              int type)
initializes the column

Parameters:
name - the name of the column
type - the JDBC-type of the column

Column

public Column(java.lang.String name,
              int type,
              int size)
initializes the column

Parameters:
name - the name of the column
type - the JDBC-type of the column
size - the "display" size of the type, -1 is uninitialized

Column

public Column(java.lang.String name,
              int type,
              java.lang.String typeName)
initializes the column

Parameters:
name - the name of the column
type - the JDBC-type of the column
typeName - the database specific type name

Column

public Column(java.lang.String name,
              int type,
              java.lang.String typeName,
              int size)
initializes the column

Parameters:
name - the name of the column
type - the JDBC-type of the column
typeName - the database specific type name
size - the "display" size of the type, -1 is uninitialized
Method Detail

clone

public java.lang.Object clone()
returns a copy of itself

Overrides:
clone in class java.lang.Object

getTable

public java.lang.String getTable()
returns the name of the table this column is member of, can be null!

Returns:
the name of the table this column belongs to

getName

public java.lang.String getName()
returns the name of the column


setType

public void setType(int type)
sets the type of the column

See Also:
Types

getType

public int getType()
returns the type of the column

See Also:
Types

setTypeName

public void setTypeName(java.lang.String typeName)
sets the type name of the column (database specific)


getTypeName

public java.lang.String getTypeName()
returns the type name (database specific) of the column


getSize

public int getSize()
returns the display size of the column

See Also:
ResultSetMetaData.getColumnDisplaySize(int)

typeToString

public java.lang.String typeToString()
returns an SQL representation of the current type

See Also:
typeToString(int, int)

typeToString

public static java.lang.String typeToString(int type)
returns an SQL representation of the given type (very crude, only INT DOUBLE, DATE and VARCHAR(255) are returned), NULL if it cannot convert it

See Also:
typeToString(int, int)

typeToString

public static java.lang.String typeToString(int type,
                                            int size)
returns an SQL representation of the given type (very crude, only INT DOUBLE, DATE, CHAR(size) and VARCHAR(size) are returned), NULL if it cannot convert it


typeToString

public static java.lang.String typeToString(int type,
                                            java.lang.String typeName,
                                            int size)
returns an SQL representation of the given type (very crude, only INT DOUBLE, DATE, CHAR(size) and VARCHAR(size) are returned), NULL if it cannot convert it


isNominal

public boolean isNominal()
checks whether the column is of nominal type, i.e. CHAR, VARCHAR or LONGVARCHAR

See Also:
Types.CHAR, Types.VARCHAR, Types.LONGVARCHAR

isBoolean

public boolean isBoolean()
checks whether the column is of boolean type, i.e. BIT or BOOLEAN

See Also:
Types.BIT, Types.BOOLEAN

isInteger

public boolean isInteger()
checks whether the column is an integer type, i.e. INTEGER, TINYINT, SMALLINT, BIGINT

See Also:
Types.INTEGER, Types.TINYINT, Types.SMALLINT, Types.BIGINT

isDecimal

public boolean isDecimal()
checks whether the column is a decimal type, i.e. NUMERIC, REAL, FLOAT, DOUBLE, DECIMAL

See Also:
Types.NUMERIC, Types.REAL, Types.FLOAT, Types.DOUBLE, Types.DECIMAL

isNumerical

public boolean isNumerical()
checks whether the value is either integer or float type

See Also:
isInteger(), isDecimal()

isDate

public boolean isDate()
checks whether the column is date type, i.e. DATE, TIMESTAMP

See Also:
Types.DATE, Types.TIMESTAMP

assign

public void assign(java.lang.Object o)
retrieves the inner state of the given object and updates its own state with those settings

Specified by:
assign in interface Assignable
Parameters:
o - the object to retrieve the inner state from

compareTo

public int compareTo(java.lang.Object o)
              throws java.lang.ClassCastException
compares the given object to itself

Specified by:
compareTo in interface java.lang.Comparable
Throws:
java.lang.ClassCastException

equals

public boolean equals(java.lang.Object obj)
checks whether the objects are the same

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
just returns the name of the table

Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
for testing only