tppt.db
Class DBHandler

java.lang.Object
  |
  +--tppt.db.DBHandler
Direct Known Subclasses:
DB2Handler, SybaseHandler

public abstract class DBHandler
extends java.lang.Object

This class is the abstract class that defined the required methods for the any DBMS that tool would like to run on. The methods with implementation are those methods have same behaviors (or said independent) between different DBMS. The abstract methods are those methods that are dependent on the DBMS - different DBMS needs different implementation. Therefore, if you would like to extend the tool to support any other DBMS besides DB2 and Sybase then you have to create the own DB handler for that new DBMS and new DB handler have to extend this class and implement the required abstract methods.

Version:
2.0
Author:
Jodie Wu

Field Summary
protected  java.sql.Connection connection
          DB Connection
 
Constructor Summary
DBHandler()
           
 
Method Summary
 void closeConnection()
           
private  void closeReader(java.io.Reader reader)
          Close the file reader.
 boolean dbConnection(java.lang.String id, java.lang.String passd, java.lang.String u, java.lang.String d, java.lang.String p)
          Create the connection to the database.
 boolean dropATable(java.lang.String tableName)
          Drop a table with name tableName.
 boolean dropConstraint(java.lang.String cname, java.lang.String tname)
          Drop the specific constraint for specific table.
 boolean dropSP(java.lang.String spName)
          Drop a specific store procedure with name spName.
abstract  void dropStoredProcedures()
          The method to obtain all the existing stored procedures and then call dropSP method to drop those stored procedure before the experiment starts.
abstract  void dropTables()
          The method to obtain all the existing tables and constraints and then call dropConstraint and dropATable methods to drop all the constraints and tables before the experiment starts.
 boolean executeStmt(java.lang.String s)
          Execute the SQL command.
 boolean initDB()
          This method executes the initial tasks before the experiment starts.
 boolean initStatement(java.lang.String fileName, int mode)
          Read the sql commands from the filename and execute those commands.
static void main(java.lang.String[] args)
           
abstract  boolean setMaxRowsForTable(java.sql.CallableStatement sp, java.lang.String table)
          This method used to set up the maximun rows for a table.
abstract  boolean setMaxRowsPerPage()
          Set up the maximum row per page for all the user created tables. table.
 boolean SQLFileExecutor(java.lang.String file, java.lang.String db)
          New version of initial procedure for "sync.xml".
 boolean twoPhaseDBInit(java.lang.String file)
          This method is used to parse the XML format DB initialization file for two-phase commit experiment.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

connection

protected java.sql.Connection connection
DB Connection
Constructor Detail

DBHandler

public DBHandler()
Method Detail

dropStoredProcedures

public abstract void dropStoredProcedures()
The method to obtain all the existing stored procedures and then call dropSP method to drop those stored procedure before the experiment starts. This method is DBMS dependent. Different DBMS needs to query its own system table and the system table usually has different name and DB schema. You will need to check your DBMS documentation before you implement it.
See Also:
dropSP(java.lang.String)

dropTables

public abstract void dropTables()
The method to obtain all the existing tables and constraints and then call dropConstraint and dropATable methods to drop all the constraints and tables before the experiment starts. This method is DBMS dependent. Different DBMS needs to query its own system table and the system table usually has different name and DB schema. You will need to check your DBMS documentation before you implement it.
See Also:
dropATable(java.lang.String), dropConstraint(java.lang.String, java.lang.String)

setMaxRowsForTable

public abstract boolean setMaxRowsForTable(java.sql.CallableStatement sp,
                                           java.lang.String table)
This method used to set up the maximun rows for a table. This method is DBMS dependent. Check your DBMS whether it does support this function and how to set it up before you implement it
Parameters:
sp - the CallableStatement to execute the maximun-rows setup.
table - the table name.
Returns:
returns true if setup sucessfully, false otherwise.

setMaxRowsPerPage

public abstract boolean setMaxRowsPerPage()
Set up the maximum row per page for all the user created tables. table. This method is DBMS dependent. Check your DBMS whether it does support this function and how to set it up before you implement it.
Returns:
returns true if no error occurs during setting up, false otherwise.
See Also:
setMaxRowsForTable(CallableStatement,String)

dbConnection

public boolean dbConnection(java.lang.String id,
                            java.lang.String passd,
                            java.lang.String u,
                            java.lang.String d,
                            java.lang.String p)
Create the connection to the database. This method is DBMS independent. For Sybase, this method will try to "use" database. For both Sybase and DB2. it expects that the database name is the same with user id.
Returns:
return true if connection creates sucessfully, false otherwise.

dropConstraint

public boolean dropConstraint(java.lang.String cname,
                              java.lang.String tname)
Drop the specific constraint for specific table.
Parameters:
cname - the name of constraint.
tname - the name of table.
Returns:
returns true if the constrant drops sucessfully, false otherwise.

dropSP

public boolean dropSP(java.lang.String spName)
Drop a specific store procedure with name spName.
Parameters:
spName - the name of store procedure.
Returns:
return true if the store procedure is dropped sucessfully, false otherwise.

dropATable

public boolean dropATable(java.lang.String tableName)
Drop a table with name tableName.
Returns:
true if the table is dropped, false otherwise.

closeConnection

public void closeConnection()

closeReader

private void closeReader(java.io.Reader reader)
Close the file reader.
Parameters:
reader -  

executeStmt

public boolean executeStmt(java.lang.String s)
Execute the SQL command.
Parameters:
the - string of SQL command.

initDB

public boolean initDB()
This method executes the initial tasks before the experiment starts. The tasks include create the databse connection, drop all the user tables constriants and store procedures. Then executes the SQL commands from the Database Schema File and Database State Initialization file and sets up the Maximun Row per Page for all the tables.
Returns:
returns true if all the initial jobs execute sucessfully, false otherwise.
See Also:
dbConnection(String,String,String,String,String), dropTables(), dropStoredProcedures(), initStatement(String,int), closeConnection(), setMaxRowsPerPage(), GlobalData.dbSchemaFile, GlobalData.dbInitFile

initStatement

public boolean initStatement(java.lang.String fileName,
                             int mode)
Read the sql commands from the filename and execute those commands.
Parameters:
SQL - script file
mode:1 - from Jar ,2 from file system.
Returns:
true if executing sucessfully, false otherwise.

SQLFileExecutor

public boolean SQLFileExecutor(java.lang.String file,
                               java.lang.String db)
New version of initial procedure for "sync.xml". This file is defined the stored procedure procedure to control the access for Single user mode. SQLFileExecutor is used to parsed the "sync.xml" and create the stored procedures defined in that file for each available DBMS.
Parameters:
xml - file
the - name of DBMS - DB2 or Sybase
Returns:
true if execution sucessfully; false otherwise.

twoPhaseDBInit

public boolean twoPhaseDBInit(java.lang.String file)
This method is used to parse the XML format DB initialization file for two-phase commit experiment.
Parameters:
file - the db initialization file
Returns:
true if initialization executes sucessfully; false otherwise.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception