com.ibm.dse.services.jdbc
Class JDBCJournalSchemaGenerator

java.lang.Object
  |
  +--com.ibm.dse.services.jdbc.JDBCServicesAdministrator
        |
        +--com.ibm.dse.services.jdbc.JDBCJournalSchemaGenerator

public class JDBCJournalSchemaGenerator
extends JDBCServicesAdministrator

The JDBCJournalSchemaGenerator class is responsible for creating, modifying, and removing all of the JDBCJournal Tables and the associated Control Tables.


Field Summary
static boolean createSchema
          Keeps the createSchema attribute value.
 java.lang.String databaseName
          Keeps the databaseName attribute value.
 java.lang.String indexName
          Keeps the indexName attribute value.
 int requestedNumberOfGenerations
          Keeps the number of generations for the journal schema
 java.lang.String requestedTableDefinition
          Keeps the journal tables definition in SQL format
 java.lang.String schemaName
          Keeps the journal schema name
 
Fields inherited from class com.ibm.dse.services.jdbc.JDBCServicesAdministrator
COMPID, databaseConnection
 
Constructor Summary
JDBCJournalSchemaGenerator()
          This constructor creates a JDBCJournalSchemaGenerator object.
JDBCJournalSchemaGenerator(java.lang.String aSchemaName)
          This constructor creates a JDBCJournalSchemaGenerator object for the specified schema.
 
Method Summary
 void addEntity(java.lang.String anEntityName)
          Adds a new entity in the journal schema definition.
 Vector allEntities()
          Returns a vector with the entities defined for the current journal schema.
static Vector allEntities(java.lang.String aSchemaName, boolean schemaInDatabase)
          Returns a Vector with the entities names defined for the journal schema aSchemaName.
protected static java.lang.String controlTableName(java.lang.String aSchemaName)
          Returns the name of the control table for the schema name aSchemaName.
protected static DatabaseResultSetMetaData currentJournalTableColumnData(java.lang.String aSchemaName)
          Returns the DatabaseResultSetMetaData instance that contains the journal table columns information.
protected  java.lang.String currentJournalTableDefinition(java.lang.String aSchemaName)
          Calls the currentJournalTableColumnsData method to get the DatabaseResultSetMetaData instance for the schema aSchemaName.
 void generateSchema(Vector aListOfEntities, int nbrOfGenerations, java.lang.String aTableDefinition)
          Generates the journal schema with a schema name previously set or the default database schema name (set in the JournalConstants class in attribute DEFAULT_SCHEMA_NAME).
 void generateSchema(Vector aListOfEntities, int nbrOfGenerations, java.lang.String aTableDefinition, java.lang.String aSchemaName)
          Generates the journal schema with name aSchemaName in the currently connected database.
 java.lang.String getDatabaseName()
          Returns the databaseName attribute.
 java.lang.String getIndexName()
          Returns the indexName attribute.
protected static DatabaseResultSetMetaData getMetaData(java.lang.String aSchemaName, boolean schemaInDatabase)
          Returns the DatabaseResultSetMetaData instance associated with the schema aSchemaName.
 java.lang.String journalTableDefinition()
          Returns a string with the SQL definition of the journal tables columns.
 void loadDriver()
          Loads the JDBC Driver as set in the JournalConstants EJ_DEFAULT_JDBCDRIVER attribute.
 void loadDriver(java.lang.String aDriverName)
          Loads the JDBC Driver explicitly provided as an argument.
 int numberOfGenerations()
          Returns the number of journal generations in the journal service definition.
static int numberOfGenerations(java.lang.String aSchemaName, boolean schemaInDatabase)
          Returns the number of journal generations for the schema aSchemaName.
 void removeAllEntities(java.lang.String aSchemaName)
          Removes all entities for the given journal schema.
 void removeEntity(java.lang.String anEntityName)
          Removes the entity anEntityName from the current journal schema.
 void removeEntity(java.lang.String anEntityName, java.lang.String aSchemaName)
          Removes the entity anEntityName from the journal schema aSchemaName.
 void removeSchema(java.lang.String aSchemaName)
          Removes a journal schema and all its related journal tables.
 void setCreateSchema(boolean newCreateSchema)
          Sets the createSchema attribute value to newCreateSchema.
 void setDatabaseName(java.lang.String newDatabaseName)
          Sets the databaseName attribute value to newDatabaseName.
 void setIndexName(java.lang.String newIndexName)
          Sets the indexName attribute value to newIndexName.
 void setRequestedNumberOfGenerations(int newRequestedNumberOfGenerations)
          Sets the requestedNumberOfGenerations attribute value to newRequestedNumberOfGenerations.
 void setRequestedTableDefinition(java.lang.String newRequestedTableDefinition)
          Sets the requestedTableDefinition attribute value to newRequestedTableDefinition.
 void setSchemaName(java.lang.String newSchemaName)
          Sets the schemaName attribute value to newSchemaName.
protected static java.lang.String tableName(java.lang.String aSchemaName, java.lang.String anEntityName, java.lang.String aGeneration)
          Returns the current journal table name.
 
Methods inherited from class com.ibm.dse.services.jdbc.JDBCServicesAdministrator
connect, connect, disconnect, dropProcedure, getProcedureMetaData, isRegistered, isRegistered, registerProcedure
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestedNumberOfGenerations

public int requestedNumberOfGenerations
Keeps the number of generations for the journal schema

requestedTableDefinition

public java.lang.String requestedTableDefinition
Keeps the journal tables definition in SQL format

schemaName

public java.lang.String schemaName
Keeps the journal schema name

createSchema

public static boolean createSchema
Keeps the createSchema attribute value. This attribute is set to true if the database schema representing the journal schema is to be created in the database, executing a CREATE SCHEMA statement. If this attribute is set to false, the database schema will not be created.

databaseName

public java.lang.String databaseName
Keeps the databaseName attribute value. This attribute is used when working with DB2 UDB in OS/390. In this environment, the database URL as set in the database connection has the following format: jdbc:db2os390:", where is the name of a shared database subsystem with different databases and storage groups defined in it. If not specified, the journal tables will be created in the default database within this location.

indexName

public java.lang.String indexName
Keeps the indexName attribute value. This attribute is used when working with DB2 UDB in OS/390. In this environment, when a table is created, also an index on that table must be created ( while in other operating systems a default index is automatically created). This attribute contains the index name to be used in the CREATE INDEX statement when creating the control table for the journal schema and the index name prefix to be used in the CREATE INDEX statement for all other journal tables. Default value is I.
Constructor Detail

JDBCJournalSchemaGenerator

public JDBCJournalSchemaGenerator()
This constructor creates a JDBCJournalSchemaGenerator object.

JDBCJournalSchemaGenerator

public JDBCJournalSchemaGenerator(java.lang.String aSchemaName)
                           throws DSEInvalidArgumentException,
                                  DSEInvalidRequestException,
                                  DSEInternalErrorException,
                                  DSESQLException
This constructor creates a JDBCJournalSchemaGenerator object for the specified schema.
Parameters:
aSchemaName - java.lang.String the name of the Schema
Throws:
DSEInvalidArgumentException - if the Schema name is not valid
DSEInvalidRequestException - if the Schema already exists
DSEInternalErrorException - if an internal program error occurs
DSESQLException - when a SQL Exception is caught
Method Detail

addEntity

public void addEntity(java.lang.String anEntityName)
               throws DSESQLException,
                      DSEInvalidArgumentException,
                      DSEInternalErrorException,
                      DSEInvalidRequestException
Adds a new entity in the journal schema definition. If the entity already exists, it throws a DSEInvalidArgument exception.
Parameters:
anEntityName - java.lang.String the name of the entity to be added
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught

allEntities

public Vector allEntities()
                   throws DSEInvalidRequestException,
                          DSEInternalErrorException,
                          DSESQLException
Returns a vector with the entities defined for the current journal schema.
Returns:
Vector the vector that contains all entities
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQL Exception is caught

allEntities

public static Vector allEntities(java.lang.String aSchemaName,
                                 boolean schemaInDatabase)
                          throws DSEInvalidRequestException,
                                 DSEInternalErrorException,
                                 DSESQLException
Returns a Vector with the entities names defined for the journal schema aSchemaName. It accesses the schema control table to get this information.
Parameters:
aSchemaName - java.lang.String, the name of the journal schema
schemaInDatabase - java.lang.String, indicates whether the schema was created in the database
Returns:
Vector - the vector that contains all entities
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught

controlTableName

protected static java.lang.String controlTableName(java.lang.String aSchemaName)
Returns the name of the control table for the schema name aSchemaName.
Parameters:
aSchemaName - java.lang.String, the name of the journal schema

currentJournalTableColumnData

protected static DatabaseResultSetMetaData currentJournalTableColumnData(java.lang.String aSchemaName)
                                                                  throws DSEInternalErrorException,
                                                                         DSEInvalidRequestException,
                                                                         DSEInvalidArgumentException,
                                                                         DSESQLException
Returns the DatabaseResultSetMetaData instance that contains the journal table columns information. This method always requests the information from the database. The table name must be constructed by concatenating the schema name (available by default or provided as an argument), an entity name, and a generation number. The entity name is obtained by calling the allEntities method.
Parameters:
aSchemaName - java.lang.String, the journal schema name
Returns:
DatabaseResultSetMetaData - the table meta data
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught

currentJournalTableDefinition

protected java.lang.String currentJournalTableDefinition(java.lang.String aSchemaName)
                                                  throws DSEInvalidArgumentException,
                                                         DSEInvalidRequestException,
                                                         DSEInternalErrorException,
                                                         DSESQLException
Calls the currentJournalTableColumnsData method to get the DatabaseResultSetMetaData instance for the schema aSchemaName. From this information, it builds the string with the journal table columns definition.
Parameters:
aSchemaName - java.lang.String, the journal schema Name
Returns:
java.lang.String - the journal tables definition for the specified schema name in SQL format
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQL Exception is caught

generateSchema

public void generateSchema(Vector aListOfEntities,
                           int nbrOfGenerations,
                           java.lang.String aTableDefinition)
                    throws DSEInvalidArgumentException,
                           DSEInvalidRequestException,
                           DSESQLException,
                           DSEInternalErrorException
Generates the journal schema with a schema name previously set or the default database schema name (set in the JournalConstants class in attribute DEFAULT_SCHEMA_NAME).
Parameters:
aListOfEntities - com.ibm.dse.base.Vector, the vector of journal entities
nbrOfGenerations - int, the number of journal generations
aTableDefinition - java.lang.String, the table definition in SQL format
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQL Exception is caught

generateSchema

public void generateSchema(Vector aListOfEntities,
                           int nbrOfGenerations,
                           java.lang.String aTableDefinition,
                           java.lang.String aSchemaName)
                    throws DSEInvalidArgumentException,
                           DSEInvalidRequestException,
                           DSESQLException,
                           DSEInternalErrorException
Generates the journal schema with name aSchemaName in the currently connected database.
Parameters:
aListOfEntities - com.ibm.dse.base.Vector, the vector of journal entities
nbrOfGenerations - int, the number of journal generations
aTableDefinition - java.lang.String, the table definition in SQL format
aSchemaName - java.lang.String, the journal schema name
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught

getDatabaseName

public java.lang.String getDatabaseName()
Returns the databaseName attribute. Used in OS/390 environment to identify the database inside the location referenced by the database URL where the table is to be created.
Returns:
java.lang.String

getIndexName

public java.lang.String getIndexName()
Returns the indexName attribute. Used in OS/390 environment to create indexes on the journal achema tables.
Returns:
java.lang.String

getMetaData

protected static DatabaseResultSetMetaData getMetaData(java.lang.String aSchemaName,
                                                       boolean schemaInDatabase)
                                                throws DSEInvalidArgumentException,
                                                       DSEInvalidRequestException,
                                                       DSEInternalErrorException,
                                                       DSESQLException
Returns the DatabaseResultSetMetaData instance associated with the schema aSchemaName.
Parameters:
aSchemaName - java.lang.String, the journal schema name
schemaInDatabase - java.lang.String, indicates whether the schema was created in the database
Returns:
DatabaseResultSetMetaData the DatabaseResultSetMetaData (null if the key is not mapped to any value)
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQL Exception is caught

journalTableDefinition

public java.lang.String journalTableDefinition()
                                        throws DSEException
Returns a string with the SQL definition of the journal tables columns.
Returns:
java.lang.String
Throws:
DSEException - if a DSEException occurs

loadDriver

public void loadDriver()
                throws DSEInternalErrorException
Loads the JDBC Driver as set in the JournalConstants EJ_DEFAULT_JDBCDRIVER attribute.
Throws:
DSEInternalErrorException - if an internal program error occurs

loadDriver

public void loadDriver(java.lang.String aDriverName)
                throws DSEInternalErrorException
Loads the JDBC Driver explicitly provided as an argument.
Parameters:
aDriverName - java.lang.String, the driver name (full path)
Throws:
DSEInternalErrorException - if an internal program error occurs

numberOfGenerations

public int numberOfGenerations()
                        throws DSEInvalidRequestException,
                               DSESQLException,
                               DSEInternalErrorException
Returns the number of journal generations in the journal service definition.
Returns:
int
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQL Exception is caught

numberOfGenerations

public static int numberOfGenerations(java.lang.String aSchemaName,
                                      boolean schemaInDatabase)
                               throws DSEInvalidRequestException,
                                      DSESQLException,
                                      DSEInternalErrorException
Returns the number of journal generations for the schema aSchemaName.
Parameters:
aSchemaName - java.lang.String, the journal schema name
schemaInDatabase - java.lang.String, indicates whether the schema was created in the database
Returns:
int
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught

removeAllEntities

public void removeAllEntities(java.lang.String aSchemaName)
                       throws DSEInvalidArgumentException,
                              DSEInvalidRequestException,
                              DSEInternalErrorException,
                              DSESQLException
Removes all entities for the given journal schema.
Parameters:
aSchemaName - java.lang.String, the name of the journal schema
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQL Exception is caught

removeEntity

public void removeEntity(java.lang.String anEntityName)
                  throws DSEInternalErrorException,
                         DSEInvalidArgumentException,
                         DSEInvalidRequestException,
                         DSESQLException
Removes the entity anEntityName from the current journal schema.
Parameters:
anEntityName - java.lang.String, the entity name
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQL Exception is caught

removeEntity

public void removeEntity(java.lang.String anEntityName,
                         java.lang.String aSchemaName)
                  throws DSEInvalidArgumentException,
                         DSEInvalidRequestException,
                         DSEInternalErrorException,
                         DSESQLException
Removes the entity anEntityName from the journal schema aSchemaName.
Parameters:
anEntityName - java.lang.String, the entity name
aSchemaName - java.lang.String, the journal schema name
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught

removeSchema

public void removeSchema(java.lang.String aSchemaName)
                  throws DSEInvalidRequestException,
                         DSEInvalidArgumentException,
                         DSEInternalErrorException,
                         DSESQLException
Removes a journal schema and all its related journal tables.
Parameters:
aSchemaName - java.lang.String, the name of the journal schema
Throws:
DSEInvalidArgumentException - if the argument(s) is(are) not valid
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught

setCreateSchema

public void setCreateSchema(boolean newCreateSchema)
Sets the createSchema attribute value to newCreateSchema.
Parameters:
newCreateSchema - boolean

setDatabaseName

public void setDatabaseName(java.lang.String newDatabaseName)
Sets the databaseName attribute value to newDatabaseName.
Parameters:
newDatabaseName - java.lang.String

setIndexName

public void setIndexName(java.lang.String newIndexName)
Sets the indexName attribute value to newIndexName.
Parameters:
newIndexName - java.lang.String

setRequestedNumberOfGenerations

public void setRequestedNumberOfGenerations(int newRequestedNumberOfGenerations)
Sets the requestedNumberOfGenerations attribute value to newRequestedNumberOfGenerations.
Parameters:
newRequestedNumberOfGenerations - int

setRequestedTableDefinition

public void setRequestedTableDefinition(java.lang.String newRequestedTableDefinition)
Sets the requestedTableDefinition attribute value to newRequestedTableDefinition.
Parameters:
newRequestedTableDefinition - java.lang.String

setSchemaName

public void setSchemaName(java.lang.String newSchemaName)
Sets the schemaName attribute value to newSchemaName.
Parameters:
newSchemaName - java.lang.String

tableName

protected static java.lang.String tableName(java.lang.String aSchemaName,
                                            java.lang.String anEntityName,
                                            java.lang.String aGeneration)
Returns the current journal table name.
Parameters:
aSchemaName - java.lang.String, the journal schema name
anEntityName - java.lang.String, the entity name
aGeneration - java.lang.String, the journal generation
Returns:
java.lang.String - the full table name