Class TableElementList
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.QueryTreeNodeVector<TableElementNode>
-
- org.apache.derby.impl.sql.compile.TableElementList
-
- All Implemented Interfaces:
java.lang.Iterable<TableElementNode>
,Visitable
class TableElementList extends QueryTreeNodeVector<TableElementNode>
A TableElementList represents the list of columns and other table elements such as constraints in a CREATE TABLE or ALTER TABLE statement.
-
-
Field Summary
Fields Modifier and Type Field Description private int
numColumns
private TableDescriptor
td
-
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNodeVector
eltClass
-
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description TableElementList(ContextManager cm)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addTableElement(TableElementNode tableElement)
Add a TableElementNode to this TableElementList(package private) void
appendNewColumnsToRCL(FromBaseTable table)
Append goobered up ResultColumns to the table's RCL.private boolean
areColumnsNullable(ConstraintDefinitionNode cdn, TableDescriptor td)
Checks if any of the columns in the constraint can be null.(package private) void
bindAndValidateCheckConstraints(FromList fromList)
Bind and validate all of the check constraints in this list against the specified FromList.(package private) void
bindAndValidateGenerationClauses(SchemaDescriptor sd, FromList fromList, FormatableBitSet generatedColumns, TableDescriptor baseTable)
Bind and validate all of the generation clauses in this list against the specified FromList.private void
checkForDuplicateColumns(DDLStatementNode ddlStmt, java.util.Set<java.lang.String> seenNames, java.lang.String colName)
Check to make sure that there are no duplicate column names in the list.private void
checkForDuplicateConstraintNames(DDLStatementNode ddlStmt, java.util.Set<java.lang.String> seenNames, java.lang.String constraintName)
Check to make sure that there are no duplicate constraint names in the list.private void
checkForNullColumns(ConstraintDefinitionNode cdn, TableDescriptor td)
private java.util.Properties
checkIndexPageSizeProperty(ConstraintDefinitionNode cdn)
Checks if the index should use a larger page size.private boolean
columnsMatch(java.lang.String[] columnNames1, java.lang.String[] columnNames2)
(package private) boolean
containsColumnName(java.lang.String colName)
Determine whether or not the parameter matches a column name in this list.(package private) int
countConstraints(int constraintType)
Count the number of constraints of the specified type.(package private) int
countGenerationClauses()
Count the number of generation clauses.(package private) int
countNumberOfColumns()
Count the number of columns.private ColumnDefinitionNode
findColumnDefinition(java.lang.String colName)
Find the column definition node in this list that matches the passed in column name.(package private) void
findIllegalGenerationReferences(FromList fromList, TableDescriptor baseTable)
Complain if a generation clause references other generated columns.(package private) int
genColumnInfos(ColumnInfo[] colInfos)
Fill in the ColumnInfo[] for this table element list.(package private) void
genConstraintActions(boolean forCreateTable, ConstraintConstantAction[] conActions, java.lang.String tableName, SchemaDescriptor tableSd, DataDictionary dd)
Fill in the ConstraintConstantAction[] for this create/alter table.private IndexConstantAction
genIndexAction(boolean forCreateTable, boolean isUnique, boolean isUniqueWithDuplicateNulls, boolean hasDeferrableChecking, boolean initiallyDeferred, java.lang.String indexName, ConstraintDefinitionNode cdn, java.lang.String[] columnNames, boolean isConstraint, SchemaDescriptor sd, java.lang.String tableName, int constraintType, DataDictionary dd)
utility to generated the call to create the index.private DataTypeDescriptor
getColumnDataTypeDescriptor(java.lang.String colName)
private DataTypeDescriptor
getColumnDataTypeDescriptor(java.lang.String colName, TableDescriptor td)
(package private) void
setCollationTypeOnCharacterStringColumn(SchemaDescriptor sd, ColumnDefinitionNode cdn)
Use the passed schema descriptor's collation type to set the collation of a character string column.(package private) void
setCollationTypesOnCharacterStringColumns(SchemaDescriptor sd)
Use the passed schema descriptor's collation type to set the collation of the character string types in create table nodeprivate void
setColumnListToNotNull(ConstraintDefinitionNode cdn)
Set all columns in that appear in a PRIMARY KEY constraint in a CREATE TABLE statement to NOT NULL.(package private) void
validate(DDLStatementNode ddlStmt, DataDictionary dd, TableDescriptor td)
Validate this TableElementList.(package private) void
validateForeignKeysOnGenerationClauses(FromList fromList, FormatableBitSet generatedColumns)
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. void
validatePrimaryKeyNullability()
Validate nullability of primary keys.private void
verifyUniqueColumnList(DDLStatementNode ddlStmt, ConstraintDefinitionNode cdn)
Verify that a primary/unique table constraint has a valid column list.-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNodeVector
acceptChildren, addElement, destructiveAppend, elementAt, indexOf, insertElementAt, iterator, nondestructiveAppend, printSubNodes, removeAllElements, removeElement, removeElementAt, setElementAt, size
-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, toString, treePrint, treePrint, verifyClassExist
-
-
-
-
Field Detail
-
numColumns
private int numColumns
-
td
private TableDescriptor td
-
-
Constructor Detail
-
TableElementList
public TableElementList(ContextManager cm)
-
-
Method Detail
-
addTableElement
void addTableElement(TableElementNode tableElement)
Add a TableElementNode to this TableElementList- Parameters:
tableElement
- The TableElementNode to add to this list
-
setCollationTypesOnCharacterStringColumns
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- Parameters:
sd
-- Throws:
StandardException
-
setCollationTypeOnCharacterStringColumn
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.- Parameters:
sd
-- Throws:
StandardException
-
validate
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 which contains this listdd
- DataDictionary to usetd
- TableDescriptor for table, if existing table.- Throws:
StandardException
- Thrown on error
-
validatePrimaryKeyNullability
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.- Throws:
StandardException
-
countConstraints
int countConstraints(int constraintType)
Count the number of constraints of the specified type.- Parameters:
constraintType
- The constraint type to search for.- Returns:
- int The number of constraints of the specified type.
-
countGenerationClauses
int countGenerationClauses()
Count the number of generation clauses.
-
countNumberOfColumns
int countNumberOfColumns()
Count the number of columns.- Returns:
- int The number of columns.
-
genColumnInfos
int genColumnInfos(ColumnInfo[] colInfos) throws StandardException
Fill in the ColumnInfo[] for this table element list.- Parameters:
colInfos
- The ColumnInfo[] to be filled in.- Returns:
- int The number of constraints in the create table.
- Throws:
StandardException
-
appendNewColumnsToRCL
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
- The table in question.- Throws:
StandardException
- Thrown on error
-
bindAndValidateCheckConstraints
void bindAndValidateCheckConstraints(FromList fromList) throws StandardException
Bind and validate all of the check constraints in this list against the specified FromList.- Parameters:
fromList
- The FromList in question.- Throws:
StandardException
- Thrown on error
-
bindAndValidateGenerationClauses
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
- Schema where the table lives.fromList
- The FromList in question.generatedColumns
- 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
- Table descriptor if this is an ALTER TABLE statement.- Throws:
StandardException
- Thrown on error
-
findIllegalGenerationReferences
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
- The FromList in question.baseTable
- Table descriptor if this is an ALTER TABLE statement.- Throws:
StandardException
- Thrown on error
-
validateForeignKeysOnGenerationClauses
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
- The FromList in question.generatedColumns
- Bitmap of generated columns in the table.- Throws:
StandardException
- Thrown on error
-
genConstraintActions
void genConstraintActions(boolean forCreateTable, ConstraintConstantAction[] conActions, java.lang.String tableName, SchemaDescriptor tableSd, DataDictionary dd) throws StandardException
Fill in the ConstraintConstantAction[] for this create/alter table.- Parameters:
forCreateTable
- ConstraintConstantAction is for a create table.conActions
- The ConstraintConstantAction[] to be filled in.tableName
- The name of the Table being created.tableSd
- The schema for that table.dd
- The DataDictionary- Throws:
StandardException
- Thrown on failure
-
columnsMatch
private boolean columnsMatch(java.lang.String[] columnNames1, java.lang.String[] columnNames2)
-
genIndexAction
private IndexConstantAction genIndexAction(boolean forCreateTable, boolean isUnique, boolean isUniqueWithDuplicateNulls, boolean hasDeferrableChecking, boolean initiallyDeferred, java.lang.String indexName, ConstraintDefinitionNode cdn, java.lang.String[] columnNames, boolean isConstraint, SchemaDescriptor sd, java.lang.String tableName, int constraintType, DataDictionary dd) throws StandardException
utility to generated the call to create the index.- Parameters:
forCreateTable
- Executed as part of a CREATE TABLEisUnique
- True means it will be a unique indexisUniqueWithDuplicateNulls
- 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
- True if index is used to back a deferrable constraintinitiallyDeferred
- True means the deferrable constraint has deferred modeindexName
- The type of index (BTREE, for example)cdn
-columnNames
- Names of the columns in the index, in order.isConstraint
- TRUE if index is backing up a constraint, else FALSE.sd
-tableName
- Name of table the index will be onconstraintType
-dd
-- Throws:
StandardException
-
checkIndexPageSizeProperty
private java.util.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
- Constraint node- Returns:
- properties to use for creating the index
- Throws:
StandardException
-
checkForDuplicateColumns
private void checkForDuplicateColumns(DDLStatementNode ddlStmt, java.util.Set<java.lang.String> seenNames, java.lang.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 which contains this listseenNames
- The column names seen so far (for enforcing uniqueness)colName
- Column name to check for.- Throws:
StandardException
- Thrown on error
-
checkForDuplicateConstraintNames
private void checkForDuplicateConstraintNames(DDLStatementNode ddlStmt, java.util.Set<java.lang.String> seenNames, java.lang.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 which contains this listseenNames
- The constraint names seen so far (for enforcing uniqueness)- Throws:
StandardException
- Thrown on error
-
verifyUniqueColumnList
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
- The outer DDLStatementNodecdn
- The ConstraintDefinitionNode- Throws:
StandardException
- Thrown if the column list is invalid
-
setColumnListToNotNull
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
- The ConstraintDefinitionNode for a PRIMARY KEY constraint
-
areColumnsNullable
private boolean areColumnsNullable(ConstraintDefinitionNode cdn, TableDescriptor td)
Checks if any of the columns in the constraint can be null.- Parameters:
cdn
- Constraint nodetd
- tabe descriptor of the target table- Returns:
- true if any of the column can be null false other wise
-
checkForNullColumns
private void checkForNullColumns(ConstraintDefinitionNode cdn, TableDescriptor td) throws StandardException
- Throws:
StandardException
-
getColumnDataTypeDescriptor
private DataTypeDescriptor getColumnDataTypeDescriptor(java.lang.String colName)
-
getColumnDataTypeDescriptor
private DataTypeDescriptor getColumnDataTypeDescriptor(java.lang.String colName, TableDescriptor td)
-
findColumnDefinition
private ColumnDefinitionNode findColumnDefinition(java.lang.String colName)
Find the column definition node in this list that matches the passed in column name.- Parameters:
colName
-- Returns:
- Reference to column definition node or null if the column is not in the list.
-
containsColumnName
boolean containsColumnName(java.lang.String colName)
Determine whether or not the parameter matches a column name in this list.- Parameters:
colName
- The column name to search for.- Returns:
- boolean Whether or not a match is found.
-
-