Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class TableElementList

extends QueryTreeNodeVector<TableElementNode>
Class Inheritance
Imports
java.util.ArrayList, .HashSet, .List, .Properties, .Set, org.apache.derby.catalog.UUID, org.apache.derby.catalog.types.DefaultInfoImpl, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.Property, .SQLState, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.services.property.PropertyUtil, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.StatementType, org.apache.derby.iapi.sql.compile.CompilerContext, org.apache.derby.iapi.sql.depend.DependencyManager, .ProviderInfo, .ProviderList, org.apache.derby.iapi.sql.dictionary.ColumnDescriptor, .ColumnDescriptorList, .ConstraintDescriptor, .ConstraintDescriptorList, .DataDictionary, .SchemaDescriptor, .TableDescriptor, org.apache.derby.iapi.types.DataTypeDescriptor, .TypeId, org.apache.derby.impl.sql.execute.ColumnInfo, .ConstraintConstantAction, .ConstraintInfo, .IndexConstantAction

A TableElementList represents the list of columns and other table elements such as constraints in a CREATE TABLE or ALTER TABLE statement.

Field Summary

Modifier and TypeField and Description
private int
private TableDescriptor
Inherited from org.apache.derby.impl.sql.compile.QueryTreeNodeVector:
eltClass

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addTableElement(TableElementNode
The TableElementNode to add to this list
tableElement
)

Add a TableElementNode to this TableElementList

pack-priv void
appendNewColumnsToRCL(FromBaseTable
The table in question.
table
)

Append goobered up ResultColumns to the table's RCL.

private boolean

Returns:

true if any of the column can be null false other wise
areColumnsNullable
(ConstraintDefinitionNode
Constraint node
cdn
,
TableDescriptor
tabe descriptor of the target table
td
)

Checks if any of the columns in the constraint can be null.

pack-priv void
bindAndValidateCheckConstraints(FromList
The FromList in question.
fromList
)

Bind and validate all of the check constraints in this list against the specified FromList.

pack-priv void
bindAndValidateGenerationClauses(SchemaDescriptor
Schema where the table lives.
sd
,
FromList
The FromList in question.
fromList
,
FormatableBitSet
Bitmap of generated columns in the table. Vacuous for CREATE TABLE, but may be non-trivial for ALTER TABLE. This routine may set bits for new generated columns.
generatedColumns
,
TableDescriptor
Table descriptor if this is an ALTER TABLE statement.
baseTable
)

Bind and validate all of the generation clauses in this list against the specified FromList.

private void
checkForDuplicateColumns(DDLStatementNode
DDLStatementNode which contains this list
ddlStmt
,
Set<String>
The column names seen so far (for enforcing uniqueness)
seenNames
,
String
Column name to check for.
colName
)

Check to make sure that there are no duplicate column names in the list.

private void
checkForDuplicateConstraintNames(DDLStatementNode
DDLStatementNode which contains this list
ddlStmt
,
Set<String>
The constraint names seen so far (for enforcing uniqueness)
seenNames
,
String constraintName)

Check to make sure that there are no duplicate constraint names in the list.

private void
private Properties

Returns:

properties to use for creating the index
checkIndexPageSizeProperty
(ConstraintDefinitionNode
Constraint node
cdn
)

Checks if the index should use a larger page size.

private boolean
columnsMatch(String[] columnNames1, String[] columnNames2)

pack-priv boolean

Returns:

boolean Whether or not a match is found.
containsColumnName
(String
The column name to search for.
colName
)

Determine whether or not the parameter matches a column name in this list.

pack-priv int

Returns:

int The number of constraints of the specified type.
countConstraints
(int
The constraint type to search for.
constraintType
)

Count the number of constraints of the specified type.

pack-priv int
countGenerationClauses()

Count the number of generation clauses.

pack-priv int

Returns:

int The number of columns.
countNumberOfColumns
()

Count the number of columns.

private ColumnDefinitionNode

Returns:

Reference to column definition node or null if the column is not in the list.
findColumnDefinition
(String colName)

Find the column definition node in this list that matches the passed in column name.

pack-priv void
findIllegalGenerationReferences(FromList
The FromList in question.
fromList
,
TableDescriptor
Table descriptor if this is an ALTER TABLE statement.
baseTable
)

Complain if a generation clause references other generated columns.

pack-priv int

Returns:

int The number of constraints in the create table.
genColumnInfos
(ColumnInfo[]
The ColumnInfo[] to be filled in.
colInfos
)

Fill in the ColumnInfo[] for this table element list.

pack-priv void
genConstraintActions(boolean
ConstraintConstantAction is for a create table.
forCreateTable
,
ConstraintConstantAction[]
The ConstraintConstantAction[] to be filled in.
conActions
,
String
The name of the Table being created.
tableName
,
SchemaDescriptor
The schema for that table.
tableSd
,
DataDictionary
The DataDictionary
dd
)

Fill in the ConstraintConstantAction[] for this create/alter table.

private IndexConstantAction
genIndexAction(boolean
Executed as part of a CREATE TABLE
forCreateTable
,
boolean
True means it will be a unique index
isUnique
,
boolean
True means index check and disallow any duplicate key if key has no column with a null value. If any column in the key has a null value, no checking is done and insert will always succeed.
isUniqueWithDuplicateNulls
,
boolean
True if index is used to back a deferrable constraint
hasDeferrableChecking
,
boolean
True means the deferrable constraint has deferred mode
initiallyDeferred
,
String
The type of index (BTREE, for example)
indexName
,
ConstraintDefinitionNode cdn, String[]
Names of the columns in the index, in order.
columnNames
,
boolean
TRUE if index is backing up a constraint, else FALSE.
isConstraint
,
SchemaDescriptor sd, String
Name of table the index will be on
tableName
,
int constraintType, DataDictionary dd)

utility to generated the call to create the index.

private DataTypeDescriptor
private DataTypeDescriptor
pack-priv void
setCollationTypeOnCharacterStringColumn(SchemaDescriptor sd, ColumnDefinitionNode cdn)

Use the passed schema descriptor's collation type to set the collation of a character string column.

pack-priv void
setCollationTypesOnCharacterStringColumns(SchemaDescriptor sd)

Use the passed schema descriptor's collation type to set the collation of the character string types in create table node

private void
setColumnListToNotNull(ConstraintDefinitionNode
The ConstraintDefinitionNode for a PRIMARY KEY constraint
cdn
)

Set all columns in that appear in a PRIMARY KEY constraint in a CREATE TABLE statement to NOT NULL.

pack-priv void
validate(DDLStatementNode
DDLStatementNode which contains this list
ddlStmt
,
DataDictionary
DataDictionary to use
dd
,
TableDescriptor
TableDescriptor for table, if existing table.
td
)

Validate this TableElementList.

pack-priv void
validateForeignKeysOnGenerationClauses(FromList
The FromList in question.
fromList
,
FormatableBitSet
Bitmap of generated columns in the table.
generatedColumns
)

Prevent foreign keys on generated columns from violating the SQL spec, part 2, section 11.8 (<column definition>), syntax rule 12: the referential action may not specify SET NULL or SET DEFAULT and the update rule may not specify ON UPDATE CASCADE.

public void
validatePrimaryKeyNullability()

Validate nullability of primary keys.

private void
verifyUniqueColumnList(DDLStatementNode
The outer DDLStatementNode
ddlStmt
,
ConstraintDefinitionNode
The ConstraintDefinitionNode
cdn
)

Verify that a primary/unique table constraint has a valid column list.

Inherited from org.apache.derby.impl.sql.compile.QueryTreeNodeVector:
acceptChildrenaddElementdestructiveAppendelementAtindexOfinsertElementAtiteratornondestructiveAppendprintSubNodesremoveAllElementsremoveElementremoveElementAtsetElementAtsize

Field Detail

numColumnsback to summary
private int numColumns
tdback to summary
private TableDescriptor td

Constructor Detail

TableElementListback to summary
public TableElementList(ContextManager cm)

Method Detail

addTableElementback to summary
pack-priv void addTableElement(TableElementNode tableElement)

Add a TableElementNode to this TableElementList

Parameters
tableElement:TableElementNode

The TableElementNode to add to this list

appendNewColumnsToRCLback to summary
pack-priv void appendNewColumnsToRCL(FromBaseTable table) throws StandardException

Append goobered up ResultColumns to the table's RCL. This is useful for binding check constraints for CREATE and ALTER TABLE.

Parameters
table:FromBaseTable

The table in question.

Exceptions
StandardException:
Thrown on error
areColumnsNullableback to summary
private boolean areColumnsNullable(ConstraintDefinitionNode cdn, TableDescriptor td)

Checks if any of the columns in the constraint can be null.

Parameters
cdn:ConstraintDefinitionNode

Constraint node

td:TableDescriptor

tabe descriptor of the target table

Returns:boolean

true if any of the column can be null false other wise

bindAndValidateCheckConstraintsback to summary
pack-priv void bindAndValidateCheckConstraints(FromList fromList) throws StandardException

Bind and validate all of the check constraints in this list against the specified FromList.

Parameters
fromList:FromList

The FromList in question.

Exceptions
StandardException:
Thrown on error
bindAndValidateGenerationClausesback to summary
pack-priv void bindAndValidateGenerationClauses(SchemaDescriptor sd, FromList fromList, FormatableBitSet generatedColumns, TableDescriptor baseTable) throws StandardException

Bind and validate all of the generation clauses in this list against the specified FromList.

Parameters
sd:SchemaDescriptor

Schema where the table lives.

fromList:FromList

The FromList in question.

generatedColumns:FormatableBitSet

Bitmap of generated columns in the table. Vacuous for CREATE TABLE, but may be non-trivial for ALTER TABLE. This routine may set bits for new generated columns.

baseTable:TableDescriptor

Table descriptor if this is an ALTER TABLE statement.

Exceptions
StandardException:
Thrown on error
checkForDuplicateColumnsback to summary
private void checkForDuplicateColumns(DDLStatementNode ddlStmt, Set<String> seenNames, String colName) throws StandardException

Check to make sure that there are no duplicate column names in the list. (The comparison here is case sensitive. The work of converting column names that are not quoted identifiers to upper case is handled by the parser.)

Resolve

This check will also be performed by alter table.

Parameters
ddlStmt:DDLStatementNode

DDLStatementNode which contains this list

seenNames:Set<String>

The column names seen so far (for enforcing uniqueness)

colName:String

Column name to check for.

Exceptions
StandardException:
Thrown on error
checkForDuplicateConstraintNamesback to summary
private void checkForDuplicateConstraintNames(DDLStatementNode ddlStmt, Set<String> seenNames, String constraintName) throws StandardException

Check to make sure that there are no duplicate constraint names in the list. (The comparison here is case sensitive. The work of converting column names that are not quoted identifiers to upper case is handled by the parser.)

Resolve

This check will also be performed by alter table.

Parameters
ddlStmt:DDLStatementNode

DDLStatementNode which contains this list

seenNames:Set<String>

The constraint names seen so far (for enforcing uniqueness)

Exceptions
StandardException:
Thrown on error
checkForNullColumnsback to summary
private void checkForNullColumns(ConstraintDefinitionNode cdn, TableDescriptor td) throws StandardException
checkIndexPageSizePropertyback to summary
private Properties checkIndexPageSizeProperty(ConstraintDefinitionNode cdn) throws StandardException

Checks if the index should use a larger page size. If the columns in the index are large, and if the user hasn't already specified a page size to use, then we may need to default to the large page size in order to get an index with sufficiently large pages. For example, this DDL should use a larger page size for the index that backs the PRIMARY KEY constraint: create table t (x varchar(1000) primary key)

Parameters
cdn:ConstraintDefinitionNode

Constraint node

Returns:Properties

properties to use for creating the index

columnsMatchback to summary
private boolean columnsMatch(String[] columnNames1, String[] columnNames2)
containsColumnNameback to summary
pack-priv boolean containsColumnName(String colName)

Determine whether or not the parameter matches a column name in this list.

Parameters
colName:String

The column name to search for.

Returns:boolean

boolean Whether or not a match is found.

countConstraintsback to summary
pack-priv int countConstraints(int constraintType)

Count the number of constraints of the specified type.

Parameters
constraintType:int

The constraint type to search for.

Returns:int

int The number of constraints of the specified type.

countGenerationClausesback to summary
pack-priv int countGenerationClauses()

Count the number of generation clauses.

countNumberOfColumnsback to summary
pack-priv int countNumberOfColumns()

Count the number of columns.

Returns:int

int The number of columns.

findColumnDefinitionback to summary
private ColumnDefinitionNode findColumnDefinition(String colName)

Find the column definition node in this list that matches the passed in column name.

Returns:ColumnDefinitionNode

Reference to column definition node or null if the column is not in the list.

findIllegalGenerationReferencesback to summary
pack-priv void findIllegalGenerationReferences(FromList fromList, TableDescriptor baseTable) throws StandardException

Complain if a generation clause references other generated columns. This is required by the SQL Standard, part 2, section 4.14.8.

Parameters
fromList:FromList

The FromList in question.

baseTable:TableDescriptor

Table descriptor if this is an ALTER TABLE statement.

Exceptions
StandardException:
Thrown on error
genColumnInfosback to summary
pack-priv int genColumnInfos(ColumnInfo[] colInfos) throws StandardException

Fill in the ColumnInfo[] for this table element list.

Parameters
colInfos:ColumnInfo[]

The ColumnInfo[] to be filled in.

Returns:int

int The number of constraints in the create table.

genConstraintActionsback to summary
pack-priv void genConstraintActions(boolean forCreateTable, ConstraintConstantAction[] conActions, String tableName, SchemaDescriptor tableSd, DataDictionary dd) throws StandardException

Fill in the ConstraintConstantAction[] for this create/alter table.

Parameters
forCreateTable:boolean

ConstraintConstantAction is for a create table.

conActions:ConstraintConstantAction[]

The ConstraintConstantAction[] to be filled in.

tableName:String

The name of the Table being created.

tableSd:SchemaDescriptor

The schema for that table.

dd:DataDictionary

The DataDictionary

Exceptions
StandardException:
Thrown on failure
genIndexActionback to summary
private IndexConstantAction genIndexAction(boolean forCreateTable, boolean isUnique, boolean isUniqueWithDuplicateNulls, boolean hasDeferrableChecking, boolean initiallyDeferred, String indexName, ConstraintDefinitionNode cdn, String[] columnNames, boolean isConstraint, SchemaDescriptor sd, String tableName, int constraintType, DataDictionary dd) throws StandardException

utility to generated the call to create the index.

Parameters
forCreateTable:boolean

Executed as part of a CREATE TABLE

isUnique:boolean

True means it will be a unique index

isUniqueWithDuplicateNulls:boolean

True means index check and disallow any duplicate key if key has no column with a null value. If any column in the key has a null value, no checking is done and insert will always succeed.

hasDeferrableChecking:boolean

True if index is used to back a deferrable constraint

initiallyDeferred:boolean

True means the deferrable constraint has deferred mode

indexName:String

The type of index (BTREE, for example)

columnNames:String[]

Names of the columns in the index, in order.

isConstraint:boolean

TRUE if index is backing up a constraint, else FALSE.

tableName:String

Name of table the index will be on

getColumnDataTypeDescriptorback to summary
private DataTypeDescriptor getColumnDataTypeDescriptor(String colName)
getColumnDataTypeDescriptorback to summary
private DataTypeDescriptor getColumnDataTypeDescriptor(String colName, TableDescriptor td)
setCollationTypeOnCharacterStringColumnback to summary
pack-priv void setCollationTypeOnCharacterStringColumn(SchemaDescriptor sd, ColumnDefinitionNode cdn) throws StandardException

Use the passed schema descriptor's collation type to set the collation of a character string column.

setCollationTypesOnCharacterStringColumnsback to summary
pack-priv void setCollationTypesOnCharacterStringColumns(SchemaDescriptor sd) throws StandardException

Use the passed schema descriptor's collation type to set the collation of the character string types in create table node

setColumnListToNotNullback to summary
private void setColumnListToNotNull(ConstraintDefinitionNode cdn)

Set all columns in that appear in a PRIMARY KEY constraint in a CREATE TABLE statement to NOT NULL.

Parameters
cdn:ConstraintDefinitionNode

The ConstraintDefinitionNode for a PRIMARY KEY constraint

validateback to summary
pack-priv void validate(DDLStatementNode ddlStmt, DataDictionary dd, TableDescriptor td) throws StandardException

Validate this TableElementList. This includes checking for duplicate columns names, and checking that user types really exist.

Parameters
ddlStmt:DDLStatementNode

DDLStatementNode which contains this list

dd:DataDictionary

DataDictionary to use

td:TableDescriptor

TableDescriptor for table, if existing table.

Exceptions
StandardException:
Thrown on error
validateForeignKeysOnGenerationClausesback to summary
pack-priv void validateForeignKeysOnGenerationClauses(FromList fromList, FormatableBitSet generatedColumns) throws StandardException

Prevent foreign keys on generated columns from violating the SQL spec, part 2, section 11.8 (), syntax rule 12: the referential action may not specify SET NULL or SET DEFAULT and the update rule may not specify ON UPDATE CASCADE.

Parameters
fromList:FromList

The FromList in question.

generatedColumns:FormatableBitSet

Bitmap of generated columns in the table.

Exceptions
StandardException:
Thrown on error
validatePrimaryKeyNullabilityback to summary
public void validatePrimaryKeyNullability() throws StandardException

Validate nullability of primary keys. This logic was moved out of the main validate method so that it can be called after binding generation clauses. We need to perform the nullability checks later on because the datatype may be omitted on the generation clause--we can't set/vet the nullability of the datatype until we determine what the datatype is.

verifyUniqueColumnListback to summary
private void verifyUniqueColumnList(DDLStatementNode ddlStmt, ConstraintDefinitionNode cdn) throws StandardException

Verify that a primary/unique table constraint has a valid column list. (All columns in table and no duplicates.)

Parameters
ddlStmt:DDLStatementNode

The outer DDLStatementNode

cdn:ConstraintDefinitionNode

The ConstraintDefinitionNode

Exceptions
StandardException:
Thrown if the column list is invalid