com.ibm.dse.tools.workbench.base
Class AbstractTable

java.lang.Object
  |
  +--com.ibm.dse.tools.workbench.base.AbstractTable
Direct Known Subclasses:
AllowedValuesTable, AttributesTable, DomainsTable, EntitiesEntitiesTable, GroupsEntitiesTable, GroupsGroupsTable, GroupsInstancesTable, InstanceErrorsTable, PropertiesTable, UsersTable, VersionableTable

public abstract class AbstractTable
extends java.lang.Object
implements Table, TableNames

This class represents a generic database table


Field Summary
protected  java.lang.String alias
          The Table Name Alias, Used to generate PK Names
protected  CheckConstraint[] checks
          The list of column check constraints
protected  int[] columnLengths
          The list of column lengths
protected  java.lang.String[] columns
          The list of column names
static char DATA_DELIMITER
          The delimiter for the data in data exchange files (Imports and Exports)
static char DATA_SEPARATOR
          The separator for the data in data exchange files (Imports and Exports)
protected  java.util.Hashtable deletedRows
          The list of deleted rows since the last commit or rollback
static char ESCAPE_SEQUENCE
          The escape sequence for the data in data exchange files (Imports and Exports)
protected  java.util.Hashtable fks
          The list of foreign keys with other tables
protected  Index[] indexes
          The list of indexes
protected  java.util.Hashtable insertedRows
          The list of inserted rows since the last commit or rollback
protected  java.util.Hashtable modifiedRows
          The list of modified rows since the last commit or rollback
protected  java.lang.String name
          The name of the table
protected  int[] pk
          The list of columns in the primary key
protected  Relationship[] relations
          The list of relationships with other tables
protected  Repository repository
          The repository where the table is located
protected  boolean[] required
          The list of column mandatory indicators
protected  OrderedHashtable rows
          The list of cached rows
protected  boolean triggers
          Switch to deactivate triggers when importing data
 
Fields inherited from interface com.ibm.dse.tools.workbench.base.TableNames
ALLOWED_VALUES, ATTRIBUTES, DOMAINS, ENTITIES, ENTITIES_ENTITIES, GROUPS, GROUPS_ENTITIES, GROUPS_GROUPS, GROUPS_INSTANCES, INSTANCE_ERRORS, INSTANCES, PROPERTIES, USERS
 
Constructor Summary
AbstractTable()
          This constructor creates an AbstractTable object
AbstractTable(Repository repository)
          This constructor creates an AbstractTable object in a repository.
 
Method Summary
 void add(TableRow row)
          This method adds a row to the list of rows.
 boolean areTriggersActive()
          This method returns the triggers state
 void cleanRollbackData()
          This method cleans the lists of inserted, modified and deleted rows, and marks them as commited.
 int count(Clause where)
          This method counts the rows that accomplish the conditions in the where clause
abstract  void createRelations()
          This method creates the relationships for a table
 TableRow createTableRow()
          This method creates a new TableRow object for this table.
 TableRow createTableRow(boolean isNew, java.lang.String[] values)
          This method creates a TableRow object for this table with a list of values for the columns.
 void exportToFile(java.io.Writer w)
          This method sends the table data to a file writer.
 void flush()
          This method persists the modifications, creations or deletions of rows in this table
 java.lang.String getAlias()
          This method returns the table alias.
 CheckConstraint[] getChecks()
          Returns the list of check constraints for this table
 CheckConstraint[] getChecks(int column)
          Returns the list of check constraints for a column of the table
 int[] getColumnLengths()
          Returns the list of column lengths.
 java.lang.String[] getColumns()
          Returns the list of column names for this table
 java.lang.String getColumnsString(int[] columnsList, java.lang.String separator)
          This method constructs a String with column names to use in clauses like select, order by, insert, ...
 java.lang.String getColumnsString(java.lang.String separator)
          This method constructs a String with all column names to use in clauses like select...
 java.sql.Connection getConnection()
          Returns the connection to the database for this table
 java.lang.String[] getCreateChecksStrings()
          This method returns the list of sentences to create the check constraints for the table.
 java.lang.String[] getCreateFksStrings()
          This method returns the list of sentences to create the foreign keys for the table.
 java.lang.String[] getCreateIndexesStrings()
          This method returns the list of sentences to create the indexes for the table.
 java.lang.String getCreatePkString()
          This method returns the sentence to create the primary key for the table.
 java.lang.String getCreateTableString()
          This method returns the sentence to create the table.
 java.lang.String getDefaultVersion()
          Returns a default version code
 java.util.Hashtable getFks()
          Returns the list of foreign keys that this table has with other tables
 Index[] getIndexes()
          Returns the list of indexes.
 java.lang.String getName()
          Returns the name of the table
 int[] getPk()
          Returns the list of column identifiers that are part of the primary key of this table
 java.lang.String getPkValue(TableRow row)
          Returns the Values in the primary key of a row in a String with separators
 TableRow[] getRelated(int relation, java.lang.String[] values, Clause where, int[] orderBy)
          Returns the rows of another table based on a relationship
 Relationship[] getRelations()
          Returns the list of relationships that this table has with other tables
 Repository getRepository()
          Returns repository in which this table is created
 java.lang.String getTimestamp()
          Returns a timestamp value
 java.lang.String getUniqueValue()
          Returns a unique value for generation of unique identifiers (primary keys) purpose
abstract  boolean hasSelfGeneratedPk()
          This method indicates if the field in the primary key must be generated automatically
 void importFromString(java.lang.String s)
          This method inserts data into the table from a String that can be read from a stream
 boolean isInPk(int column)
          Checks if a column is part of the primary key
 boolean isRequired(int column)
          Checks if a column in the table is mandatory
 void postDelete(TableRow row)
          This method is called after a row is deleted
 void postInsert(TableRow row)
          This method is called after a row is inserted
 void postUpdate(TableRow row)
          This method is called after a row is updated
 void preDelete(TableRow row)
          This method is called before deleting a row
 void preInsert(TableRow row)
          This method is called before inserting a row
 void preUpdate(TableRow row)
          This method is called before modifying a row
 void registerDeletedRow(TableRow row)
          This method adds a row to the list of deleted rows
 void registerInsertedRow(TableRow row)
          This method adds a row to the list of inserted rows
 void registerModifiedRow(TableRow row)
          This method adds a row to the list of modified rows
 void removeFromList(TableRow row)
          This method removes a row from the list of rows
 void restoreRows()
          This method restores the mapped rows when doing a rollback
 TableRow[] retrieveAll(Clause where, int[] orderBy)
          Returns all the rows that accomplish the conditions in the where Clause
 TableRow retrieveByPk(java.lang.String[] values)
          Returns the row corresponding to the values of the primary key
 java.lang.String[] retrieveDistinct(int column, Clause where)
          This method retrieves the distinct values in a column in the rows that accomplish the conditions in a where clause
protected  void setAlias(java.lang.String newAlias)
          This method sets the alias for the table
 void setRepository(Repository repository)
          Sets the repository where this table is located
 void setTriggersState(boolean active)
          This method sets the triggers state
abstract  java.lang.String[] validate(TableRow row)
          This abstract method must validate the correctness of a row based on the rules of each object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columns

protected java.lang.String[] columns
The list of column names

required

protected boolean[] required
The list of column mandatory indicators

columnLengths

protected int[] columnLengths
The list of column lengths

name

protected java.lang.String name
The name of the table

pk

protected int[] pk
The list of columns in the primary key

relations

protected Relationship[] relations
The list of relationships with other tables

checks

protected CheckConstraint[] checks
The list of column check constraints

indexes

protected Index[] indexes
The list of indexes

repository

protected Repository repository
The repository where the table is located

rows

protected OrderedHashtable rows
The list of cached rows

fks

protected java.util.Hashtable fks
The list of foreign keys with other tables

alias

protected java.lang.String alias
The Table Name Alias, Used to generate PK Names

DATA_DELIMITER

public static final char DATA_DELIMITER
The delimiter for the data in data exchange files (Imports and Exports)

ESCAPE_SEQUENCE

public static final char ESCAPE_SEQUENCE
The escape sequence for the data in data exchange files (Imports and Exports)

DATA_SEPARATOR

public static final char DATA_SEPARATOR
The separator for the data in data exchange files (Imports and Exports)

modifiedRows

protected java.util.Hashtable modifiedRows
The list of modified rows since the last commit or rollback

insertedRows

protected java.util.Hashtable insertedRows
The list of inserted rows since the last commit or rollback

deletedRows

protected java.util.Hashtable deletedRows
The list of deleted rows since the last commit or rollback

triggers

protected boolean triggers
Switch to deactivate triggers when importing data
Constructor Detail

AbstractTable

public AbstractTable()
This constructor creates an AbstractTable object

AbstractTable

public AbstractTable(Repository repository)
This constructor creates an AbstractTable object in a repository.
Parameters:
repository - com.ibm.dse.tools.workbench.base.DefaultRepository
Method Detail

add

public void add(TableRow row)
This method adds a row to the list of rows.
Specified by:
add in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow

areTriggersActive

public boolean areTriggersActive()
This method returns the triggers state
Specified by:
areTriggersActive in interface Table
Returns:
boolean

cleanRollbackData

public void cleanRollbackData()
This method cleans the lists of inserted, modified and deleted rows, and marks them as commited.
Specified by:
cleanRollbackData in interface Table

count

public int count(Clause where)
          throws RepositoryException
This method counts the rows that accomplish the conditions in the where clause
Specified by:
count in interface Table
Parameters:
where - com.ibm.dse.tools.workbench.base.Clause The where clause to apply
Returns:
int
Throws:
RepositoryException - An error ocurred doing the query.

createRelations

public abstract void createRelations()
                              throws WBInvalidArgumentException
This method creates the relationships for a table
Specified by:
createRelations in interface Table
Throws:
WBInvalidArgumentException - There is an error creating relationships.

createTableRow

public TableRow createTableRow()
                        throws WorkbenchException
This method creates a new TableRow object for this table.
Specified by:
createTableRow in interface Table
Returns:
com.ibm.dse.tools.workbench.base.TableRow
Throws:
WorkbenchException -  

createTableRow

public TableRow createTableRow(boolean isNew,
                               java.lang.String[] values)
                        throws WorkbenchException
This method creates a TableRow object for this table with a list of values for the columns.

It can be new or retrieved

Specified by:
createTableRow in interface Table
Parameters:
isNew - boolean
values - java.lang.String[]
Returns:
com.ibm.dse.tools.workbench.base.TableRow
Throws:
WorkbenchException -  

exportToFile

public void exportToFile(java.io.Writer w)
                  throws WorkbenchException,
                         java.io.IOException
This method sends the table data to a file writer.
Specified by:
exportToFile in interface Table
Parameters:
w - java.io.Writer
Throws:
WorkbenchException -  
java.io.IOException -  

flush

public void flush()
           throws RepositoryException
This method persists the modifications, creations or deletions of rows in this table
Specified by:
flush in interface Table
Throws:
RepositoryException - An error ocurred saving the changes.

getAlias

public java.lang.String getAlias()
This method returns the table alias.
Specified by:
getAlias in interface Table
Returns:
java.lang.String

getChecks

public CheckConstraint[] getChecks()
Returns the list of check constraints for this table
Specified by:
getChecks in interface Table
Returns:
com.ibm.dse.tools.workbench.base.CheckConstraint[]

getChecks

public CheckConstraint[] getChecks(int column)
Returns the list of check constraints for a column of the table
Specified by:
getChecks in interface Table
Parameters:
column - int
Returns:
com.ibm.dse.tools.workbench.base.CheckConstraint[]

getColumnLengths

public int[] getColumnLengths()
Returns the list of column lengths.
Specified by:
getColumnLengths in interface Table
Returns:
int[]

getColumns

public java.lang.String[] getColumns()
Returns the list of column names for this table
Specified by:
getColumns in interface Table
Returns:
java.lang.String[]

getColumnsString

public java.lang.String getColumnsString(int[] columnsList,
                                         java.lang.String separator)
This method constructs a String with column names to use in clauses like select, order by, insert, ...
Specified by:
getColumnsString in interface Table
Parameters:
columnsList - int[] The list of column identifiers to concat
separator - java.lang.String The separator between column names
Returns:
java.lang.String

getColumnsString

public java.lang.String getColumnsString(java.lang.String separator)
This method constructs a String with all column names to use in clauses like select...
Specified by:
getColumnsString in interface Table
Parameters:
separator - java.lang.String The separator between column names
Returns:
java.lang.String

getConnection

public java.sql.Connection getConnection()
Returns the connection to the database for this table
Returns:
java.sql.Connection

getCreateChecksStrings

public java.lang.String[] getCreateChecksStrings()
This method returns the list of sentences to create the check constraints for the table.
Specified by:
getCreateChecksStrings in interface Table
Returns:
java.lang.String[]

getCreateFksStrings

public java.lang.String[] getCreateFksStrings()
This method returns the list of sentences to create the foreign keys for the table.
Specified by:
getCreateFksStrings in interface Table
Returns:
java.lang.String[]

getCreateIndexesStrings

public java.lang.String[] getCreateIndexesStrings()
This method returns the list of sentences to create the indexes for the table.
Specified by:
getCreateIndexesStrings in interface Table
Returns:
java.lang.String[]

getCreatePkString

public java.lang.String getCreatePkString()
This method returns the sentence to create the primary key for the table.
Specified by:
getCreatePkString in interface Table
Returns:
java.lang.String

getCreateTableString

public java.lang.String getCreateTableString()
This method returns the sentence to create the table.
Specified by:
getCreateTableString in interface Table
Returns:
java.lang.String

getDefaultVersion

public java.lang.String getDefaultVersion()
Returns a default version code
Returns:
java.lang.String

getFks

public java.util.Hashtable getFks()
Returns the list of foreign keys that this table has with other tables
Specified by:
getFks in interface Table
Returns:
java.util.Hashtable

getIndexes

public Index[] getIndexes()
Returns the list of indexes.
Specified by:
getIndexes in interface Table
Returns:
com.ibm.dse.tools.workbench.base.Index[]

getName

public java.lang.String getName()
Returns the name of the table
Specified by:
getName in interface Table
Returns:
java.lang.String

getPk

public int[] getPk()
Returns the list of column identifiers that are part of the primary key of this table
Specified by:
getPk in interface Table
Returns:
int[]

getPkValue

public java.lang.String getPkValue(TableRow row)
Returns the Values in the primary key of a row in a String with separators
Specified by:
getPkValue in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
Returns:
java.lang.String

getRelated

public TableRow[] getRelated(int relation,
                             java.lang.String[] values,
                             Clause where,
                             int[] orderBy)
                      throws WorkbenchException
Returns the rows of another table based on a relationship
Specified by:
getRelated in interface Table
Parameters:
relation - int The relationship identifier
values - java.lang.String[] The list of values to apply to the columns of the relationship
where - com.ibm.dse.tools.workbench.base.Clause The where clause to add to the conditions of relationship
orderBy - int[] The list of columns used to order the results
Returns:
com.ibm.dse.tools.workbench.base.TableRow[]
Throws:
WorkbenchException - An error ocurred doing the query.

getRelations

public Relationship[] getRelations()
Returns the list of relationships that this table has with other tables
Specified by:
getRelations in interface Table
Returns:
com.ibm.dse.tools.workbench.base.Relationship[]

getRepository

public Repository getRepository()
Returns repository in which this table is created
Specified by:
getRepository in interface Table
Returns:
com.ibm.dse.tools.workbench.base.Repository The repository of this table

getTimestamp

public java.lang.String getTimestamp()
Returns a timestamp value
Specified by:
getTimestamp in interface Table
Returns:
java.lang.String

getUniqueValue

public java.lang.String getUniqueValue()
Returns a unique value for generation of unique identifiers (primary keys) purpose
Specified by:
getUniqueValue in interface Table
Returns:
java.lang.String

hasSelfGeneratedPk

public abstract boolean hasSelfGeneratedPk()
This method indicates if the field in the primary key must be generated automatically
Specified by:
hasSelfGeneratedPk in interface Table
Returns:
boolean

importFromString

public void importFromString(java.lang.String s)
                      throws WorkbenchException
This method inserts data into the table from a String that can be read from a stream
Specified by:
importFromString in interface Table
Parameters:
s - java.lang.String
Throws:
WorkbenchException - an error ocurred while importing

isInPk

public boolean isInPk(int column)
Checks if a column is part of the primary key
Specified by:
isInPk in interface Table
Parameters:
column - int The column to check
Returns:
boolean

isRequired

public boolean isRequired(int column)
Checks if a column in the table is mandatory
Specified by:
isRequired in interface Table
Parameters:
column - int The identifier of the column to check
Returns:
boolean True if column is mandatory

postDelete

public void postDelete(TableRow row)
                throws RepositoryException
This method is called after a row is deleted
Specified by:
postDelete in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
Throws:
RepositoryException -  

postInsert

public void postInsert(TableRow row)
                throws RepositoryException
This method is called after a row is inserted
Specified by:
postInsert in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
Throws:
RepositoryException -  

postUpdate

public void postUpdate(TableRow row)
                throws RepositoryException
This method is called after a row is updated
Specified by:
postUpdate in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
Throws:
RepositoryException -  

preDelete

public void preDelete(TableRow row)
               throws RepositoryException
This method is called before deleting a row
Specified by:
preDelete in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
Throws:
RepositoryException -  

preInsert

public void preInsert(TableRow row)
               throws RepositoryException
This method is called before inserting a row
Specified by:
preInsert in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
Throws:
RepositoryException -  

preUpdate

public void preUpdate(TableRow row)
               throws RepositoryException
This method is called before modifying a row
Specified by:
preUpdate in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
Throws:
RepositoryException -  

registerDeletedRow

public void registerDeletedRow(TableRow row)
This method adds a row to the list of deleted rows
Specified by:
registerDeletedRow in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow

registerInsertedRow

public void registerInsertedRow(TableRow row)
This method adds a row to the list of inserted rows
Specified by:
registerInsertedRow in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow

registerModifiedRow

public void registerModifiedRow(TableRow row)
This method adds a row to the list of modified rows
Specified by:
registerModifiedRow in interface Table
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow

removeFromList

public void removeFromList(TableRow row)
This method removes a row from the list of rows

(does not deletes the row from the repository)

Specified by:
removeFromList in interface Table
Parameters:
com.ibm.dse.tools.workbench.base.TableRow - The row to be removed

restoreRows

public void restoreRows()
This method restores the mapped rows when doing a rollback
Specified by:
restoreRows in interface Table

retrieveAll

public TableRow[] retrieveAll(Clause where,
                              int[] orderBy)
                       throws WorkbenchException
Returns all the rows that accomplish the conditions in the where Clause

The rows retrieved are added to the list, for cache purpose

Specified by:
retrieveAll in interface Table
Parameters:
where - com.ibm.dse.tools.workbench.base.Clause The where clause to accomplish
orderBy - int[] The list of column identifiers used to order the results
Returns:
com.ibm.dse.tools.workbench.base.TableRow[] The list of rows retrieved
Throws:
WorkbenchException - An error ocurred doing the query.

retrieveByPk

public TableRow retrieveByPk(java.lang.String[] values)
                      throws WorkbenchException
Returns the row corresponding to the values of the primary key

The row retrieved is added to the list, for cache purpose

Specified by:
retrieveByPk in interface Table
Parameters:
values - String[] The values of the primary key components
Returns:
com.ibm.dse.tools.workbench.base.TableRow The row retrieved
Throws:
WorkbenchException - An error ocurred doing the query.

retrieveDistinct

public java.lang.String[] retrieveDistinct(int column,
                                           Clause where)
                                    throws WorkbenchException
This method retrieves the distinct values in a column in the rows that accomplish the conditions in a where clause
Specified by:
retrieveDistinct in interface Table
Parameters:
column - int
where - com.ibm.dse.tools.workbench.base.Clause
Returns:
java.lang.String[]
Throws:
WorkbenchException -  

setAlias

protected void setAlias(java.lang.String newAlias)
This method sets the alias for the table
Parameters:
newAlias - java.lang.String

setRepository

public void setRepository(Repository repository)
Sets the repository where this table is located
Specified by:
setRepository in interface Table
Parameters:
repository - com.ibm.dse.tools.workbench.base.Repository The repository to set

setTriggersState

public void setTriggersState(boolean active)
This method sets the triggers state
Specified by:
setTriggersState in interface Table
Parameters:
active - boolean

validate

public abstract java.lang.String[] validate(TableRow row)
This abstract method must validate the correctness of a row based on the rules of each object

It returns the list of error strings or null if there are no errors

Specified by:
validate in interface Table
Parameters:
com.ibm.dse.tools.workbench.base.TableRow - the row to validate
Returns:
java.lang.String[]