org.h2.table
Class Column

java.lang.Object
  extended by org.h2.table.Column

public class Column
extends java.lang.Object

This class represents a column in a table.


Field Summary
static int NOT_NULLABLE
          This column is not nullable.
static int NULLABLE
          This column is nullable.
static int NULLABLE_UNKNOWN
          It is not know whether this column is nullable.
 
Constructor Summary
Column(java.lang.String name, int type)
           
Column(java.lang.String name, int type, long precision, int scale, int displaySize)
           
 
Method Summary
 void addCheckConstraint(Session session, Expression expr)
          Add a check constraint expression to this column.
 Value convert(Value v)
          Convert a value to this column's type.
 void convertAutoIncrementToSequence(Session session, Schema schema, int id, boolean temporary)
          Convert the auto-increment flag to a sequence that is linked with this table.
 boolean equals(java.lang.Object o)
           
 Expression getCheckConstraint(Session session, java.lang.String asColumnName)
          Get the check constraint expression for this column if set.
 Column getClone()
           
 int getColumnId()
           
 java.lang.String getComment()
           
 java.lang.String getCreateSQL()
           
 Expression getDefaultExpression()
           
 int getDisplaySize()
           
 java.lang.String getName()
           
 java.lang.String getOriginalSQL()
           
 long getPrecision()
           
 int getScale()
           
 int getSelectivity()
          Get the selectivity of the column.
 Sequence getSequence()
           
 java.lang.String getSQL()
           
 Table getTable()
           
 int getType()
           
 int hashCode()
           
 boolean isAutoIncrement()
           
 boolean isNullable()
           
 boolean isPrimaryKey()
           
 void prepareExpression(Session session)
          Prepare all expressions of this column.
 void rename(java.lang.String newName)
          Rename the column.
 void setAutoIncrement(boolean autoInc, long start, long increment)
          Set the autoincrement flag and related properties of this column.
 void setComment(java.lang.String comment)
           
 void setComputedExpression(Expression expression)
          Set the default value in the form of a computed expression of other columns.
 void setConvertNullToDefault(boolean convert)
           
 void setDefaultExpression(Session session, Expression defaultExpression)
          Set the default expression.
 void setNullable(boolean b)
           
 void setOriginalSQL(java.lang.String original)
           
 void setPrimaryKey(boolean primaryKey)
           
 void setSelectivity(int selectivity)
          Set the new selectivity of a column.
 void setSequence(Sequence sequence)
           
 void setTable(Table table, int columnId)
          Set the table and column id.
 java.lang.String toString()
           
 Value validateConvertUpdateSequence(Session session, Value value)
          Validate the value, convert it if required, and update the sequence value if required.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NOT_NULLABLE

public static final int NOT_NULLABLE
This column is not nullable.

See Also:
Constant Field Values

NULLABLE

public static final int NULLABLE
This column is nullable.

See Also:
Constant Field Values

NULLABLE_UNKNOWN

public static final int NULLABLE_UNKNOWN
It is not know whether this column is nullable.

See Also:
Constant Field Values
Constructor Detail

Column

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

Column

public Column(java.lang.String name,
              int type,
              long precision,
              int scale,
              int displaySize)
Method Detail

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getClone

public Column getClone()

convert

public Value convert(Value v)
Convert a value to this column's type.

Parameters:
v - the value
Returns:
the value

setComputedExpression

public void setComputedExpression(Expression expression)
Set the default value in the form of a computed expression of other columns.

Parameters:
expression - the computed expression

setTable

public void setTable(Table table,
                     int columnId)
Set the table and column id.

Parameters:
table - the table
columnId - the column index

getTable

public Table getTable()

setDefaultExpression

public void setDefaultExpression(Session session,
                                 Expression defaultExpression)
Set the default expression.

Parameters:
session - the session
defaultExpression - the default expression

getColumnId

public int getColumnId()

getSQL

public java.lang.String getSQL()

getName

public java.lang.String getName()

getType

public int getType()

getPrecision

public long getPrecision()

getDisplaySize

public int getDisplaySize()

getScale

public int getScale()

setNullable

public void setNullable(boolean b)

validateConvertUpdateSequence

public Value validateConvertUpdateSequence(Session session,
                                           Value value)
Validate the value, convert it if required, and update the sequence value if required. If the value is null, the default value (NULL if no default is set) is returned. Check constraints are validated as well.

Parameters:
session - the session
value - the value or null
Returns:
the new or converted value

convertAutoIncrementToSequence

public void convertAutoIncrementToSequence(Session session,
                                           Schema schema,
                                           int id,
                                           boolean temporary)
Convert the auto-increment flag to a sequence that is linked with this table.

Parameters:
session - the session
schema - the schema where the sequence should be generated
id - the object id
temporary - true if the sequence is temporary and does not need to be stored

prepareExpression

public void prepareExpression(Session session)
Prepare all expressions of this column.

Parameters:
session - the session

getCreateSQL

public java.lang.String getCreateSQL()

isNullable

public boolean isNullable()

setOriginalSQL

public void setOriginalSQL(java.lang.String original)

getOriginalSQL

public java.lang.String getOriginalSQL()

getDefaultExpression

public Expression getDefaultExpression()

isAutoIncrement

public boolean isAutoIncrement()

setAutoIncrement

public void setAutoIncrement(boolean autoInc,
                             long start,
                             long increment)
Set the autoincrement flag and related properties of this column.

Parameters:
autoInc - the new autoincrement flag
start - the sequence start value
increment - the sequence increment

setConvertNullToDefault

public void setConvertNullToDefault(boolean convert)

rename

public void rename(java.lang.String newName)
Rename the column. This method will only set the column name to the new value.

Parameters:
newName - the new column name

setSequence

public void setSequence(Sequence sequence)

getSequence

public Sequence getSequence()

getSelectivity

public int getSelectivity()
Get the selectivity of the column. Selectivity 100 means values are unique, 10 means every distinct value appears 10 times on average.

Returns:
the selectivity

setSelectivity

public void setSelectivity(int selectivity)
Set the new selectivity of a column.

Parameters:
selectivity - the new value

addCheckConstraint

public void addCheckConstraint(Session session,
                               Expression expr)
Add a check constraint expression to this column. An existing check constraint constraint is added using AND.

Parameters:
session - the session
expr - the (additional) constraint

getCheckConstraint

public Expression getCheckConstraint(Session session,
                                     java.lang.String asColumnName)
Get the check constraint expression for this column if set.

Parameters:
session - the session
asColumnName - the column name to use
Returns:
the constraint expression

setComment

public void setComment(java.lang.String comment)

getComment

public java.lang.String getComment()

setPrimaryKey

public void setPrimaryKey(boolean primaryKey)

isPrimaryKey

public boolean isPrimaryKey()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object