Top Description Fields Constructors Methods
org.h2.table

public final Class Column

extends Object
implements HasSQL, Typed, ColumnTemplate
Class Inheritance
All Implemented Interfaces
org.h2.table.ColumnTemplate, org.h2.value.Typed, org.h2.util.HasSQL
Imports
java.sql.ResultSetMetaData, java.util.Arrays, .Objects, org.h2.api.ErrorCode, org.h2.command.ParserBase, org.h2.command.ddl.SequenceOptions, org.h2.engine.CastDataProvider, .Constants, .SessionLocal, org.h2.expression.Expression, .ExpressionVisitor, .ValueExpression, org.h2.message.DbException, org.h2.result.Row, org.h2.schema.Domain, .Schema, .Sequence, org.h2.util.HasSQL, .ParserUtil, .StringUtils, org.h2.value.ExtTypeInfoRow, .TypeInfo, .Typed, .Value, .ValueNull, .ValueRow, .ValueUuid

This class represents a column in a table.

Field Summary

Modifier and TypeField and Description
private int
private String
private Expression
private boolean
private Domain
private GeneratedColumnResolver
private SequenceOptions
private boolean
private String
public static final int
NOT_NULLABLE

This column is not nullable.

public static final int
NULLABLE

This column is nullable.

private boolean
public static final int
NULLABLE_UNKNOWN

It is not know whether this column is nullable.

private Expression
private boolean
public static final String
ROWID

The name of the rowid pseudo column.

private boolean
private int
private Sequence
private Table
private TypeInfo
private boolean

Constructor Summary

AccessConstructor and Description
public
Column(String name, TypeInfo type)

public
Column(String name, TypeInfo type, Table table, int columnId)

Method Summary

Modifier and TypeMethod and Description
public Value

Returns:

the value
convert
(CastDataProvider
the cast information provider
provider
,
Value
the value
v
)

Convert a value to this column's type without precision and scale checks.

public static ValueRow

Returns:

a ValueRow which contains the converted values
convert
(CastDataProvider
the cast information provider
provider
,
Column[]
the column info list used for the conversation
columns
,
ValueRow
the holder of the values
valueRow
)

Converts the values in a ValueRow based on the passed column info.

public void
copy(Column
the source column
source
)

Copy the data of the source column into the current column.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Column
public int
public String
public String
public String

Returns:

the SQL statement
getCreateSQL
(boolean
whether this is for the metadata table
forMeta
)

Get this columns part of CREATE TABLE SQL statement.

private String
getCreateSQL(StringBuilder builder, boolean forMeta)

public String
private DbException
public Expression
private Value
public String
public Domain
public Expression
public Expression
public SequenceOptions

Returns:

identity column options, or null
getIdentityOptions
()

Returns identity column options, or null if sequence was already created or this column is not an identity column.

public String
public Expression
public String
public int

Returns:

the selectivity
getSelectivity
()

Get the selectivity of the column.

public Sequence
public String
getSQL(int
formatting flags
sqlFlags
)

Overrides default org.h2.util.HasSQL.getSQL.

Get the SQL statement of this expression.

public StringBuilder
getSQL(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Implements org.h2.util.HasSQL.getSQL.

Appends the SQL statement of this object to the specified builder.

public StringBuilder

Returns:

the specified string builder
getSQLWithTable
(StringBuilder
the string builder
builder
,
int
formatting flags
sqlFlags
)

Appends the table name and column name to the specified builder.

public Table
public TypeInfo
getType()

Implements org.h2.value.Typed.getType.

Returns the data type.

public boolean
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if yes
hasIdentityOptions
()

Whether the column has any identity options.

public void
initializeSequence(SessionLocal
the session
session
,
Schema
the schema where the sequence should be generated
schema
,
int
the object id
id
,
boolean
true if the sequence is temporary and does not need to be stored
temporary
)

Initialize the sequence for this column.

public boolean
pack-priv boolean

Returns:

true if every visited expression returned true, or if there are no expressions
isEverything
(ExpressionVisitor
the visitor
visitor
)

Visit the default expression, the check constraint, and the sequence (if any).

public boolean

Returns:

whether this column is a generated column
isGenerated
()

Returns whether this column is a generated column.

public boolean

Returns:

whether this column is a generated column or always generated identity column
isGeneratedAlways
()

Returns whether this column is a generated column or always generated identity column.

public boolean

Returns:

whether this column is an identity column
isIdentity
()

Returns whether this column is an identity column.

public boolean
public boolean
public boolean

Returns:

true for _ROWID_ column, false otherwise
isRowId
()

Returns whether this column is a row identity column.

public boolean

Returns:

true if the new column is compatible
isWideningConversion
(Column
the new (target) column
newColumn
)

Check whether the new column is of the same type and not more restricted than this column.

public void
prepareExpressions(SessionLocal
the session
session
)

Implements org.h2.table.ColumnTemplate.prepareExpressions.

Prepare all expressions of this column or domain.

private void
public void
rename(String
the new column name
newName
)

Rename the column.

public void
setComment(String comment)

public void
setDefaultExpression(SessionLocal
the session
session
,
Expression
the default expression
defaultExpression
)

Implements org.h2.table.ColumnTemplate.setDefaultExpression.

Set the default expression.

public void
setDefaultOnNull(boolean defaultOnNull)

public void
public void
setGeneratedExpression(Expression
the computed expression
expression
)

Set the default value in the form of a generated expression of other columns.

public void
setIdentityOptions(SequenceOptions
identity column options
identityOptions
,
boolean
whether value should be always generated
generatedAlways
)

Set the identity options of this column.

public void
setNullable(boolean b)

public void
setOnUpdateExpression(SessionLocal
the session
session
,
Expression
the on update expression
onUpdateExpression
)

Implements org.h2.table.ColumnTemplate.setOnUpdateExpression.

Set the on update expression.

public void
setPrimaryKey(boolean primaryKey)

public void
setRowId(boolean
true _ROWID_ column, false otherwise
rowId
)

Set row identity flag.

public void
setSelectivity(int
the new value
selectivity
)

Set the new selectivity of a column.

public void
setSequence(Sequence
the sequence
sequence
,
boolean
whether the value of the sequence is always used
generatedAlways
)

Set the sequence to generate the value.

public void
setTable(Table
the table
table
,
int
the column index
columnId
)

Set the table and column id.

public void
setVisible(boolean b)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
pack-priv Value

Returns:

the new or converted value
validateConvertUpdateSequence
(SessionLocal
the session
session
,
Value
the value or null
value
,
Row
the row
row
)

Validate the value, convert it if required, and update the sequence value if required.

public static StringBuilder

Returns:

the specified string builder
writeColumns
(StringBuilder
string builder
builder
,
Column[]
columns
columns
,
int
formatting flags
sqlFlags
)

Appends the specified columns to the specified builder.

public static StringBuilder

Returns:

the specified string builder
writeColumns
(StringBuilder
string builder
builder
,
Column[]
columns
columns
,
String
separator
separator
,
String
additional SQL to append after each column
suffix
,
int
formatting flags
sqlFlags
)

Appends the specified columns to the specified builder.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

columnIdback to summary
private int columnId
commentback to summary
private String comment
defaultExpressionback to summary
private Expression defaultExpression
defaultOnNullback to summary
private boolean defaultOnNull
domainback to summary
private Domain domain
generatedTableFilterback to summary
private GeneratedColumnResolver generatedTableFilter
identityOptionsback to summary
private SequenceOptions identityOptions
isGeneratedAlwaysback to summary
private boolean isGeneratedAlways
nameback to summary
private String name
NOT_NULLABLEback to summary
public static final int NOT_NULLABLE

This column is not nullable.

NULLABLEback to summary
public static final int NULLABLE

This column is nullable.

nullableback to summary
private boolean nullable
NULLABLE_UNKNOWNback to summary
public static final int NULLABLE_UNKNOWN

It is not know whether this column is nullable.

onUpdateExpressionback to summary
private Expression onUpdateExpression
primaryKeyback to summary
private boolean primaryKey
ROWIDback to summary
public static final String ROWID

The name of the rowid pseudo column.

rowIdback to summary
private boolean rowId
selectivityback to summary
private int selectivity
sequenceback to summary
private Sequence sequence
tableback to summary
private Table table
typeback to summary
private TypeInfo type
visibleback to summary
private boolean visible

Constructor Detail

Columnback to summary
public Column(String name, TypeInfo type)
Columnback to summary
public Column(String name, TypeInfo type, Table table, int columnId)

Method Detail

convertback to summary
public Value convert(CastDataProvider provider, Value v)

Convert a value to this column's type without precision and scale checks.

Parameters
provider:CastDataProvider

the cast information provider

v:Value

the value

Returns:Value

the value

convertback to summary
public static ValueRow convert(CastDataProvider provider, Column[] columns, ValueRow valueRow)

Converts the values in a ValueRow based on the passed column info. Creates a new instance if any of the contained item must be converted. Otherwise, returns the same valueRow.

Parameters
provider:CastDataProvider

the cast information provider

columns:Column[]

the column info list used for the conversation

valueRow:ValueRow

the holder of the values

Returns:ValueRow

a ValueRow which contains the converted values

See Also
Column#convert(CastDataProvider, Value)
copyback to summary
public void copy(Column source)

Copy the data of the source column into the current column.

Parameters
source:Column

the source column

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getCloneback to summary
public Column getClone()
getColumnIdback to summary
public int getColumnId()
getCommentback to summary
public String getComment()
getCreateSQLback to summary
public String getCreateSQL()
getCreateSQLback to summary
public String getCreateSQL(boolean forMeta)

Get this columns part of CREATE TABLE SQL statement.

Parameters
forMeta:boolean

whether this is for the metadata table

Returns:String

the SQL statement

getCreateSQLback to summary
private String getCreateSQL(StringBuilder builder, boolean forMeta)
getCreateSQLWithoutNameback to summary
public String getCreateSQLWithoutName()
getDataConversionErrorback to summary
private DbException getDataConversionError(Value value, DbException cause)
getDefaultExpressionback to summary
public Expression getDefaultExpression()

Implements org.h2.table.ColumnTemplate.getDefaultExpression.

Annotations
@Override
getDefaultOrGeneratedback to summary
private Value getDefaultOrGenerated(SessionLocal session, Row row)
getDefaultSQLback to summary
public String getDefaultSQL()

Implements org.h2.table.ColumnTemplate.getDefaultSQL.

Annotations
@Override
getDomainback to summary
public Domain getDomain()

Implements org.h2.table.ColumnTemplate.getDomain.

Annotations
@Override
getEffectiveDefaultExpressionback to summary
public Expression getEffectiveDefaultExpression()

Implements org.h2.table.ColumnTemplate.getEffectiveDefaultExpression.

Annotations
@Override
getEffectiveOnUpdateExpressionback to summary
public Expression getEffectiveOnUpdateExpression()

Implements org.h2.table.ColumnTemplate.getEffectiveOnUpdateExpression.

Annotations
@Override
getIdentityOptionsback to summary
public SequenceOptions getIdentityOptions()

Returns identity column options, or null if sequence was already created or this column is not an identity column.

Returns:SequenceOptions

identity column options, or null

getNameback to summary
public String getName()
getOnUpdateExpressionback to summary
public Expression getOnUpdateExpression()

Implements org.h2.table.ColumnTemplate.getOnUpdateExpression.

Annotations
@Override
getOnUpdateSQLback to summary
public String getOnUpdateSQL()

Implements org.h2.table.ColumnTemplate.getOnUpdateSQL.

Annotations
@Override
getSelectivityback to summary
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:int

the selectivity

getSequenceback to summary
public Sequence getSequence()
getSQLback to summary
public String getSQL(int sqlFlags)

Overrides default org.h2.util.HasSQL.getSQL.

Doc from org.h2.util.HasSQL.getSQL.

Get the SQL statement of this expression. This may not always be the original SQL statement, specially after optimization.

Parameters
sqlFlags:int

formatting flags

Returns:String

the SQL statement

Annotations
@Override
getSQLback to summary
public StringBuilder getSQL(StringBuilder builder, int sqlFlags)

Implements org.h2.util.HasSQL.getSQL.

Doc from org.h2.util.HasSQL.getSQL.

Appends the SQL statement of this object to the specified builder.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

Annotations
@Override
getSQLWithTableback to summary
public StringBuilder getSQLWithTable(StringBuilder builder, int sqlFlags)

Appends the table name and column name to the specified builder.

Parameters
builder:StringBuilder

the string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

getTableback to summary
public Table getTable()
getTypeback to summary
public TypeInfo getType()

Implements org.h2.value.Typed.getType.

Doc from org.h2.value.Typed.getType.

Returns the data type.

Returns:TypeInfo

the data type

Annotations
@Override
getVisibleback to summary
public boolean getVisible()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
hasIdentityOptionsback to summary
public boolean hasIdentityOptions()

Whether the column has any identity options.

Returns:boolean

true if yes

initializeSequenceback to summary
public void initializeSequence(SessionLocal session, Schema schema, int id, boolean temporary)

Initialize the sequence for this column.

Parameters
session:SessionLocal

the session

schema:Schema

the schema where the sequence should be generated

id:int

the object id

temporary:boolean

true if the sequence is temporary and does not need to be stored

isDefaultOnNullback to summary
public boolean isDefaultOnNull()
isEverythingback to summary
pack-priv boolean isEverything(ExpressionVisitor visitor)

Visit the default expression, the check constraint, and the sequence (if any).

Parameters
visitor:ExpressionVisitor

the visitor

Returns:boolean

true if every visited expression returned true, or if there are no expressions

isGeneratedback to summary
public boolean isGenerated()

Returns whether this column is a generated column.

Returns:boolean

whether this column is a generated column

isGeneratedAlwaysback to summary
public boolean isGeneratedAlways()

Returns whether this column is a generated column or always generated identity column.

Returns:boolean

whether this column is a generated column or always generated identity column

isIdentityback to summary
public boolean isIdentity()

Returns whether this column is an identity column.

Returns:boolean

whether this column is an identity column

isNullableback to summary
public boolean isNullable()
isPrimaryKeyback to summary
public boolean isPrimaryKey()
isRowIdback to summary
public boolean isRowId()

Returns whether this column is a row identity column.

Returns:boolean

true for _ROWID_ column, false otherwise

isWideningConversionback to summary
public boolean isWideningConversion(Column newColumn)

Check whether the new column is of the same type and not more restricted than this column.

Parameters
newColumn:Column

the new (target) column

Returns:boolean

true if the new column is compatible

prepareExpressionsback to summary
public void prepareExpressions(SessionLocal session)

Implements org.h2.table.ColumnTemplate.prepareExpressions.

Doc from org.h2.table.ColumnTemplate.prepareExpressions.

Prepare all expressions of this column or domain.

Parameters
session:SessionLocal

the session

Annotations
@Override
removeNonIdentityPropertiesback to summary
private void removeNonIdentityProperties()
renameback to summary
public void rename(String newName)

Rename the column. This method will only set the column name to the new value.

Parameters
newName:String

the new column name

setCommentback to summary
public void setComment(String comment)
setDefaultExpressionback to summary
public void setDefaultExpression(SessionLocal session, Expression defaultExpression)

Implements org.h2.table.ColumnTemplate.setDefaultExpression.

Doc from org.h2.table.ColumnTemplate.setDefaultExpression.

Set the default expression.

Parameters
session:SessionLocal

the session

defaultExpression:Expression

the default expression

Annotations
@Override
setDefaultOnNullback to summary
public void setDefaultOnNull(boolean defaultOnNull)
setDomainback to summary
public void setDomain(Domain domain)

Implements org.h2.table.ColumnTemplate.setDomain.

Annotations
@Override
setGeneratedExpressionback to summary
public void setGeneratedExpression(Expression expression)

Set the default value in the form of a generated expression of other columns.

Parameters
expression:Expression

the computed expression

setIdentityOptionsback to summary
public void setIdentityOptions(SequenceOptions identityOptions, boolean generatedAlways)

Set the identity options of this column.

Parameters
identityOptions:SequenceOptions

identity column options

generatedAlways:boolean

whether value should be always generated

setNullableback to summary
public void setNullable(boolean b)
setOnUpdateExpressionback to summary
public void setOnUpdateExpression(SessionLocal session, Expression onUpdateExpression)

Implements org.h2.table.ColumnTemplate.setOnUpdateExpression.

Doc from org.h2.table.ColumnTemplate.setOnUpdateExpression.

Set the on update expression.

Parameters
session:SessionLocal

the session

onUpdateExpression:Expression

the on update expression

Annotations
@Override
setPrimaryKeyback to summary
public void setPrimaryKey(boolean primaryKey)
setRowIdback to summary
public void setRowId(boolean rowId)

Set row identity flag.

Parameters
rowId:boolean

true _ROWID_ column, false otherwise

setSelectivityback to summary
public void setSelectivity(int selectivity)

Set the new selectivity of a column.

Parameters
selectivity:int

the new value

setSequenceback to summary
public void setSequence(Sequence sequence, boolean generatedAlways)

Set the sequence to generate the value.

Parameters
sequence:Sequence

the sequence

generatedAlways:boolean

whether the value of the sequence is always used

setTableback to summary
public void setTable(Table table, int columnId)

Set the table and column id.

Parameters
table:Table

the table

columnId:int

the column index

setVisibleback to summary
public void setVisible(boolean b)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateSequenceIfRequiredback to summary
private void updateSequenceIfRequired(SessionLocal session, long value)
validateConvertUpdateSequenceback to summary
pack-priv Value validateConvertUpdateSequence(SessionLocal session, Value value, Row row)

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. Domain constraints are validated as well.

Parameters
session:SessionLocal

the session

value:Value

the value or null

row:Row

the row

Returns:Value

the new or converted value

writeColumnsback to summary
public static StringBuilder writeColumns(StringBuilder builder, Column[] columns, int sqlFlags)

Appends the specified columns to the specified builder.

Parameters
builder:StringBuilder

string builder

columns:Column[]

columns

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

writeColumnsback to summary
public static StringBuilder writeColumns(StringBuilder builder, Column[] columns, String separator, String suffix, int sqlFlags)

Appends the specified columns to the specified builder.

Parameters
builder:StringBuilder

string builder

columns:Column[]

columns

separator:String

separator

suffix:String

additional SQL to append after each column

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder