org.apache.derby.impl.sql.compile
Class TableElementList

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.QueryTreeNodeVector
          extended by org.apache.derby.impl.sql.compile.TableElementList
All Implemented Interfaces:
Visitable

public class TableElementList
extends QueryTreeNodeVector

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


Field Summary
private  int numColumns
           
private  TableDescriptor td
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
TableElementList()
           
 
Method Summary
 void addTableElement(TableElementNode tableElement)
          Add a TableElementNode to this TableElementList
 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.Hashtable ht, 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.Hashtable ht, 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)
           
 boolean containsColumnName(java.lang.String colName)
          Determine whether or not the parameter matches a column name in this list.
 int countConstraints(int constraintType)
          Count the number of constraints of the specified type.
 int countGenerationClauses()
          Count the number of generation clauses.
 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.
 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, 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 node
private  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, nondestructiveAppend, printSubNodes, remove, removeAllElements, removeElement, removeElementAt, setElementAt, size
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, foundString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, toString, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numColumns

private int numColumns

td

private TableDescriptor td
Constructor Detail

TableElementList

public TableElementList()
Method Detail

addTableElement

public 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 list
dd - DataDictionary to use
td - 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

public 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

public int countGenerationClauses()
Count the number of generation clauses.


countNumberOfColumns

public int countNumberOfColumns()
Count the number of columns.

Returns:
int The number of columns.

genColumnInfos

public 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

public 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,
                                           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 TABLE
isUnique - True means it will be a unique index
isUniqueWithDuplicateNulls - 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.
indexName - 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 on
constraintType -
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.Hashtable ht,
                                      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 list
ht - Hashtable for enforcing uniqueness.
colName - Column name to check for.
Throws:
StandardException - Thrown on error

checkForDuplicateConstraintNames

private void checkForDuplicateConstraintNames(DDLStatementNode ddlStmt,
                                              java.util.Hashtable ht,
                                              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 list
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 DDLStatementNode
cdn - 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 node
td - 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

public 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.

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.