Databases

Database

Database

The database represents a Database in an Enterprise.

Database Name

The database has a logical database name, which is accessed using the get/setDatabaseName() methods.

This is defined with the following syntax: -

source=<logical name>

For example: -

source=furniture

The database can also have a physical name, which is accessed using the get/setPhyscialName() methods.

The physical name is defined using the following syntax: -

<source>.physicalName=<physical name>

For example: -

furniture.physicalName=furniture1

Database Context

Databases can live in Contexts. Contexts has a name a provide way of grouping databases. Sets of Databases can be accessed from the server using a context name.

The context of a database is defined, in a macro, by the following syntax: -

$CONTEXTNAME=<Context Name>

For example: -

$CONTEXTNAME=Furniture

Database Vendor

The database is associated with a Vendor, which is accessed using get/setVendor() methods.

The vendor is defined using the following syntax: -

<source>.vendor=[ms|sybase|kdb|interbase|oracle|interbase]

For example: -

furniture.vendor=ms

Comments

A comment can be added to each database, this is set using the following syntax: -

<DatabaseName>.comment=<comment>

For example: -

RefDatabase.comment=This is a comment

 

Copyright

A copyright can be added to each database, this is set using the following syntax: -

<DatabaseName>.copyright=<copyright>

For example: -

RefDatabase.copyright=(c) Javelin Software all Right Reserved

 

Author

An author can be added to each database, this is set using the following syntax: -

<DatabaseName>.author=<author>

For example: -

RefDatabase.author=Robin Sharp

Database Access

JGenerator usually accesses the database using JPool. JPool uses the database name as its source name. However a user name and password may need to be access the database directly (e.g. for EJB).

The user name and password properties can be accessed using the get/setPassword() and get/setPassword() methods.

These values can be defined using the following syntax: -

<source>.userName=<username>
<source>.password=<password>

For example: -

furniture.userName=user1
furniture.password=password1

Database Tables

Tables can be added, removed or retrieved from a database. Adding or Removing a Table to a database will either set the Table's database property or clear it, respectively.

The Database is also able to calculate the table dependency order. This is the order that Tables must be removed from the database. Reversing the dependency order gives the order that tables must be added.

Database Validation

The validation method calls the validation method on all the tables.

Writing Databases

The following example shows how to call a methods, passing each table in turn as a parameter: -

for( int index = 0; index < tables.getTableCount(); index++ )
{
    printTable( (Table)database.getTable( index ) );
}

The following example shows how to write out a set of SQL drop statements for a database, making use of the canonical vendor name method: -

for( Enumeration tables = database.getDependentTables(); tables.hasMoreElements() )
{
    Table table = (Table)tables.nextElement();
    writer.println( "DROP TABLE " + table.getVendor().getCanonicalName( table ) );
    writer.println( "DROP TABLE " + table.getVendor().getCommandTerminator());
}