net.sf.colle.sql.schema
Class Table

java.lang.Object
  extended bynet.sf.colle.sql.schema.Table

public class Table
extends Object

Model abstraction of a relational table. Created: 21 Feb 2001

Version:
$Revision: 1.7 $, $Date: 2004/07/11 18:39:48 $
Author:
Dwayne Schultz

Constructor Summary
(package private) Table(File pxFile, TableBuilder pxTableBuilder)
          Constructs a relational table from a node in a DOM tree.
  Table(String psName)
          Constructs a table with limited state (use for dropping foreign tables only).
 
Method Summary
(package private)  void addForeignKey(String psName, org.jdom.Element pxData, Column pxColumn)
          Constructs and adds the foreign key to the list of foreign keys.
(package private)  void addIndex(String psName, boolean pbUnique, Column pxColumn)
          Constructs and adds the index to the list of indexes.
(package private)  void connectForeignKeys(RelationalModel pxModel)
          Connects foreign keys to foreign indexes.
 void create(Connection pxConnection)
          Creates the table, dropping it first if necessary, in the database of the given connection.
 void drop(Connection pxConnection)
          Drops the table in the database of the given connection.
 boolean exists(Connection pxConnection)
          Checks if the table exist in the database of the given connection.
 List getColumns()
          Returns the full set of columns.
 File getFile()
          Returns the containing the table definition.
 Index getIndex(String psName)
          Returns a specific named index.
 Map getIndexes()
          Returns all of the indexes, not including the primary key and foreign keys.
 String getName()
          Returns the name of the table.
 String getPackage()
          Returns the name of the package.
 Index getPrimaryKey()
          Returns the primary key index.
 boolean hasReferenceTable(Table pxTable)
          Checks weather this table has a foreign key reference to the specified table.
 void index(Connection pxConnection)
          Creates indexes on this table in the database of the given connection.
 void indexForeignKeys(Connection pxConnection)
          Creates foreign key indexes on this table in the database of the given connection.
 boolean isSequence()
          check for sequences on table columns.
 void load(File pxCSVFile, Connection pxConnection)
          Loads the date from the file specified into this table in the database of the given connection.
 void lockTable(Connection pxConnection)
          Locks this table for multiple operations.
 void sequence(Connection pxConnection)
          Drop/Create sequences for columns within this table in the database of the given connection.
(package private)  void setPrimaryKey(Column pxColumn)
          Defines the column as part of the primary key.
 void unlockTable(Connection pxConnection)
          Unlocks this table when previously locked with lockTable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Table

public Table(String psName)
Constructs a table with limited state (use for dropping foreign tables only). Note that this table is not to be part of a schema.

Parameters:
psName - name of table that will be dropped.

Table

Table(File pxFile,
      TableBuilder pxTableBuilder)
Constructs a relational table from a node in a DOM tree.

Parameters:
pxFile - table node containing the table definition.
Method Detail

getFile

public File getFile()
Returns the containing the table definition.


getName

public String getName()
Returns the name of the table.

Returns:
name of the table.

getPackage

public String getPackage()
Returns the name of the package.


getColumns

public List getColumns()
Returns the full set of columns.


getIndex

public Index getIndex(String psName)
Returns a specific named index.


getIndexes

public Map getIndexes()
Returns all of the indexes, not including the primary key and foreign keys.


getPrimaryKey

public Index getPrimaryKey()
Returns the primary key index.


hasReferenceTable

public boolean hasReferenceTable(Table pxTable)
Checks weather this table has a foreign key reference to the specified table.


create

public void create(Connection pxConnection)
Creates the table, dropping it first if necessary, in the database of the given connection.


drop

public void drop(Connection pxConnection)
Drops the table in the database of the given connection.


exists

public boolean exists(Connection pxConnection)
Checks if the table exist in the database of the given connection.


load

public void load(File pxCSVFile,
                 Connection pxConnection)
Loads the date from the file specified into this table in the database of the given connection.


index

public void index(Connection pxConnection)
Creates indexes on this table in the database of the given connection.


indexForeignKeys

public void indexForeignKeys(Connection pxConnection)
Creates foreign key indexes on this table in the database of the given connection.


isSequence

public boolean isSequence()
check for sequences on table columns.


sequence

public void sequence(Connection pxConnection)
Drop/Create sequences for columns within this table in the database of the given connection.


lockTable

public void lockTable(Connection pxConnection)
               throws SQLException
Locks this table for multiple operations. This method should be used very sparingly when a large number of write operations will be performed on most of the records in the table. Calling this method may be a no-op as RDBMSs are not required to implement it. If locked, the table will remain locked until one of the following conditions is met: 1. unlockTable is called. 2. The current transaction is committed. 3. The connection is closed. Which of these conditions actually cause the table to become unlocked depends on the DBMS. It is therefore recommended that when possible all conditions are met to maintain compatibility across DBMSs.

Throws:
SQLException

unlockTable

public void unlockTable(Connection pxConnection)
                 throws SQLException
Unlocks this table when previously locked with lockTable. Calling this method may be a no-op as RDBMSs are not required to implement it. Some RDBMSs may unlock all currently locked tables when this method is called.

Throws:
SQLException

setPrimaryKey

void setPrimaryKey(Column pxColumn)
Defines the column as part of the primary key. The Column object calls this method as it constructs itself.

Parameters:
pxColumn - the column that is part of the primary key.

addIndex

void addIndex(String psName,
              boolean pbUnique,
              Column pxColumn)
Constructs and adds the index to the list of indexes. If the index already exists it is expanded to contain the specified column.

Parameters:
psName - name of the index, the table name and an underscore are prepended to the name before creation.
pbUnique - true if the index is an unique index.
pxColumn - the column that is part of the index.

addForeignKey

void addForeignKey(String psName,
                   org.jdom.Element pxData,
                   Column pxColumn)
Constructs and adds the foreign key to the list of foreign keys. If the foreign key already exists it is expanded to contain the specified column.

Parameters:
psName - name of the index, the table name and an underscore are prepended to the name before creation.
pxData - DOM node containing the foreign key information.
pxColumn - the column that is part of the index.

connectForeignKeys

void connectForeignKeys(RelationalModel pxModel)
Connects foreign keys to foreign indexes. This isn't done on the first pass because the order in which the tables are created isn't known and the table containing the foreign key may be created before the table containing the foreign index.