Creating the schema

After the connection to the database has been set, you can then generate the tables by invoking one of the following methods:
void generateSchema(Vector entities, int numberOfGenerations, 
    String journalTableDefinition)

void generateSchema(Vector entities, int numberOfGenerations, 
    String journalTableDefinition, String aSchemaName)

You can specify the schema name, either by setting the schemaName attribute of the JDBCJournalSchemaGenerator instance (and then using the first method to generate the tables) or by passing the attribute as an argument to the generateSchema method (using the second method). If you do not provide the schema name, the method uses the default value of DSESCHEM. If the schema does not have to be explicitly created in the database, you must set the createSchema attribute to false before calling the generateSchema method. In this situation, the JDBCJournalSchemaGenerator expects the schema identified by the schemaName attribute to be defined and accessible in the database.

If the journal tables are created in the default schema associated with a database user (in most DBMS such as DB2(R) and Oracle, when the DBMS creates a user, it assigns the user a default schema that has a name matching the user identification), you must set the userDefaultSchema attribute to true before calling the generateSchema method This automatically sets the schemaName to the user name.

The first argument for both methods is a collection of strings with the names of the desired entities. The Vector of entities is mandatory, even if the journal is working with a unique entity. The second argument is the desired number of journal generations to be kept in the database. The third argument is a string with the SQL definition of the journal tables (without the record number DSERECN primary key, which is automatically added to the table definition).

The following is an example:

Vector entities= new Vector(3);
entities.addElement("User1");
entities.addElement("User2");
entities.addElement("User3"); 
jsg = new JDBCJournalSchemaGenerator;
String tableDefinition = "BRANCHNUMBER CHAR(4), AGREEMENTNUMBER
INTEGER, DUEDATE DATE";
jsg.generateSchema(entities, 6, tableDefinition); 

This sample creates 18 tables for the schema DSESCHEM with columns BRANCHNUMBER, AGREEMENTNUMBER, and DUEDATE, plus the extra column DSERECN. In addition, it creates the control table.

The following table describes the JDBCJournalSchemaGenerator arguments, their default values, and when they should be set to a different value:

Table 1. JDBCJournalSchemaGenerator arguments
Attribute name Description
schemaName Contains the name of the journal schema. If you do not set this attribute, either explicitly or as an argument of the generateSchema method, the method uses the default value of DSESCHEM. If the userDefaultSchema attribute is set to true, the schemaName attribute is set to the name of the user creating the tables.

Default value: DSESCHEM
createSchema Indicates whether the schema identified by schemaName must be explicitly created before the tables are created. If you set this attribute to false, the schema identified by schemaName must be already available in the database.

When the DBMS is Oracle or SQLServer 2000, always set this attribute to false, as the schemas are automatically created when a new database user is defined and no other schemas can be created.

Default value: true

createIndex Indicates whether the indexes for the journal tables must be explicitly created after creating the tables. DB2 for NT/AIX and Oracle automatically create indexes on the table primary keys when the table is created.

Default value: false
userDefaultSchema Indicates whether the journal tables are going to be created in the default schema of the database user that is connected to the database. If you set this attribute to true, the value of the schemaName attribute value is not used.

When the DBMS is Oracle, you can either set this attribute to true, in which case the DBMS creates the tables in the schema associated to the user executing the CREATE TABLE statement (the schema name matches the user name), or you can keep this attribute as false, in which case you must set the schemaName attribute to the schema of another user and set the createSchema attribute to false.

Default value: false
databaseName Indicates which database contains the table. If you do not specify a value, the DBMS creates the journal tables in the default database within this location.