uk.org.ogsadai.client.dbcreate2
Class CreateTestDB

java.lang.Object
  |
  +--uk.org.ogsadai.client.dbcreate2.CreateTestDB
Direct Known Subclasses:
CreateTestDB2DB, CreateTestDerbyDB, CreateTestMySQLDB, CreateTestOracleDB, CreateTestPostgreSQLDB, CreateTestSQLServerDB

public abstract class CreateTestDB
extends java.lang.Object

Base class for creating and populating test database tables.

Author:
The OGSA-DAI Project Team

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
           
protected  java.lang.String mBookingTable
           
protected  TravelDataCreator mData
          Generates the test data.
protected  java.lang.String mDatabase
           
protected  java.lang.String mDBMS
           
protected  java.lang.String mDestinationTable
           
protected  java.lang.String mDriver
           
protected  java.lang.String mHost
           
protected  int mNumberOfBookings
           
protected  int mNumberOfDestinations
           
protected  int mNumberOfTravellers
           
protected  java.lang.String mPassword
           
protected  java.lang.String mPort
           
protected  int mRows
           
protected  int mSizeOfBlob
           
protected  java.lang.String mTablePrefix
           
protected  java.lang.String mTravellerTable
           
protected  java.lang.String mUsername
           
 
Constructor Summary
CreateTestDB(java.lang.String[] args)
          Parse the arguments and populates the test database.
 
Method Summary
protected  void createBookingTable(java.sql.Connection connection)
          Creates a new table with name mTablePrefix+mBookingTable and populates it with data generated by the TravelDataCreator.
protected  void createDestinationTable(java.sql.Connection connection)
          Creates a new table with name mTablePrefix+mDestinationTable and populates it with data generated by the TravelDataCreator.
protected  void createTravellerTable(java.sql.Connection connection)
          Creates a new table with name mTablePrefix+mTravellerTable and populates it with data generated by the TravelDataCreator.
protected abstract  void dropTableIfExists(java.sql.Connection connection, java.lang.String tablename)
          Drops the specified table.
protected abstract  java.sql.Connection getConnection()
          Returns a java.sql.Connection data resource.
protected  java.lang.String getCreateBookingTableStatement()
          Constructs the statement for creating the traveller table.
protected  java.lang.String getCreateDestinationTableStatement()
          Constructs the statement for creating a destination table.
protected  java.lang.String getCreateTravellerTableStatement()
          Constructs the statement for creating the traveller table.
protected  void loadDriver()
          Loads the driver class specified by the mDriver instance variable.
protected  void populateDatabase()
          Populates the test database with the test data.
protected  void printUsage()
          Prints the general usage instructions for a CreateTestDB client.
protected  void printVariables(java.lang.String prefix)
          Displays the settings prefixed by the specified string.
protected abstract  void setDefaultSettings()
          Sets the default settings for the client.
protected  boolean setupArguments(java.lang.String[] args)
          Parses the arguments general to most CreateTestDB clients.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
See Also:
Constant Field Values

mData

protected final TravelDataCreator mData
Generates the test data.


mDBMS

protected java.lang.String mDBMS

mDriver

protected java.lang.String mDriver

mHost

protected java.lang.String mHost

mPort

protected java.lang.String mPort

mDatabase

protected java.lang.String mDatabase

mUsername

protected java.lang.String mUsername

mPassword

protected java.lang.String mPassword

mTablePrefix

protected java.lang.String mTablePrefix

mTravellerTable

protected java.lang.String mTravellerTable

mDestinationTable

protected java.lang.String mDestinationTable

mBookingTable

protected java.lang.String mBookingTable

mRows

protected int mRows

mNumberOfTravellers

protected int mNumberOfTravellers

mNumberOfDestinations

protected int mNumberOfDestinations

mNumberOfBookings

protected int mNumberOfBookings

mSizeOfBlob

protected int mSizeOfBlob
Constructor Detail

CreateTestDB

public CreateTestDB(java.lang.String[] args)
Parse the arguments and populates the test database. Displays an error message if the arguments are invalid or an error arises while creating the test database.

Parameters:
args - the arguments passed to the client's main method.
Method Detail

setDefaultSettings

protected abstract void setDefaultSettings()
Sets the default settings for the client.


populateDatabase

protected void populateDatabase()
                         throws CreateTestDatabaseException
Populates the test database with the test data.

Throws:
CreateTestDatabaseException - if something went wrong

setupArguments

protected boolean setupArguments(java.lang.String[] args)
Parses the arguments general to most CreateTestDB clients. This method may be overridden if a client requires special argument parsing.

Parameters:
args - the argument string
Returns:
true if the arguments are parsed correctly, otherwise false

printUsage

protected void printUsage()
Prints the general usage instructions for a CreateTestDB client. This may be overridden if a client requires special usage.


printVariables

protected void printVariables(java.lang.String prefix)
Displays the settings prefixed by the specified string.

Parameters:
prefix - the displayed settings begin with "prefix Settings:"

loadDriver

protected void loadDriver()
                   throws CreateTestDatabaseException
Loads the driver class specified by the mDriver instance variable.

Throws:
CreateTestDatabaseException - if there is a problem loading the driver

getConnection

protected abstract java.sql.Connection getConnection()
                                              throws java.sql.SQLException
Returns a java.sql.Connection data resource.

Returns:
Connection
Throws:
java.sql.SQLException

dropTableIfExists

protected abstract void dropTableIfExists(java.sql.Connection connection,
                                          java.lang.String tablename)
                                   throws java.sql.SQLException
Drops the specified table. Note: This method must not throw an error if the table does not exist.

Parameters:
connection - a connection to the data resource
tablename - the name of the table to be created
Throws:
java.sql.SQLException

getCreateTravellerTableStatement

protected java.lang.String getCreateTravellerTableStatement()
Constructs the statement for creating the traveller table. Subclasses can override this method if a data resource uses a different statement.

Returns:
a create table statement

getCreateBookingTableStatement

protected java.lang.String getCreateBookingTableStatement()
Constructs the statement for creating the traveller table. Subclasses can override this method if a data resource uses a different statement.

Returns:
a create table statement

getCreateDestinationTableStatement

protected java.lang.String getCreateDestinationTableStatement()
Constructs the statement for creating a destination table. Subclasses can override this method if the statement differs.

Returns:
String a create table statement

createTravellerTable

protected void createTravellerTable(java.sql.Connection connection)
                             throws java.sql.SQLException
Creates a new table with name mTablePrefix+mTravellerTable and populates it with data generated by the TravelDataCreator.

Parameters:
connection - a connection to the data resource
Throws:
java.sql.SQLException

createDestinationTable

protected void createDestinationTable(java.sql.Connection connection)
                               throws java.sql.SQLException
Creates a new table with name mTablePrefix+mDestinationTable and populates it with data generated by the TravelDataCreator.

Parameters:
connection - a connection to the data resource
Throws:
java.sql.SQLException

createBookingTable

protected void createBookingTable(java.sql.Connection connection)
                           throws java.sql.SQLException
Creates a new table with name mTablePrefix+mBookingTable and populates it with data generated by the TravelDataCreator.

Parameters:
connection - a connection to the data resource
Throws:
java.sql.SQLException