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

java.lang.Object
  |
  +--com.ibm.dse.tools.workbench.base.AbstractTable
        |
        +--com.ibm.dse.tools.workbench.base.VersionableTable
Direct Known Subclasses:
EntitiesTable, GroupsTable, InstancesTable

public abstract class VersionableTable
extends AbstractTable
implements Versionable

This class represents a versionable database table.

A versionable database table supports version, create open edition and import to workspace processes to be performed on its rows.


Fields inherited from class com.ibm.dse.tools.workbench.base.AbstractTable
alias, checks, columnLengths, columns, DATA_DELIMITER, DATA_SEPARATOR, deletedRows, ESCAPE_SEQUENCE, fks, indexes, insertedRows, modifiedRows, name, pk, relations, repository, required, rows, triggers
 
Constructor Summary
VersionableTable()
          This constructor creates a VersionableTable object
VersionableTable(Repository repository)
          This constructor creates an VersionableTable object in a repository.
 
Method Summary
protected  void alterFkFields(TableRow origParentRow, TableRow finalParentRow, int relation)
          Changes the related rows pointing to a parent row to point to a new parent row.
protected  void alterRelatedRows(TableRow origParentRow, TableRow finalParentRow, int relation)
          Changes the related rows pointing to a parent row to point to a new parent row.
 void copyOwner(TableRow row, Repository rep)
          Copies the owner of a row to a repository
abstract  void copyParentGroupsTree(TableRow tableRow, Repository destinationRep, boolean exactGroup)
          Copies the container groups tree of a row to another repository.
protected  void copyParentGroupsTree(TableRow tableRow, Repository destinationRep, int relation, int column, boolean exactGroup)
          Copies the container groups tree of a row to another repository.
abstract  TableRow createOpenEdition(TableRow row)
          Creates an open edition for a table row.
abstract  int getActiveColumn()
          This method returns the column identifier for the Active field of the versionable object
abstract  TableRow getContainerGroup(TableRow versionableRow)
          This method returns the group containing the row.
protected  TableRow getContainerGroup(TableRow versionableRow, int relation, int fkColumn)
          Returns the group containing the row.
protected  TableRow getContainerGroup(TableRow versionableRow, int relation, int fkColumn, Repository destinationRep)
          This method returns the group containing the row.
 java.lang.String[] getDistinctNames(Clause where)
          This method returns the distinct names of the rows in the Versionable object.
abstract  int getNameColumn()
          This method returns the column identifier for the Name of the versionable object
abstract  int getOwnerColumn()
          This method returns the column identifier for the Owner of the versionable object
abstract  int getReleasedColumn()
          This method returns the column identifier for the Released field of the versionable object
abstract  int getTimeStampColumn()
          This method returns the column identifier for the Timestamp of the versionable object
abstract  int getVersionColumn()
          This method returns the column identifier for the Version of the versionable object
abstract  int getVersionedColumn()
          This method returns the column identifier for the Versioned field of the versionable object
 TableRow[] getVersions(java.lang.String name)
          Returns all the stored versions of a row in a versionable table object.
protected  TableRow getWorkspaceContainerGroup(TableRow row, Workspace ws)
          This method returns the group containing the workspace copy of a row.
 void importToWorkspace(Workspace ws, TableRow row)
          Copies a row of this VersionableTable from a repository to a workspace.
 boolean isAValidVersionNumber(TableRow versionableRow, java.lang.String versionNumber, Repository rep)
          Checks if a version number is valid for a row stored in this versionable object.
 boolean isVersioned(TableRow row)
          Tests if a row in this versionable object is versioned.
 TableRow[] rowsToBeRemoved(TableRow[] rows)
          Returns the rows that a remove process performed on a set of rows will remove.
protected  void rowsToBeRemoved(TableRow row, java.util.Hashtable rowList)
          Adds to a Hashtable the related rows that a remove process performed on a row will remove.
protected  void setContainerGroup(TableRow versionableRow, int relation, int grpColumn, java.lang.String grpCode)
          Sets the container group of a row of this versionable object.
abstract  void setContainerGroup(TableRow versionableRow, java.lang.String grpCode)
          Sets the container group of a row of this versionable object.
 void updateOpenEditionFields(TableRow versionableRow, java.lang.String[] newPk)
          This method updates the row fields relative to the version process.
 void updateVersionFields(TableRow versionableRow, java.lang.String[] newPk, java.lang.String newVersion)
          This method updates the row fields relative to the version process..
abstract  TableRow version(TableRow versionableRow, java.lang.String newVersion, Repository repository)
          Versions a row in this versionable object.
 
Methods inherited from class com.ibm.dse.tools.workbench.base.AbstractTable
add, areTriggersActive, cleanRollbackData, count, createRelations, createTableRow, createTableRow, exportToFile, flush, getAlias, getChecks, getChecks, getColumnLengths, getColumns, getColumnsString, getColumnsString, getConnection, getCreateChecksStrings, getCreateFksStrings, getCreateIndexesStrings, getCreatePkString, getCreateTableString, getDefaultVersion, getFks, getIndexes, getName, getPk, getPkValue, getRelated, getRelations, getRepository, getTimestamp, getUniqueValue, hasSelfGeneratedPk, importFromString, isInPk, isRequired, postDelete, postInsert, postUpdate, preDelete, preInsert, preUpdate, registerDeletedRow, registerInsertedRow, registerModifiedRow, removeFromList, restoreRows, retrieveAll, retrieveByPk, retrieveDistinct, setAlias, setRepository, setTriggersState, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VersionableTable

public VersionableTable()
This constructor creates a VersionableTable object

VersionableTable

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

alterFkFields

protected void alterFkFields(TableRow origParentRow,
                             TableRow finalParentRow,
                             int relation)
                      throws WorkbenchException
Changes the related rows pointing to a parent row to point to a new parent row.

This method sets the values at the columns associated with the foreign key so that the parent row would change from origParentRow to finalParentRow.

Parameters:
origParentRow - com.ibm.dse.tools.workbench.base.TableRow the initial parent row where the fk points to.
finalParentRow - com.ibm.dse.tools.workbench.base.TableRow the new parent row where the fk would point to.
relation - int the relation between the row and its parent, associated to the foreign key to be altered.
Throws:
WorkbenchException - An error ocurred while altering the foreign key.

alterRelatedRows

protected void alterRelatedRows(TableRow origParentRow,
                                TableRow finalParentRow,
                                int relation)
                         throws WorkbenchException
Changes the related rows pointing to a parent row to point to a new parent row.

In addition of altering the fk fields in the related rows so that they change their parent, it also changes the value at their Code column, if applies (that is if they have selfgenerated primary key).

Parameters:
origParentRow - com.ibm.dse.tools.workbench.base.TableRow the initial parent row
finalParentRow - com.ibm.dse.tools.workbench.base.TableRow the new parent row.
relation - int the relation between the related rows and its parent
Throws:
WorkbenchException - An error ocurred while altering the related rows.

copyOwner

public void copyOwner(TableRow row,
                      Repository rep)
               throws WorkbenchException
Copies the owner of a row to a repository
Specified by:
copyOwner in interface Versionable
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
rep - com.ibm.dse.tools.workbench.base.Repository
Throws:
WorkbenchException - An error occurred while copying the owner.

copyParentGroupsTree

protected void copyParentGroupsTree(TableRow tableRow,
                                    Repository destinationRep,
                                    int relation,
                                    int column,
                                    boolean exactGroup)
                             throws WorkbenchException
Copies the container groups tree of a row to another repository.

This method recursively searches for container groups in the origin repository and copies them to the destination repository.

The method behavior depends on the exactGroup parameter and whether the original container group is versioned or not:

If exactGroup = true and the original container group is versioned, the same version of the container group would be searched for in the destination repository to be set as the container group. If it doesn´t exist the original container group would be copied to the destination repository.

If exactGroup = true and the original container group isn't versioned, an open edition of the container group would be searched for in the destination repository to be set as the container group. If it doesn´t exist the original container group would be copied to the destination repository.

If exactGroup = false, any edition of the original container group in the repository would be set as the container group

Parameters:
tableRow - com.ibm.dse.tools.workbench.base.TableRow the row
destinationRep - com.ibm.dse.tools.workbench.base.Repository the destination repository
relation - int the relation between the VersionableTable object and the Table cointaining the relational rows representing the relation between the GroupsTable and this VersionableTable (tipically a groups_xxx table)
column - int the column where the Group Code is stored.
exactGroup - boolean indicates whether it must search for exact matching groups in the destination repository.
Throws:
WorkbenchException - an error ocurred while copying the parent groups tree.

copyParentGroupsTree

public abstract void copyParentGroupsTree(TableRow tableRow,
                                          Repository destinationRep,
                                          boolean exactGroup)
                                   throws WorkbenchException
Copies the container groups tree of a row to another repository.
Specified by:
copyParentGroupsTree in interface Versionable
Parameters:
tableRow - com.ibm.dse.tools.workbench.base.TableRow the row whose parent groups tree would be copied.
destinationRep - com.ibm.dse.tools.workbench.base.Repository the destination repository.
exactGroup - boolean indicates whether it must search for exact matching groups in the destination repository.
Throws:
WorkbenchException - an error ocurred while copying the parent groups tree.

createOpenEdition

public abstract TableRow createOpenEdition(TableRow row)
                                    throws WorkbenchException
Creates an open edition for a table row.

An open edition is an edition ready to be worked on it.

Specified by:
createOpenEdition in interface Versionable
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
Returns:
com.ibm.dse.tools.workbench.base.TableRow The open edition of the row
Throws:
WorkbenchException - An error ocurred while creating the open edition.

getActiveColumn

public abstract int getActiveColumn()
This method returns the column identifier for the Active field of the versionable object
Specified by:
getActiveColumn in interface Versionable
Returns:
int The Active field identifier

getContainerGroup

public abstract TableRow getContainerGroup(TableRow versionableRow)
                                    throws WorkbenchException
This method returns the group containing the row.
Specified by:
getContainerGroup in interface Versionable
Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow The row whose container group must be returned
Returns:
com.ibm.dse.tools.workbench.base.TableRow The group containing the row
Throws:
WorkbenchException - An error ocurred while retrieving the conatiner group

getContainerGroup

protected TableRow getContainerGroup(TableRow versionableRow,
                                     int relation,
                                     int fkColumn)
                              throws WorkbenchException
Returns the group containing the row.

If a row is owned by more than one group it returns the active one having the latest timestamp.

Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow the row whose group must be returned
relation - int the relation between the VersionableTable object and the Table containing the rows associating VersionableTable rows and GroupsTable rows.
fkColumn - int the column in the Table containing the rows associating VersionableTable rows and GroupsTable rows where the Group Code is stored.
Returns:
com.ibm.dse.tools.workbench.base.TableRow the group containing the row.

If no parent group is found it returns null.

Throws:
WorkbenchException - An error ocurred while retrieving the container group.

getContainerGroup

protected TableRow getContainerGroup(TableRow versionableRow,
                                     int relation,
                                     int fkColumn,
                                     Repository destinationRep)
                              throws WorkbenchException
This method returns the group containing the row. If there are multiple groups containing a group it returns the matching group in its repository and the repository passed as parameter.
Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow the row whose group must be returned
relation - int the relation between the VersionableTable object and the Table containing the rows associating VersionableTable rows and GroupsTable rows.
fkColumn - int the column in the Table containing the rows associating VersionableTable rows and GroupsTable rows where the Group Code is stored.
Returns:
com.ibm.dse.tools.workbench.base.TableRow the group containing the row.

If no parent group is found it returns null.

Throws:
WorkbenchException - An error ocurred while retrieving the container group.

getDistinctNames

public java.lang.String[] getDistinctNames(Clause where)
                                    throws WorkbenchException
This method returns the distinct names of the rows in the Versionable object.
Specified by:
getDistinctNames in interface Versionable
Parameters:
where - com.ibm.dse.tools.workbench.base.Clause A clause to filter the names retrieved.
Returns:
java.lang.String[] The distinct names of the rows.
Throws:
WorkbenchException - An error ocurred while retrieving the distinct names.

getNameColumn

public abstract int getNameColumn()
This method returns the column identifier for the Name of the versionable object
Specified by:
getNameColumn in interface Versionable
Returns:
int The Name column identifier

getOwnerColumn

public abstract int getOwnerColumn()
This method returns the column identifier for the Owner of the versionable object
Specified by:
getOwnerColumn in interface Versionable
Returns:
int The Owner column identifier

getReleasedColumn

public abstract int getReleasedColumn()
This method returns the column identifier for the Released field of the versionable object
Specified by:
getReleasedColumn in interface Versionable
Returns:
int The Released column identifier

getTimeStampColumn

public abstract int getTimeStampColumn()
This method returns the column identifier for the Timestamp of the versionable object
Specified by:
getTimeStampColumn in interface Versionable
Returns:
int The Timestamp column identifier

getVersionColumn

public abstract int getVersionColumn()
This method returns the column identifier for the Version of the versionable object
Specified by:
getVersionColumn in interface Versionable
Returns:
int The Version column identifier

getVersionedColumn

public abstract int getVersionedColumn()
This method returns the column identifier for the Versioned field of the versionable object
Specified by:
getVersionedColumn in interface Versionable
Returns:
int The Versioned column identifier

getVersions

public TableRow[] getVersions(java.lang.String name)
                       throws WorkbenchException
Returns all the stored versions of a row in a versionable table object.

The search is performed by name.

The returned rows are ordered by timestamp.

Specified by:
getVersions in interface Versionable
Parameters:
name - java.lang.String The name of the row.
Returns:
com.ibm.dse.tools.workbench.base.TableRow[] The stored versions.
Throws:
WorkbenchException - An error ocurred while retrieving the versions.

getWorkspaceContainerGroup

protected TableRow getWorkspaceContainerGroup(TableRow row,
                                              Workspace ws)
                                       throws WorkbenchException
This method returns the group containing the workspace copy of a row.
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
ws - com.ibm.dse.tools.workbench.base.Workspace
Returns:
com.ibm.dse.tools.workbench.base.TableRow
Throws:
WorkbenchException -  

importToWorkspace

public void importToWorkspace(Workspace ws,
                              TableRow row)
                       throws WorkbenchException
Copies a row of this VersionableTable from a repository to a workspace.

Rows in VersionableTable objects contained in a Workspace object can not be imported to a Workspace.

This method also copies the parent groups tree if needed.

Specified by:
importToWorkspace in interface Versionable
Parameters:
ws - com.ibm.dse.tools.workbench.base.Workspace The destination repository.
row - com.ibm.dse.tools.workbench.base.TableRow The row to be copied.
Throws:
WorkbenchException - An error ocurred while importing to workspace.

isAValidVersionNumber

public boolean isAValidVersionNumber(TableRow versionableRow,
                                     java.lang.String versionNumber,
                                     Repository rep)
                              throws WorkbenchException
Checks if a version number is valid for a row stored in this versionable object.

This method would be tipically used to ensure that only a version number exists in a repository for a named row.

Specified by:
isAValidVersionNumber in interface Versionable
Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow the row.
versionNumber - java.lang.String the version number.
rep - com.ibm.dse.tools.workbench.base.Repository the repository.
Returns:
boolean true if the version number is valid for the row in the repository passed as parameters, false otherwise.
Throws:
WorkbenchException - an error ocurred while checking the version number.

isVersioned

public boolean isVersioned(TableRow row)
Tests if a row in this versionable object is versioned.

A row marked as deleted is considered to be non versioned.

Specified by:
isVersioned in interface Versionable
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow the row.
Returns:
boolean true if the row is versioned; false otherwhise.

rowsToBeRemoved

public TableRow[] rowsToBeRemoved(TableRow[] rows)
                           throws WorkbenchException
Returns the rows that a remove process performed on a set of rows will remove.
Specified by:
rowsToBeRemoved in interface Versionable
Parameters:
rows - com.ibm.dse.tools.workbench.base.TableRow[] the rows
Returns:
com.ibm.dse.tools.workbench.base.TableRow[] the rows that would de removed
Throws:
WorkbenchException - An error ocurred while retrieving the rows to be removed.

rowsToBeRemoved

protected void rowsToBeRemoved(TableRow row,
                               java.util.Hashtable rowList)
                        throws WorkbenchException
Adds to a Hashtable the related rows that a remove process performed on a row will remove.
Parameters:
row - com.ibm.dse.tools.workbench.base.TableRow
rowList - java.util.Hashtable
Throws:
WorkbenchException - An error ocurred while retrieving the rows to be removed.

setContainerGroup

protected void setContainerGroup(TableRow versionableRow,
                                 int relation,
                                 int grpColumn,
                                 java.lang.String grpCode)
                          throws WorkbenchException
Sets the container group of a row of this versionable object.

This method creates the row in the table relating this VersionableTable row and the Group having grpCode Code.

Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow the row
relation - int the relation between the VersionableTable object and the Table containing the rows associating VersionableTable rows and GroupsTable rows.
grpColumn - int the column in the Table containing the rows associating VersionableTable rows and GroupsTable rows where the Group Code is stored.
grpCode - java.lang.String the group code
Throws:
WorkbenchException - An error ocurred while setting the container group.

setContainerGroup

public abstract void setContainerGroup(TableRow versionableRow,
                                       java.lang.String grpCode)
                                throws WorkbenchException
Sets the container group of a row of this versionable object.
Specified by:
setContainerGroup in interface Versionable
Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow the row
grpCode - java.lang.String the group code
Throws:
WorkbenchException - An error ocurred while setting the container group.

updateOpenEditionFields

public void updateOpenEditionFields(TableRow versionableRow,
                                    java.lang.String[] newPk)
                             throws RepositoryException
This method updates the row fields relative to the version process.

The fields updated are:
the primary key fields are set to be the one passed as a parameter
the Version field is set to be the current date and time
the Versioned field is set to "N"
the Timestamp field is set to be the current date and time

Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow the row
newPk - java.lang.String[] the new primary key
Throws:
RepositoryException - an error ocurred while updating the version fields.

updateVersionFields

public void updateVersionFields(TableRow versionableRow,
                                java.lang.String[] newPk,
                                java.lang.String newVersion)
                         throws RepositoryException
This method updates the row fields relative to the version process..

The fields updated are:
the primary key fields are set to be the one passed as a parameter
the Version field is set to be the version code passed as a parameter
the Versioned field is set to "Y"
the Timestamp field is set to be the current date and time
the Active field is set to be "Y"
the user is set as the owner

Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow the row
newPk - java.lang.String[] the new primary key
newVersion - java.lang.String the new version code
Throws:
RepositoryException - an error ocurred while updating the version fields.

version

public abstract TableRow version(TableRow versionableRow,
                                 java.lang.String newVersion,
                                 Repository repository)
                          throws WorkbenchException
Versions a row in this versionable object.
Specified by:
version in interface Versionable
Parameters:
versionableRow - com.ibm.dse.tools.workbench.base.TableRow the row to be versioned.
newVersion - java.lang.String the version code
repository - com.ibm.dse.tools.workbench.base.Repository the repository where the versioned row should be copied.
Returns:
com.ibm.dse.tools.workbench.base.TableRow the versioned row.
Throws:
WorkbenchException - An error ocurred while versioning the row.