com.ptc.windchill.upgrade.modeldiff
Class IndexInfo

java.lang.Object
  extended bycom.ptc.windchill.upgrade.modeldiff.IndexInfo

class IndexInfo
extends Object

This package private class encapsulates the all the information for one index.


Field Summary
private  String[] columns_
           
private  String conceptualSize_
           
private  boolean dropForAlterTableModify_
           
private static String DUMMY_INDEX_NAME
          Name of dummy index used for normalizing column names.
private  boolean hasColumnsThatAreFunctions_
           
private static int HASHMAP_INITIAL_CAPACITY
           
private  String indexDbName_
           
private  String indexName_
           
private  int indexType_
           
private  Boolean[] isExpression_
           
private  boolean new_
           
private  String[] nonNormalizedColumns_
           
private static HashMap normalizedColumnNameCache_
          Storage for the mapping of column names to their normalized column names.
private  boolean obsolete_
           
private  String previousIndexName_
           
private  String prexistingIndexName_
           
private  BaseTableInfo tableInfo_
           
private  String tableName_
           
private  String tableSpaceName_
           
 
Constructor Summary
(package private) IndexInfo()
          Used to get access to methods that do not need BaseTableInfo, or that supply the BaseTableInfo.
(package private) IndexInfo(BaseTableInfo tableInfo, String table_name, String index_name, int index_type, String column)
          Create an index on a single column.
(package private) IndexInfo(BaseTableInfo tableInfo, String table_name, String index_name, int index_type, String[] columns)
          Create an index on multiple columns.
(package private) IndexInfo(String table_name, String index_name, int index_type)
          Create an index from data from the database, not the class model, and set the columns later.
 
Method Summary
private static String[][] cloneColumnNames(String[][] in)
          Clones the data structure that holds Column Names.
(package private)  String column(int i)
          Get the i-th normalized column name used to define this index.
(package private)  int columnCount()
          Delivers the count of columns, independent of knowing the structure that holds them.
private  boolean createDummyIndex(Statement statement, String column_name)
          A dummy index is needed in order to prepare for the uncontrollable, automated re-naming performed by the database.
private  void dropDummyIndexSmotheringErrors(Statement statement)
           
(package private)  String generateCreateDDL()
          Produce a create statement for this index.
(package private)  String generateDropDDL()
          Produce a drop statement for this index.
(package private)  boolean getColumnIsAnExpression(int i)
           
(package private) static String[][] getComputedIndexColumns(BaseTableInfo tableInfo, boolean isUnique)
          Get the COMPOSITE UNIQUE indices or COMPOSITE NON-UNIQUE indices.
protected  String getIndexDbName()
           
protected  void getIndexDbName(String value_)
           
private  String getIndexFunctionExpression(String index_name, int position)
          Look up the function expression for columns that are named SYS_NC...##$.
protected  String getIndexName()
          Accessor for the index's name.
(package private)  int getIndexType()
          Accessor for the index's type.
protected  boolean getNew()
           
protected  boolean getObsolete()
           
(package private)  String getPreviousIndexName()
           
private  HashMap getTableColumnMapCache()
          Lookup the map of columnName to normalizedColumnName for the current index's tableName.
(package private)  String getTableName()
          Accessor for the index's Table name.
(package private)  boolean hasColumnsThatAreFunctions()
           
private  boolean indexesSameInformationAs(IndexInfo other_index)
          Tests whether the other index represents the same index on the same table as this one does.
(package private)  boolean indexesSameInformationInSameWayAs(IndexInfo other_index)
          Note that column names are case insensitive and that the "indexName_" and "tableInfo_" are NOT involved in determining equality.
protected  void indexName(int seq)
           
private  boolean isAnAllowedColumnName(String column_name)
          Is the column name just a normal column name (versus a column name generated by the database)? A normal column name has AlphaNumeric(s), maybe "_" characters, and maybe "$" characters.
(package private)  boolean isAPrimaryKey()
           
(package private)  boolean isTheNonNormalizedColumnAFunctionExpression(int position)
           
(package private)  boolean isTheNonNormalizedColumnNameAFunctionExpression(String non_normalized_column_name)
          Is the column name an oracle reference to a function expression?
(package private) static void lookupFbiRelatedDbTriggerNames(HashSet droppedFbiRelatedTriggerNames)
          Query the database for names of all triggers that are used to update Function Based Index (FBI) computed columns.
(package private)  void markDropForAlterTableModify()
           
(package private)  boolean markedDropForAlterTableModify()
           
(package private)  String nonNormalizedColumn(int position)
          A table's index is an ordered collection of nonNormalizedColumns.
private  String normalizeColumnName(DatabaseMetaData meta_data, String column_name)
          Create a dummy index from the column name and read back the column name on the created index.
private  void normalizeColumnNames()
           
(package private)  void putColumns(Hashtable cols)
          Add these columns to the collection of non-Normalized Columns.
(package private)  void setConceptualSize(String size)
          Change the conceptual size.
protected  void setIndexDbName(String index_name)
           
private  void setName(String index_name)
          Ensure that the name is of reasonable length.
protected  void setNew(boolean value_)
           
protected  void setObsolete(boolean value_)
           
(package private)  void setPreviousIndexName(String x)
           
(package private)  void setTableSpaceName(String x)
          Change the TableSpace name.
protected  void shortenNameIfApplicable()
           
 String toString()
          Override public toString() in the java.lang.Object class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HASHMAP_INITIAL_CAPACITY

private static int HASHMAP_INITIAL_CAPACITY

tableInfo_

private BaseTableInfo tableInfo_

indexName_

private String indexName_

previousIndexName_

private String previousIndexName_

tableName_

private String tableName_

tableSpaceName_

private String tableSpaceName_

conceptualSize_

private String conceptualSize_

prexistingIndexName_

private String prexistingIndexName_

indexType_

private int indexType_

isExpression_

private Boolean[] isExpression_

columns_

private String[] columns_

nonNormalizedColumns_

private String[] nonNormalizedColumns_

hasColumnsThatAreFunctions_

private boolean hasColumnsThatAreFunctions_

dropForAlterTableModify_

private boolean dropForAlterTableModify_

obsolete_

private boolean obsolete_

new_

private boolean new_

indexDbName_

private String indexDbName_

normalizedColumnNameCache_

private static HashMap normalizedColumnNameCache_
Storage for the mapping of column names to their normalized column names. Contents is tableName-&062;HashMap whose mapping is columnName-&062;normalizedColumnName.


DUMMY_INDEX_NAME

private static final String DUMMY_INDEX_NAME
Name of dummy index used for normalizing column names.

See Also:
Constant Field Values
Constructor Detail

IndexInfo

IndexInfo()
Used to get access to methods that do not need BaseTableInfo, or that supply the BaseTableInfo.


IndexInfo

IndexInfo(String table_name,
          String index_name,
          int index_type)
Create an index from data from the database, not the class model, and set the columns later. Since they are from the database, they will not have introspection BaseTableInfo.

Parameters:
table_name - The table that has the index.
index_name - An index name unique to that table.
index_type - A number that represents the index type.

IndexInfo

IndexInfo(BaseTableInfo tableInfo,
          String table_name,
          String index_name,
          int index_type,
          String column)
    throws CompareSchemaException
Create an index on a single column.

Parameters:
tableInfo - Table information obtained from Target Model introspection.
table_name - The table that has the index.
index_name - An index name unique to that table.
index_type - A number that represents the index type.
Throws:
CompareSchemaException - Forwarded from normalizeColumnNames().

IndexInfo

IndexInfo(BaseTableInfo tableInfo,
          String table_name,
          String index_name,
          int index_type,
          String[] columns)
    throws CompareSchemaException
Create an index on multiple columns.

Parameters:
tableInfo - Table information obtained from Target Model introspection.
table_name - The table that has the index.
index_name - An index name unique to that table.
index_type - A number that represents the index type.
columns - An array of multiple column names.
Throws:
CompareSchemaException - Forwarded from normalizeColumnNames().
Method Detail

toString

public String toString()
Override public toString() in the java.lang.Object class. This method is public because of the java.lang.Object class.

Returns:
This index, as represented as an understandable string.

getIndexName

protected String getIndexName()
Accessor for the index's name.

Returns:
The index's name.

getPreviousIndexName

String getPreviousIndexName()

setPreviousIndexName

void setPreviousIndexName(String x)

getTableName

String getTableName()
Accessor for the index's Table name.

Returns:
The name of the table that has the index.

getIndexType

int getIndexType()
Accessor for the index's type.

Returns:
A number that represents the index type.

setTableSpaceName

void setTableSpaceName(String x)
Change the TableSpace name.

Parameters:
x - The new TableSpace name.

setConceptualSize

void setConceptualSize(String size)
Change the conceptual size.

Parameters:
size - The new conceptual size.

getColumnIsAnExpression

boolean getColumnIsAnExpression(int i)

column

String column(int i)
Get the i-th normalized column name used to define this index.

Parameters:
i - Identify one of the columns in this IndexInfo.
Returns:
The chosen column's name.

nonNormalizedColumn

String nonNormalizedColumn(int position)
A table's index is an ordered collection of nonNormalizedColumns.

Parameters:
position - The index for one column in the column array.
Returns:
The chosen column's nonNormalized name.

hasColumnsThatAreFunctions

boolean hasColumnsThatAreFunctions()

markDropForAlterTableModify

void markDropForAlterTableModify()

markedDropForAlterTableModify

boolean markedDropForAlterTableModify()

columnCount

int columnCount()
Delivers the count of columns, independent of knowing the structure that holds them. Allows the code to read more like English.

Returns:
The total number of column names.

putColumns

void putColumns(Hashtable cols)
          throws CompareSchemaException
Add these columns to the collection of non-Normalized Columns.

Parameters:
cols - The columns that are to be added to the collection.
Throws:
CompareSchemaException - If the normalizeColumnNames failed.

indexesSameInformationInSameWayAs

boolean indexesSameInformationInSameWayAs(IndexInfo other_index)
Note that column names are case insensitive and that the "indexName_" and "tableInfo_" are NOT involved in determining equality.

Parameters:
other_index - The other index to compare against.
Returns:
True, if it is the same index, even thought it may have a different name.

isAPrimaryKey

boolean isAPrimaryKey()

generateCreateDDL

String generateCreateDDL()
Produce a create statement for this index. Note: does NOT handle Primary Key indices. These should be created with the table only.

Returns:
The executable SQL/DDL to create an index.

generateDropDDL

String generateDropDDL()
Produce a drop statement for this index.

Returns:
The executable SQL/DDL to drop an index.

getComputedIndexColumns

static String[][] getComputedIndexColumns(BaseTableInfo tableInfo,
                                          boolean isUnique)
Get the COMPOSITE UNIQUE indices or COMPOSITE NON-UNIQUE indices.

Parameters:
tableInfo - All the definitions for a table.
isUnique - True if results have only uniqueness indices.
Returns:
A String[][] structure that contains all the indexes' ColumnNames.

lookupFbiRelatedDbTriggerNames

static void lookupFbiRelatedDbTriggerNames(HashSet droppedFbiRelatedTriggerNames)
                                    throws CompareSchemaException
Query the database for names of all triggers that are used to update Function Based Index (FBI) computed columns.

Parameters:
droppedFbiRelatedTriggerNames - Adds triggers to this HashSet.
Throws:
CompareSchemaException - The original SQLException is in the log.

setName

private void setName(String index_name)
Ensure that the name is of reasonable length. If it's oversized then pull out the middle.

Parameters:
index_name - A potentially new name that is not to long, but is adequately unique.

setIndexDbName

protected void setIndexDbName(String index_name)

indexName

protected void indexName(int seq)

shortenNameIfApplicable

protected void shortenNameIfApplicable()

indexesSameInformationAs

private boolean indexesSameInformationAs(IndexInfo other_index)
Tests whether the other index represents the same index on the same table as this one does.

Parameters:
other_index - The other index to compare against.
Returns:
True, if it is the same index, even thought it may have a different name.

getTableColumnMapCache

private HashMap getTableColumnMapCache()
Lookup the map of columnName to normalizedColumnName for the current index's tableName.

Returns:
The map of columnName to normalizedColumnName.

normalizeColumnNames

private void normalizeColumnNames()
                           throws CompareSchemaException
Throws:
CompareSchemaException

isAnAllowedColumnName

private boolean isAnAllowedColumnName(String column_name)
Is the column name just a normal column name (versus a column name generated by the database)? A normal column name has AlphaNumeric(s), maybe "_" characters, and maybe "$" characters. It does not have function-like characters like ( ) + - * / , | like an evaluated link to a column Expression (that is a function). It does not start with "SYS_" and end with "$" like a link to a column Expression.

Parameters:
column_name - Test this column name.
Returns:
True if the ColumnName is a normal name (non-generated).

isTheNonNormalizedColumnNameAFunctionExpression

boolean isTheNonNormalizedColumnNameAFunctionExpression(String non_normalized_column_name)
Is the column name an oracle reference to a function expression?

Parameters:
non_normalized_column_name - The column name.
Returns:
True if the column name is a Function Expression.

isTheNonNormalizedColumnAFunctionExpression

boolean isTheNonNormalizedColumnAFunctionExpression(int position)

getIndexFunctionExpression

private String getIndexFunctionExpression(String index_name,
                                          int position)
                                   throws CompareSchemaException
Look up the function expression for columns that are named SYS_NC...##$.

Parameters:
index_name - The name of an index.
position - The COLUMN_POSITION in the result set.
Returns:
The expression to evaluate that is this index.
Throws:
CompareSchemaException - A converted SQLException.

normalizeColumnName

private String normalizeColumnName(DatabaseMetaData meta_data,
                                   String column_name)
                            throws CompareSchemaException
Create a dummy index from the column name and read back the column name on the created index. This will ensure that the column name is formatted consistently according to the database engine. Columns that don't exist or which are function expressions referencing non-existent columns will be returned as is.

Parameters:
meta_data - All the meta data.
column_name - One column name.
Returns:
The normalized column name that the database is using, instead.
Throws:
CompareSchemaException - A converted SQLException.

dropDummyIndexSmotheringErrors

private void dropDummyIndexSmotheringErrors(Statement statement)

createDummyIndex

private final boolean createDummyIndex(Statement statement,
                                       String column_name)
                                throws SQLException
A dummy index is needed in order to prepare for the uncontrollable, automated re-naming performed by the database.

Parameters:
statement - The information needed to perform the execution in the database.
column_name - The dummy index's name.
Returns:
True, if the index creation was successful.
Throws:
SQLException - If an error occurred, but not due to an invalid column name.

setObsolete

protected void setObsolete(boolean value_)

setNew

protected void setNew(boolean value_)

getIndexDbName

protected void getIndexDbName(String value_)

getObsolete

protected boolean getObsolete()

getNew

protected boolean getNew()

getIndexDbName

protected String getIndexDbName()

cloneColumnNames

private static String[][] cloneColumnNames(String[][] in)
Clones the data structure that holds Column Names.

Parameters:
in - A String[][] structure that contains all the indexes' ColumnNames.
Returns:
A String[][] structure that contains all the indexes' ColumnNames.