org.afcs.warts.db
Class TableDescription

java.lang.Object
  extended byorg.afcs.warts.db.TableDescription

public final class TableDescription
extends java.lang.Object

A TableDescription class contains information about a particular database table, including the source account, the descriptions of each column, and the number of primary key columns.

LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.

Version:
Last Modified 4 February 2004
Author:
Warren Hedley ( whedley at sdsc dot edu )

Constructor Summary
TableDescription(AccountConfiguration accountConfiguration, java.lang.String owner, java.lang.String name, java.util.List columnDescriptions, int numPrimaryColumns, boolean fakePrimaryKeys)
          Initialises a new table description with the specified information.
 
Method Summary
 int bindPrimaryKeyValues(java.sql.PreparedStatement statement, java.util.List primaryKeyValues, int offset)
          This method loops through the specified list of primary key values, using the column descriptions maintained internally to bind them to variables in the specified prepared statement, starting at the specified offset.
 boolean dataHandlersOK()
          Returns true if valid data handlers exist for the primary key columns in this table.
 java.lang.String describeFirstEquivalenceIssue(TableDescription anotherTableDescription)
          Returns a text description of the first reason that can be found for this table not being equivalent to the specified table.
 boolean equals(java.lang.Object otherObj)
          Returns true if the current table description describes the same table reached via the same account configuration as the specified object.
 TableDescription findEquivalentDescription(java.util.List accountConfigurations, AccountConfiguration preferredAccount)
          This method looks through all of the tables reachable through the account configurations in the specified list, returning the first table that is equivalent to the current table (but isn't in the current account), or null if no equivalent table can be found.
 AccountConfiguration getAccountConfiguration()
          Returns the account configuration used to load this table.
 ColumnDescription getColumnDescription(int columnIndex)
          Returns the column description for the specified column.
 java.util.List getColumnDescriptions()
          Returns an unmodifiable list containing all of the columns in this table, with primary key columns first.
 java.lang.String getName()
          Returns the name of the table.
 java.util.List getNonPrimaryColumns()
          Returns an unmodifiable list containing the primary key columns in this table.
 int getNumNonPrimaryKeyColumns()
          Returns the number of non-primary key columns.
 int getNumPrimaryKeyColumns()
          Returns the number of primary key columns.
 java.lang.String getOwner()
          Returns the owner of the table.
 java.util.List getPrimaryKeyColumns()
          Returns an unmodifiable list containing the non-primary key columns in this table.
 java.lang.String getQualifiedName()
          Returns the qualified name of the table, which is in the form 'owner.name'.
 java.lang.String getQualifiedNameSql()
          Returns the qualified name of the table for use in SQL statements, which is in the form '"owner"."name"'.
 java.lang.String getQualifiedNameWithAccount()
          Returns the qualified name of the table with information about the account from which the table was referenced (which includes the machine name).
 java.lang.String getWhereClause()
          Returns the where clause appropriate for use in a prepared statement that will be selecting or updating a value given primary key values that identify the row.
 boolean hasFakePrimaryColumns()
          Returns true if the primary key columns in this table are not actually primary key columns.
 int hashCode()
          Returns a hashcode for this instance that obeys the general contract.
 boolean isEquivalentTo(TableDescription anotherTableDescription)
          Returns true if the specified table is equivalent to this one.
 java.lang.String toString()
          Returns a text description of the current instance that can be used for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TableDescription

public TableDescription(AccountConfiguration accountConfiguration,
                        java.lang.String owner,
                        java.lang.String name,
                        java.util.List columnDescriptions,
                        int numPrimaryColumns,
                        boolean fakePrimaryKeys)
Initialises a new table description with the specified information.

Parameters:
accountConfiguration - The account configuration from which the table was loaded.
owner - The owner of the table (which is not necessarily the owner of the account used to load the table). This is case sensitive.
name - The name of the table, which is case sensitive.
columnDescriptions - The list of columns in the table.
numPrimaryColumns - The number of primary key columns.
fakePrimaryKeys - Whether or not the primary key columns are fake. This can be used when a table has no primary key columns, in which case all columns are taken to be primary key columns.
Method Detail

bindPrimaryKeyValues

public int bindPrimaryKeyValues(java.sql.PreparedStatement statement,
                                java.util.List primaryKeyValues,
                                int offset)
                         throws java.sql.SQLException
This method loops through the specified list of primary key values, using the column descriptions maintained internally to bind them to variables in the specified prepared statement, starting at the specified offset.

Parameters:
statement - The prepared statement to bind values to.
primaryKeyValues - The list of primary key values.
offset - The variable index to start binding variables at.
Returns:
The variable index that the next variable should be bound to.
Throws:
java.sql.SQLException - If a SQL error occurs while binding any errors.
java.lang.NullPointerException - If statement or primaryKeyValues is null.
java.lang.IllegalArgumentException - If the length of primaryKeyValues is less than the number of primary key columns.

dataHandlersOK

public boolean dataHandlersOK()
Returns true if valid data handlers exist for the primary key columns in this table. The data from a table can not be loaded without primary keys, as there would then be no way to distinguish the rows.

Returns:
True if valid data handlers exist for the primary key columns in this table.

hasFakePrimaryColumns

public boolean hasFakePrimaryColumns()
Returns true if the primary key columns in this table are not actually primary key columns. This can be used when a table has no primary key columns, in which case all columns are taken to be primary key columns.

Returns:
True if the primary key columns in this table are not actually primary key columns.

getName

public java.lang.String getName()
Returns the name of the table. This doesn't include any owner or account information.

Returns:
The name of the table.

getNumNonPrimaryKeyColumns

public int getNumNonPrimaryKeyColumns()
Returns the number of non-primary key columns.

Returns:
The number of non-primary key columns.

getNumPrimaryKeyColumns

public int getNumPrimaryKeyColumns()
Returns the number of primary key columns.

Returns:
The number of primary key columns.

getOwner

public java.lang.String getOwner()
Returns the owner of the table. Note that is not necessarily the same as the owner of the account from which the table was loaded. The value is case sensitive.

Returns:
The owner of the table.

getQualifiedName

public java.lang.String getQualifiedName()
Returns the qualified name of the table, which is in the form 'owner.name'.

Returns:
The qualified name of the table.

getQualifiedNameSql

public java.lang.String getQualifiedNameSql()
Returns the qualified name of the table for use in SQL statements, which is in the form '"owner"."name"'.

Returns:
The qualified name of the table for use in SQL statements.

getQualifiedNameWithAccount

public java.lang.String getQualifiedNameWithAccount()
Returns the qualified name of the table with information about the account from which the table was referenced (which includes the machine name). The result is in the form 'owner.name from user/instance@machine'.

Returns:
The qualified name of the table, with information about the account from which the table was referenced.

getColumnDescription

public ColumnDescription getColumnDescription(int columnIndex)
Returns the column description for the specified column.

Parameters:
columnIndex - The index of the column to look up.
Returns:
The column description for the specified column.
Throws:
java.lang.IllegalArgumentException - If columnIndex is out of bounds.

getColumnDescriptions

public java.util.List getColumnDescriptions()
Returns an unmodifiable list containing all of the columns in this table, with primary key columns first.

Returns:
A list of all of the columns in this table.

getNonPrimaryColumns

public java.util.List getNonPrimaryColumns()
Returns an unmodifiable list containing the primary key columns in this table.

Returns:
An unmodifiable list containing the primary key columns in this table.

getPrimaryKeyColumns

public java.util.List getPrimaryKeyColumns()
Returns an unmodifiable list containing the non-primary key columns in this table.

Returns:
An unmodifiable list containing the non-primary key columns in this table.

getAccountConfiguration

public AccountConfiguration getAccountConfiguration()
Returns the account configuration used to load this table.

Returns:
The account configuration used to load this table.

getWhereClause

public java.lang.String getWhereClause()
Returns the where clause appropriate for use in a prepared statement that will be selecting or updating a value given primary key values that identify the row. bindPrimaryKeyValues(java.sql.PreparedStatement, java.util.List, int) can then be used to bind primary key values to the SQL statement generated.

Returns:
The where clause of a prepared statement that identifies a single row by its primary key columns.

isEquivalentTo

public boolean isEquivalentTo(TableDescription anotherTableDescription)
Returns true if the specified table is equivalent to this one. Two table descriptions are considered equivalent if all of the columns in each table are identical. Note that column size is not currently considered because of a bug in the Oracle JDBC drivers that prevents the correct column size from being returned for character columns with character length semantics.

Parameters:
anotherTableDescription - The other table description to compare to this one.
Returns:
True if the specified table is equivalent to this one.
Throws:
java.lang.NullPointerException - If anotherTableDescription is null.

describeFirstEquivalenceIssue

public java.lang.String describeFirstEquivalenceIssue(TableDescription anotherTableDescription)
Returns a text description of the first reason that can be found for this table not being equivalent to the specified table. If isEquivalentTo(org.afcs.warts.db.TableDescription) returns false for the same table, this is useful for finding out why. It will return null if the tables are equivalent.

Parameters:
anotherTableDescription - The other table to compare the current instance to.
Returns:
A text description of the first reason that can be found for this table not being equivalent to the specified table, or null if they are equivalent.
Throws:
java.lang.NullPointerException - If anotherTableDescription is null.

findEquivalentDescription

public TableDescription findEquivalentDescription(java.util.List accountConfigurations,
                                                  AccountConfiguration preferredAccount)
This method looks through all of the tables reachable through the account configurations in the specified list, returning the first table that is equivalent to the current table (but isn't in the current account), or null if no equivalent table can be found. Equivalence is judged using isEquivalentTo(TableDescription).

Parameters:
accountConfigurations - The list of account configurations to search.
preferredAccount - If this is non-null, then we look for equivalent tables in this account first and return any matches if found.
Returns:
The first table reachable through the specified account configurations that is equivalent to the current table, (but isn't in the current account), or null if no equivalent table can be found.
Throws:
java.lang.NullPointerException - If accountConfigurations is null.

equals

public boolean equals(java.lang.Object otherObj)
Returns true if the current table description describes the same table reached via the same account configuration as the specified object.

Parameters:
otherObj - The other object to compare this instance to.
Returns:
True if this instance is equal to the specified instance.

hashCode

public int hashCode()
Returns a hashcode for this instance that obeys the general contract.

Returns:
A hashcode for this instance.

toString

public java.lang.String toString()
Returns a text description of the current instance that can be used for debugging purposes.

Returns:
A text description of the current instance that can be used for debugging purposes.