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

java.lang.Object
  |
  +--com.ibm.dse.tools.workbench.base.DefaultRepository
Direct Known Subclasses:
Workspace

public class DefaultRepository
extends java.lang.Object
implements Repository

This class represents a basic shared repository. It has a constructor for connecting to the data source (usually, database) using a repository name, user name and user password


Field Summary
protected  java.lang.Class classDriver
          A JDBC driver
protected  java.lang.String cnnPwd
          The password used for establishing JDBC connection
protected  java.lang.String cnnUser
          The user name used for establishing JDBC connection
protected  java.sql.Connection connection
          The JDBC connection
protected  java.lang.String DEFAULT_DRIVER
          The default JDBC driver
protected  boolean modified
          Switch indicating if modifications have been done since last commit or rollback
protected  java.lang.String password
          The application password used for validate in UsersTable
protected  java.util.Hashtable tables
          The list of tables managed by this repository
protected  java.lang.String URLpath
          The URL used for establishing JDBC connection
protected  TableRow user
          The row in UsersTable that represents the user
protected  java.lang.String userName
          The application user name used for validate in UsersTable
 
Fields inherited from interface com.ibm.dse.tools.workbench.base.Repository
BEGIN_TABLE_TOKEN, END_TABLE_TOKEN, EOL
 
Constructor Summary
protected DefaultRepository()
          This method constructs a DefaultRepository object
  DefaultRepository(java.lang.String URLpath, java.lang.String user, java.lang.String password)
          This constructor creates a DefaultRepository object, with a given url, user and password.
 
Method Summary
protected  void add(AbstractTable table)
          This method adds an AbstractTable to the internal list of tables, with it's name as key.
 void commit()
          This method commits the changes to the database and cleans the data maintained to allow rollback
 void connect()
          Establish the connection to database and check the application user identification
 java.lang.String[] create(java.io.Reader initialDataSetReader)
          Creates a repository from an initial data file
 java.lang.String[] create(java.lang.String InitialDataSetFileName)
          Creates a repository from an initial data file
protected  void createTables()
          This method creates all the defined tables.
 void disconnect()
          This method disconnects from the database.
protected  void establishSession()
          This method creates a connection to the database.
 void exportToFile(java.io.Writer w)
          Export all the table data to file
protected  boolean findUser()
          Searches the repository user in the users table to check its identification
 java.lang.String getCnnPassword()
          This method returns the passsword used for JDBC connection to the repository
 java.lang.String getCnnUser()
          Returns the user name used for JDBC connection
 java.sql.Connection getConnection()
          Returns the instance of the JDBC connection
 Table getTable(java.lang.String name)
          Returns the table that has the specified name.
 Table[] getTableList()
          Returns the list of tables defined in the repository.
 java.lang.String getURLpath()
          Returns the url to connect to the repository.
 TableRow getUser()
          Returns the row in the Users table representing the application user
 java.lang.String getUserCode()
          Returns the value of the application user code.
 java.lang.String getUserName()
          Returns the value of the application user name.
 void importFromFile(java.io.Reader r)
          Imports all the tables data from a file
 boolean isModified()
          Indicates if modifications have been done since last commit or rollback
 void markAsModified()
          Marks the repository as modified, so commit or rollback is required
 void rollback()
          This method undoes the changes made to the rows since the last commit or rollback
 void setClassDriver(java.lang.String className)
          This method changes the default class driver for the data base connection.
 void setConnectData(java.lang.String URLpath, java.lang.String user, java.lang.String password)
          This method sets the connection data for a DefaultRepository object, with a given url, user and password.
 void setUser(java.lang.String userName, java.lang.String password)
          Sets the application user name and password, to be searched at the Users table at connection time
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cnnUser

protected java.lang.String cnnUser
The user name used for establishing JDBC connection

cnnPwd

protected java.lang.String cnnPwd
The password used for establishing JDBC connection

URLpath

protected java.lang.String URLpath
The URL used for establishing JDBC connection

tables

protected java.util.Hashtable tables
The list of tables managed by this repository

connection

protected java.sql.Connection connection
The JDBC connection

user

protected TableRow user
The row in UsersTable that represents the user

classDriver

protected java.lang.Class classDriver
A JDBC driver

DEFAULT_DRIVER

protected java.lang.String DEFAULT_DRIVER
The default JDBC driver

userName

protected java.lang.String userName
The application user name used for validate in UsersTable

password

protected java.lang.String password
The application password used for validate in UsersTable

modified

protected boolean modified
Switch indicating if modifications have been done since last commit or rollback
Constructor Detail

DefaultRepository

protected DefaultRepository()
                     throws WorkbenchException
This method constructs a DefaultRepository object
Throws:
WorkbenchException - When an exception is throw creating the object.

DefaultRepository

public DefaultRepository(java.lang.String URLpath,
                         java.lang.String user,
                         java.lang.String password)
                  throws WorkbenchException
This constructor creates a DefaultRepository object, with a given url, user and password.
Parameters:
URLpath - java.lang.String
user - java.lang.String
password - java.lang.String
Throws:
WorkbenchException - When an exception is throw creating the object.
Method Detail

add

protected void add(AbstractTable table)
This method adds an AbstractTable to the internal list of tables, with it's name as key.
Parameters:
table - com.ibm.dse.tools.workbench.base.AbstracTable

commit

public void commit()
            throws RepositoryException
This method commits the changes to the database and cleans the data maintained to allow rollback
Specified by:
commit in interface Repository
Throws:
RepositoryException - When changes can not be commited to the database

connect

public void connect()
             throws RpConnectionException
Establish the connection to database and check the application user identification
Specified by:
connect in interface Repository
Throws:
RpConnectionException - When the connection can't be established.

create

public java.lang.String[] create(java.io.Reader initialDataSetReader)
                          throws WorkbenchException
Creates a repository from an initial data file
Parameters:
initialDataSetReader - java.io.Reader The reader with the initial data (null if no initial data)
Returns:
java.lang.String[] The list of error messages
Throws:
WorkbenchException -  

create

public java.lang.String[] create(java.lang.String InitialDataSetFileName)
                          throws WorkbenchException
Creates a repository from an initial data file
Specified by:
create in interface Repository
Parameters:
InitialDataSetFileName - java.lang.String The name of the file with the initial data (null if no initial data)
Returns:
java.lang.String[] The list of error messages
Throws:
WorkbenchException -  

createTables

protected void createTables()
                     throws WorkbenchException
This method creates all the defined tables.

For future extensions, remember create here the new tables.

Throws:
WorkbenchException - The exception description.

disconnect

public void disconnect()
                throws RpConnectionException
This method disconnects from the database.
Specified by:
disconnect in interface Repository
Throws:
RpConnectionException - When the connection can't be disconnected.

establishSession

protected void establishSession()
                         throws RpConnectionException
This method creates a connection to the database.

If the driver isn't loaded, then load it.

Throws:
RpConnectionException - When the connection can't be established.

exportToFile

public void exportToFile(java.io.Writer w)
                  throws WorkbenchException,
                         java.io.IOException
Export all the table data to file
Specified by:
exportToFile in interface Repository
Parameters:
w - java.io.Writer
Throws:
WorkbenchException - An exception occurred accessing data
java.io.IOException - An exception occurred accessing file

findUser

protected boolean findUser()
                    throws WorkbenchException
Searches the repository user in the users table to check its identification
Returns:
boolean
Throws:
WorkbenchException -  

getCnnPassword

public java.lang.String getCnnPassword()
This method returns the passsword used for JDBC connection to the repository
Specified by:
getCnnPassword in interface Repository
Returns:
java.lang.String

getCnnUser

public java.lang.String getCnnUser()
Returns the user name used for JDBC connection
Specified by:
getCnnUser in interface Repository
Returns:
java.lang.String - The current value of cnnUser.

getConnection

public java.sql.Connection getConnection()
Returns the instance of the JDBC connection
Specified by:
getConnection in interface Repository
Returns:
java.sql.Connection - The current value of connection.

getTable

public Table getTable(java.lang.String name)
Returns the table that has the specified name.
Specified by:
getTable in interface Repository
Returns:
com.ibm.dse.tools.workbench.base.Table

getTableList

public Table[] getTableList()
Returns the list of tables defined in the repository.
Specified by:
getTableList in interface Repository
Returns:
com.ibm.dse.tools.workbench.base.Table[].

getURLpath

public java.lang.String getURLpath()
Returns the url to connect to the repository.
Specified by:
getURLpath in interface Repository
Returns:
java.lang.String

getUser

public TableRow getUser()
Returns the row in the Users table representing the application user
Specified by:
getUser in interface Repository
Returns:
com.ibm.dse.tools.workbench.base.TableRow - The current value of user.

getUserCode

public java.lang.String getUserCode()
Returns the value of the application user code.
Specified by:
getUserCode in interface Repository
Returns:
java.lang.String - The current value of user code.

getUserName

public java.lang.String getUserName()
Returns the value of the application user name.
Specified by:
getUserName in interface Repository
Returns:
java.lang.String - The current value of user name.

importFromFile

public void importFromFile(java.io.Reader r)
                    throws WorkbenchException,
                           java.io.IOException
Imports all the tables data from a file
Specified by:
importFromFile in interface Repository
Parameters:
r - java.io.Reader
Throws:
WorkbenchException - An exception occurred accessing tables
java.io.IOException - An exception occurred accessing file

isModified

public boolean isModified()
Indicates if modifications have been done since last commit or rollback
Specified by:
isModified in interface Repository
Returns:
boolean

markAsModified

public void markAsModified()
Marks the repository as modified, so commit or rollback is required
Specified by:
markAsModified in interface Repository

rollback

public void rollback()
              throws RepositoryException
This method undoes the changes made to the rows since the last commit or rollback
Specified by:
rollback in interface Repository
Throws:
RepositoryException -  

setClassDriver

public void setClassDriver(java.lang.String className)
                    throws java.lang.ClassNotFoundException
This method changes the default class driver for the data base connection.
Parameters:
className - java.lang.String
Throws:
java.lang.ClassNotFoundException - When an exception is thrown loading the driver.

setConnectData

public void setConnectData(java.lang.String URLpath,
                           java.lang.String user,
                           java.lang.String password)
This method sets the connection data for a DefaultRepository object, with a given url, user and password.
Specified by:
setConnectData in interface Repository
Parameters:
URLpath - java.lang.String
user - java.lang.String
password - java.lang.String

setUser

public void setUser(java.lang.String userName,
                    java.lang.String password)
Sets the application user name and password, to be searched at the Users table at connection time
Specified by:
setUser in interface Repository
Parameters:
userName - java.lang.String
password - java.lang.String