Package org.h2.table
Class Column
java.lang.Object
org.h2.table.Column
- All Implemented Interfaces:
ColumnTemplate,HasSQL,Typed
This class represents a column in a table.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThis column is not nullable.static final intThis column is nullable.static final intIt is not know whether this column is nullable.static final StringThe name of the rowid pseudo column.Fields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ValueRowconvert(CastDataProvider provider, Column[] columns, ValueRow valueRow) Converts the values in a ValueRow based on the passed column info.convert(CastDataProvider provider, Value v) Convert a value to this column's type without precision and scale checks.voidCopy the data of the source column into the current column.booleangetClone()intgetCreateSQL(boolean forMeta) Get this columns part of CREATE TABLE SQL statement.Returns identity column options, ornullif sequence was already created or this column is not an identity column.getName()intGet the selectivity of the column.getSQL(int sqlFlags) Get the SQL statement of this expression.getSQL(StringBuilder builder, int sqlFlags) Appends the SQL statement of this object to the specified builder.getSQLWithTable(StringBuilder builder, int sqlFlags) Appends the table name and column name to the specified builder.getTable()getType()Returns the data type.booleaninthashCode()booleanWhether the column has any identity options.voidinitializeSequence(SessionLocal session, Schema schema, int id, boolean temporary) Initialize the sequence for this column.booleanbooleanReturns whether this column is a generated column.booleanReturns whether this column is a generated column or always generated identity column.booleanReturns whether this column is an identity column.booleanbooleanbooleanisRowId()Returns whether this column is a row identity column.booleanisWideningConversion(Column newColumn) Check whether the new column is of the same type and not more restricted than this column.voidprepareExpressions(SessionLocal session) Prepare all expressions of this column or domain.voidRename the column.voidsetComment(String comment) voidsetDefaultExpression(SessionLocal session, Expression defaultExpression) Set the default expression.voidsetDefaultOnNull(boolean defaultOnNull) voidvoidsetGeneratedExpression(Expression expression) Set the default value in the form of a generated expression of other columns.voidsetIdentityOptions(SequenceOptions identityOptions, boolean generatedAlways) Set the identity options of this column.voidsetNullable(boolean b) voidsetOnUpdateExpression(SessionLocal session, Expression onUpdateExpression) Set the on update expression.voidsetPrimaryKey(boolean primaryKey) voidsetRowId(boolean rowId) Set row identity flag.voidsetSelectivity(int selectivity) Set the new selectivity of a column.voidsetSequence(Sequence sequence, boolean generatedAlways) Set the sequence to generate the value.voidSet the table and column id.voidvoidsetVisible(boolean b) toString()static StringBuilderwriteColumns(StringBuilder builder, Column[] columns, int sqlFlags) Appends the specified columns to the specified builder.static StringBuilderwriteColumns(StringBuilder builder, Column[] columns, String separator, String suffix, int sqlFlags) Appends the specified columns to the specified builder.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
Field Details
-
ROWID
The name of the rowid pseudo column.- See Also:
-
NOT_NULLABLE
public static final int NOT_NULLABLEThis column is not nullable.- See Also:
-
NULLABLE
public static final int NULLABLEThis column is nullable.- See Also:
-
NULLABLE_UNKNOWN
public static final int NULLABLE_UNKNOWNIt is not know whether this column is nullable.- See Also:
-
-
Constructor Details
-
Column
-
Column
-
-
Method Details
-
writeColumns
Appends the specified columns to the specified builder.- Parameters:
builder- string buildercolumns- columnssqlFlags- formatting flags- Returns:
- the specified string builder
-
writeColumns
public static StringBuilder writeColumns(StringBuilder builder, Column[] columns, String separator, String suffix, int sqlFlags) Appends the specified columns to the specified builder.- Parameters:
builder- string buildercolumns- columnsseparator- separatorsuffix- additional SQL to append after each columnsqlFlags- formatting flags- Returns:
- the specified string builder
-
equals
-
hashCode
public int hashCode() -
getClone
-
convert
Convert a value to this column's type without precision and scale checks.- Parameters:
provider- the cast information providerv- the value- Returns:
- the value
-
convert
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 samevalueRow.- Parameters:
provider- the cast information providercolumns- the column info list used for the conversationvalueRow- the holder of the values- Returns:
- a ValueRow which contains the converted values
- See Also:
-
isIdentity
public boolean isIdentity()Returns whether this column is an identity column.- Returns:
- whether this column is an identity column
-
isGenerated
public boolean isGenerated()Returns whether this column is a generated column.- Returns:
- whether this column is a generated column
-
isGeneratedAlways
public boolean isGeneratedAlways()Returns whether this column is a generated column or always generated identity column.- Returns:
- whether this column is a generated column or always generated identity column
-
setGeneratedExpression
Set the default value in the form of a generated expression of other columns.- Parameters:
expression- the computed expression
-
setTable
Set the table and column id.- Parameters:
table- the tablecolumnId- the column index
-
getTable
-
setDefaultExpression
Description copied from interface:ColumnTemplateSet the default expression.- Specified by:
setDefaultExpressionin interfaceColumnTemplate- Parameters:
session- the sessiondefaultExpression- the default expression
-
setOnUpdateExpression
Description copied from interface:ColumnTemplateSet the on update expression.- Specified by:
setOnUpdateExpressionin interfaceColumnTemplate- Parameters:
session- the sessiononUpdateExpression- the on update expression
-
getColumnId
public int getColumnId() -
getSQL
Description copied from interface:HasSQLGet the SQL statement of this expression. This may not always be the original SQL statement, specially after optimization. -
getSQL
Description copied from interface:HasSQLAppends the SQL statement of this object to the specified builder. -
getSQLWithTable
Appends the table name and column name to the specified builder.- Parameters:
builder- the string buildersqlFlags- formatting flags- Returns:
- the specified string builder
-
getName
-
getType
Description copied from interface:TypedReturns the data type. -
setType
-
setNullable
public void setNullable(boolean b) -
getVisible
public boolean getVisible() -
setVisible
public void setVisible(boolean b) -
getDomain
- Specified by:
getDomainin interfaceColumnTemplate
-
setDomain
- Specified by:
setDomainin interfaceColumnTemplate
-
isRowId
public boolean isRowId()Returns whether this column is a row identity column.- Returns:
- true for _ROWID_ column, false otherwise
-
setRowId
public void setRowId(boolean rowId) Set row identity flag.- Parameters:
rowId- true _ROWID_ column, false otherwise
-
initializeSequence
Initialize the sequence for this column.- Parameters:
session- the sessionschema- the schema where the sequence should be generatedid- the object idtemporary- true if the sequence is temporary and does not need to be stored
-
prepareExpressions
Description copied from interface:ColumnTemplatePrepare all expressions of this column or domain.- Specified by:
prepareExpressionsin interfaceColumnTemplate- Parameters:
session- the session
-
getCreateSQLWithoutName
-
getCreateSQL
-
getCreateSQL
Get this columns part of CREATE TABLE SQL statement.- Parameters:
forMeta- whether this is for the metadata table- Returns:
- the SQL statement
-
isNullable
public boolean isNullable() -
getDefaultExpression
- Specified by:
getDefaultExpressionin interfaceColumnTemplate
-
getEffectiveDefaultExpression
- Specified by:
getEffectiveDefaultExpressionin interfaceColumnTemplate
-
getOnUpdateExpression
- Specified by:
getOnUpdateExpressionin interfaceColumnTemplate
-
getEffectiveOnUpdateExpression
- Specified by:
getEffectiveOnUpdateExpressionin interfaceColumnTemplate
-
hasIdentityOptions
public boolean hasIdentityOptions()Whether the column has any identity options.- Returns:
- true if yes
-
setIdentityOptions
Set the identity options of this column.- Parameters:
identityOptions- identity column optionsgeneratedAlways- whether value should be always generated
-
getIdentityOptions
Returns identity column options, ornullif sequence was already created or this column is not an identity column.- Returns:
- identity column options, or
null
-
setDefaultOnNull
public void setDefaultOnNull(boolean defaultOnNull) -
isDefaultOnNull
public boolean isDefaultOnNull() -
rename
Rename the column. This method will only set the column name to the new value.- Parameters:
newName- the new column name
-
setSequence
Set the sequence to generate the value.- Parameters:
sequence- the sequencegeneratedAlways- whether the value of the sequence is always used
-
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
-
getDefaultSQL
- Specified by:
getDefaultSQLin interfaceColumnTemplate
-
getOnUpdateSQL
- Specified by:
getOnUpdateSQLin interfaceColumnTemplate
-
setComment
-
getComment
-
setPrimaryKey
public void setPrimaryKey(boolean primaryKey) -
isPrimaryKey
public boolean isPrimaryKey() -
toString
-
isWideningConversion
Check whether the new column is of the same type and not more restricted than this column.- Parameters:
newColumn- the new (target) column- Returns:
- true if the new column is compatible
-
copy
Copy the data of the source column into the current column.- Parameters:
source- the source column
-