Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.hsqldb
Class Column  view Column download Column.java

java.lang.Object
  extended byorg.hsqldb.Column

class Column
extends java.lang.Object

Implementation of SQL table columns as defined in DDL statements with static methods to process their values.

Version:
1.7.0

Field Summary
private static java.math.BigDecimal BIGDECIMAL_0
           
private  int colScale
           
private  int colSize
           
private  int colType
           
(package private)  HsqlName columnName
           
private  java.lang.String defaultString
           
private static java.util.Hashtable hTypes
           
private static java.text.Collator i18nCollator
           
private  boolean isIdentity
           
private  boolean isNullable
           
private  boolean isPrimaryKey
           
(package private) static int[] numericTypes
           
(package private) static int[] otherTypes
           
private static boolean sql_compare_in_locale
           
(package private) static int[][] typesArray
           
(package private) static int VARCHAR_IGNORECASE
           
 
Constructor Summary
(package private) Column(HsqlName name, boolean nullable, int type, int size, int scale, boolean identity, boolean primarykey, java.lang.String defstring)
          Creates a column defined in DDL statement.
 
Method Summary
(package private) static java.lang.Object add(java.lang.Object a, java.lang.Object b, int type)
          Add two object of a given type
(package private) static java.lang.Object avg(java.lang.Object a, int type, int count)
          Divide numeric object a by int count.
(package private) static int compare(java.lang.Object a, java.lang.Object b, int type)
          Compare a with b and return int value as result.
(package private) static java.lang.Object concat(java.lang.Object a, java.lang.Object b)
          Concat two objects by turning them into strings first.
private static java.lang.String convertObject(java.lang.Object o)
          Return a java string representation of a java object.
(package private) static java.lang.Object convertObject(java.lang.Object o, int type)
          Convert an object into a Java object that represents its SQL type.
private static java.lang.Object convertString(java.lang.String s, int type)
          Return a java object based on a SQL string.
(package private) static java.lang.String createSQLString(double x)
           
(package private) static java.lang.String createSQLString(java.lang.Object o, int type)
          Return an SQL representation of an object.
(package private) static java.lang.String createSQLString(java.lang.String s)
          Turns a java string into a quoted SQL string
(package private) static java.lang.Object divide(java.lang.Object a, java.lang.Object b, int type)
          Divide numeric object a by object b.
(package private) static int getCombinedNumberType(int type1, int type2, int expType)
          Arithmetic expressions terms are promoted to a type that can represent the resulting values and avoid incorrect results.
(package private)  java.lang.String getDefaultString()
          The default value for the column.
private static int getNumTypeWidth(int type)
           
(package private)  int getScale()
          Scale of the column in DDL (0 if not defined).
(package private)  int getSize()
          Size of the column in DDL (0 if not defined).
(package private)  int getType()
          Type of the column.
(package private) static int getTypeNr(java.lang.String type)
           
(package private) static java.lang.String getTypeString(int type)
           
(package private)  boolean isIdentity()
          Is this the identity column in the table.
(package private)  boolean isNullable()
          Is column nullable.
(package private)  boolean isPrimaryKey()
          Is this single column primary key of the table.
(package private) static java.lang.Object max(java.lang.Object a, java.lang.Object b, int type)
          Return the larger of two objects.
(package private) static java.lang.Object min(java.lang.Object a, java.lang.Object b, int type)
          Return the smaller of two objects.
(package private) static java.lang.Object multiply(java.lang.Object a, java.lang.Object b, int type)
          Multiply two numeric objects.
(package private) static java.lang.Object negate(java.lang.Object a, int type)
          Negate a numeric object.
(package private) static void setCompareInLocal(boolean value)
           
(package private)  void setNullable(boolean value)
          Set nullable.
(package private)  void setPrimaryKey(boolean value)
          Set primary key.
(package private) static java.lang.Object subtract(java.lang.Object a, java.lang.Object b, int type)
          Subtract numeric object b from object a.
(package private) static java.lang.Object sum(java.lang.Object a, java.lang.Object b, int type)
          Add two numeric objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VARCHAR_IGNORECASE

static final int VARCHAR_IGNORECASE
See Also:
Constant Field Values

hTypes

private static java.util.Hashtable hTypes

numericTypes

static final int[] numericTypes

otherTypes

static final int[] otherTypes

typesArray

static final int[][] typesArray

columnName

HsqlName columnName

colType

private int colType

colSize

private int colSize

colScale

private int colScale

isNullable

private boolean isNullable

isIdentity

private boolean isIdentity

isPrimaryKey

private boolean isPrimaryKey

defaultString

private java.lang.String defaultString

BIGDECIMAL_0

private static final java.math.BigDecimal BIGDECIMAL_0

i18nCollator

private static java.text.Collator i18nCollator

sql_compare_in_locale

private static boolean sql_compare_in_locale
Constructor Detail

Column

Column(HsqlName name,
       boolean nullable,
       int type,
       int size,
       int scale,
       boolean identity,
       boolean primarykey,
       java.lang.String defstring)
Creates a column defined in DDL statement.

Method Detail

isIdentity

boolean isIdentity()
Is this the identity column in the table.


isNullable

boolean isNullable()
Is column nullable.


setNullable

void setNullable(boolean value)
Set nullable.


isPrimaryKey

boolean isPrimaryKey()
Is this single column primary key of the table.


setPrimaryKey

void setPrimaryKey(boolean value)
Set primary key.


getDefaultString

java.lang.String getDefaultString()
The default value for the column.


getType

int getType()
Type of the column.


getSize

int getSize()
Size of the column in DDL (0 if not defined).


getScale

int getScale()
Scale of the column in DDL (0 if not defined).


getTypeNr

static int getTypeNr(java.lang.String type)
              throws java.sql.SQLException

getTypeString

static java.lang.String getTypeString(int type)
                               throws java.sql.SQLException

add

static java.lang.Object add(java.lang.Object a,
                            java.lang.Object b,
                            int type)
                     throws java.sql.SQLException
Add two object of a given type


concat

static java.lang.Object concat(java.lang.Object a,
                               java.lang.Object b)
                        throws java.sql.SQLException
Concat two objects by turning them into strings first.


negate

static java.lang.Object negate(java.lang.Object a,
                               int type)
                        throws java.sql.SQLException
Negate a numeric object.


multiply

static java.lang.Object multiply(java.lang.Object a,
                                 java.lang.Object b,
                                 int type)
                          throws java.sql.SQLException
Multiply two numeric objects.


divide

static java.lang.Object divide(java.lang.Object a,
                               java.lang.Object b,
                               int type)
                        throws java.sql.SQLException
Divide numeric object a by object b.


subtract

static java.lang.Object subtract(java.lang.Object a,
                                 java.lang.Object b,
                                 int type)
                          throws java.sql.SQLException
Subtract numeric object b from object a.


sum

static java.lang.Object sum(java.lang.Object a,
                            java.lang.Object b,
                            int type)
                     throws java.sql.SQLException
Add two numeric objects.


avg

static java.lang.Object avg(java.lang.Object a,
                            int type,
                            int count)
                     throws java.sql.SQLException
Divide numeric object a by int count. Adding all of these values in a column of the result of a SELECT statement gives the average for that column.


min

static java.lang.Object min(java.lang.Object a,
                            java.lang.Object b,
                            int type)
                     throws java.sql.SQLException
Return the smaller of two objects.


max

static java.lang.Object max(java.lang.Object a,
                            java.lang.Object b,
                            int type)
                     throws java.sql.SQLException
Return the larger of two objects.


setCompareInLocal

static void setCompareInLocal(boolean value)

compare

static int compare(java.lang.Object a,
                   java.lang.Object b,
                   int type)
            throws java.sql.SQLException
Compare a with b and return int value as result.


convertObject

private static java.lang.String convertObject(java.lang.Object o)
Return a java string representation of a java object.


convertObject

static java.lang.Object convertObject(java.lang.Object o,
                                      int type)
                               throws java.sql.SQLException
Convert an object into a Java object that represents its SQL type.

All type conversion operations start with this method. If a direct conversion doesn't take place, the object is converted into a string first and an attempt is made to convert the string into the target type.
One objective of this mehod is to ensure the Object can be converted to the given SQL type. For example, a number that has decimal points cannot be converted into an integral type, or a very large BIGINT value cannot be narrowed down to an INTEGER or SMALLINT.
Integral types may be represented by either Integer or Long. This works because in the rest of the methods, the java.lang.Number interface is used to retrieve the values from the object.


convertString

private static java.lang.Object convertString(java.lang.String s,
                                              int type)
                                       throws java.sql.SQLException
Return a java object based on a SQL string. This is called from convertObject(Object o, int type).


createSQLString

static java.lang.String createSQLString(java.lang.Object o,
                                        int type)
                                 throws java.sql.SQLException
Return an SQL representation of an object. Strings will be quoted with single quotes, other objects will represented as in a SQL statement.


createSQLString

static java.lang.String createSQLString(double x)
                                 throws java.sql.SQLException

createSQLString

static java.lang.String createSQLString(java.lang.String s)
Turns a java string into a quoted SQL string


getCombinedNumberType

static int getCombinedNumberType(int type1,
                                 int type2,
                                 int expType)
Arithmetic expressions terms are promoted to a type that can represent the resulting values and avoid incorrect results.

When the result or the expression is converted to the type of the target column for storage, an exception is thrown if the resulting value cannot be stored in the column

Returns a SQL type "wide" enough to represent the result of the expression.
A type is "wider" than the other if it can represent all its numeric values.
Types narrower than INTEGER (int) are promoted to INTEGER. The order is as follows

INTEGER, BIGINT, DOUBLE, DECIMAL

TINYINT and SMALLINT in any combination return INTEGER
INTEGER and INTEGER return BIGINT
BIGINT and INTEGER return NUMERIC/DECIMAL
BIGINT and BIGINT return NUMERIC/DECIMAL
DOUBLE and INTEGER return DOUBLE
DOUBLE and BIGINT return DOUBLE
NUMERIC/DECIMAL and any type returns NUMERIC/DECIMAL


getNumTypeWidth

private static int getNumTypeWidth(int type)