uk.org.ogsadai.database.jdbc.book
Class JDBCBookDataCreator

java.lang.Object
  extended by uk.org.ogsadai.database.jdbc.book.JDBCBookDataCreator
Direct Known Subclasses:
DB2BookDataCreator, MySQLBookDataCreator, OracleBookDataCreator, PostgreSQLBookDataCreator, SQLServerBookDataCreator

public class JDBCBookDataCreator
extends java.lang.Object

Class to create OGSA-DAI "littleblackbook"-style tables with schema:

 (id INTEGER, name VARCHAR(64), address VARCHAR(128), phone VARCHAR(20))
 

Two tables created using this class will always have the same data.

Author:
The OGSA-DAI Project Team.

Constructor Summary
JDBCBookDataCreator()
           
 
Method Summary
 void create(java.sql.Connection connection, java.lang.String table)
          Create a table of the given name.
 void create(java.sql.Connection connection, java.lang.String tablePrefix, int numTables)
          Create N tables with the given prefix.
 void drop(java.sql.Connection connection, java.lang.String table)
          Drop a table of the given name.
 void drop(java.sql.Connection connection, java.lang.String tablePrefix, int numTables)
          Drop N tables with the given prefix.
protected  java.lang.String getCreateTableSQL(java.lang.String table)
          Gets an SQL statement that creates a new table.
protected  java.lang.String getDropTableSQL(java.lang.String table)
          Gets an SQL statement that drops a table.
protected  java.lang.String getInsertSQL(java.lang.String table)
          Gets a parameterised SQL statement that inserts data into a table.
 void populate(java.sql.Connection connection, java.lang.String table, int rows)
          Populate a table of the given name.
 void populate(java.sql.Connection connection, java.lang.String tablePrefix, int numTables, int rows)
          Populate N tables with the given prefix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCBookDataCreator

public JDBCBookDataCreator()
Method Detail

create

public void create(java.sql.Connection connection,
                   java.lang.String table)
            throws java.sql.SQLException
Create a table of the given name. If the table already exists it will be initially deleted.

Parameters:
connection - JDBC connection.
table - Table name.
Throws:
java.sql.SQLException - If any problems arise.

populate

public void populate(java.sql.Connection connection,
                     java.lang.String table,
                     int rows)
              throws java.sql.SQLException
Populate a table of the given name. Each table is give rows rows. If rows if 10000 or greater then the rows (apart from the ID field) will have identical values (i.e. row 1 == row 10001 etc).

Parameters:
connection - JDBC connection.
table - Table name.
rows - Number of rows.
Throws:
java.sql.SQLException - If any problems arise.

drop

public void drop(java.sql.Connection connection,
                 java.lang.String table)
          throws java.sql.SQLException
Drop a table of the given name.

Parameters:
connection - JDBC connection.
table - Table name.
Throws:
java.sql.SQLException - If any problems arise.

create

public void create(java.sql.Connection connection,
                   java.lang.String tablePrefix,
                   int numTables)
            throws java.sql.SQLException
Create N tables with the given prefix. Tables are named tablePrefix0 to tablePrefixN where N = numTables - 1. If each table already exists it will be initially deleted.

Parameters:
connection - JDBC connection.
tablePrefix - Table name prefix.
numTables - Number of tables.
Throws:
java.sql.SQLException - If any problems arise.

populate

public void populate(java.sql.Connection connection,
                     java.lang.String tablePrefix,
                     int numTables,
                     int rows)
              throws java.sql.SQLException
Populate N tables with the given prefix. Assumes tables are named tablePrefix0 to tablePrefixN where N = numTables - 1. Each table is given rows rows. If rows if 10000 or greater then the rows (apart from the ID field) will have identical values (i.e. row 1 == row 10001 etc).

Parameters:
connection - JDBC connection.
tablePrefix - Table name prefix.
numTables - Number of tables.
rows - Number of rows.
Throws:
java.sql.SQLException - If any problems arise.

drop

public void drop(java.sql.Connection connection,
                 java.lang.String tablePrefix,
                 int numTables)
          throws java.sql.SQLException
Drop N tables with the given prefix. Assumes tables are named tablePrefix0 to tablePrefixN where N = numTables - 1.

Parameters:
connection - JDBC connection.
tablePrefix - Table name prefix.
numTables - Number of tables.
Throws:
java.sql.SQLException - If any problems arise.

getCreateTableSQL

protected java.lang.String getCreateTableSQL(java.lang.String table)
Gets an SQL statement that creates a new table.

Parameters:
table - Table name.
Returns:
SQL statement.

getInsertSQL

protected java.lang.String getInsertSQL(java.lang.String table)
Gets a parameterised SQL statement that inserts data into a table.

Parameters:
table - Table name.
Returns:
SQL statement.

getDropTableSQL

protected java.lang.String getDropTableSQL(java.lang.String table)
Gets an SQL statement that drops a table.

Parameters:
table - Table name.
Returns:
SQL statement.