com.tivoli.twg.engine
Class TWGDatabase

java.lang.Object
  extended bycom.tivoli.twg.engine.TWGObject
      extended bycom.tivoli.twg.engine.TWGPersistentObject
          extended bycom.tivoli.twg.engine.TWGDatabase
All Implemented Interfaces:
TWGBaseShadowedObject, TWGShadowedObject

public class TWGDatabase
extends TWGPersistentObject
implements TWGShadowedObject

TWGDatabase is the Director database class. Each instance represents one physical database. The collection of all the instances represents the logical TWG database. Each database has a name that identifies it. At this time only one instance is allowed.


Field Summary
static boolean allowConvertingToTWGEncoding
           
static int CHAR
          JDBC CHAR
static int DATE
          JDBC DATE
static int DATETIME
          Database type for Datetime.
static int DOUBLE
          JDBC DOUBLE
static int INTEGER
          JDBC INTEGER
static java.lang.String magicCharacter
           
static int READONLY
          Read only database connection type
static int REAL
          JDBC REAL
static int SMALLINT
          Standard JDBC data types supported by Director JDBC SMALLINT
static int TRANSACTION
          Transaction database connection type.
static java.lang.String TWG_DB_NAME
          Database name for main Director database.
static int UPDATE
          Update database connection type.
static int VARCHAR
          JDBC VARCHAR
static java.lang.String VERSION
          Database version
 
Fields inherited from class com.tivoli.twg.engine.TWGPersistentObject
CLASS_NAME, SIZEOF_BYTE, SIZEOF_CHAR, SIZEOF_DOUBLE, SIZEOF_FLOAT, SIZEOF_INT, SIZEOF_LONG, SIZEOF_SHORT
 
Constructor Summary
protected TWGDatabase()
          Default constructor: do nothing.
protected TWGDatabase(java.lang.String url, java.lang.String name, java.lang.String user, java.lang.String pwd)
          This method is public as an implementation side effect.
 
Method Summary
protected  TWGDbConnection addConnection()
          This method is public as an implementation side effect.
protected  java.lang.String buildConditionSQL(Vect columnFilters, Vect ops)
           
protected  void closeConnections()
          This method is protected as an implementation side effect.
protected  boolean compactJetDb()
          This method is protected as an implementation side effect.
protected  void deleteManagedObject(long managedObjId)
          This method is protected as an implementation side effect.
protected  void deleteManagedObject(long managedObjId, StringValueSet table_classes)
          This method is protected as an implementation side effect.
protected  void deleteRows(Vect columnFilters, Vect ops)
          This method is protected as an implementation side effect.
 java.util.Enumeration findTableObjects()
          The class method gets all TWGDatabaseTable objects in the database.
protected  void flatten(TWGByteArrayOutputStream data)
          Write table contents to a byte array.
 java.lang.String formatDatetimeValue(java.lang.String str)
          Formats a datetime value formatted correctly for an SQL statement
 java.lang.String formatDateValue(java.lang.String str)
          Formats a date value correctly for an SQL statement
static java.lang.String getBundleString(java.lang.String bundleKey, java.util.Locale loc)
          Look up a value in a resource bundle
 java.lang.String getColumnTypeName(int colType)
          Get database-specific name of column type
 java.lang.String GetConShadowClass()
          Get name of console shadow class.
protected static java.lang.String getConvertedStatement(java.lang.String theString)
          This method converts the java string into the TWG encoding or a the local of the server, dependng on the value of allowConvertingToTWGEncoding.
static TWGDatabase getDatabase(java.lang.String dbname)
          Class method to get a reference to a TWGDatabase object.
 java.lang.String getDatabaseName()
          Get the database name
 TWGDbMetaData getMetaInfo()
          Gets metadata about the database.
 java.lang.String getProductName()
          Gets database product name
static com.tivoli.twg.engine.TWGDbQueryServiceNode getQueryServiceNode()
          This method is public as an implementation side effect.
 byte[] GetShadowRecord(java.util.Locale locale)
          Get buffer containing current values of the shadowed attributes to be delivered to the console shadow class.
 long GetShadowVersion()
          Get object state version.
 TWGDatabaseTable getTable(java.lang.String tableName)
          Instance method to get the table for the supplied table name
static com.tivoli.twg.engine.TWGDbUpdateServiceNode getUpdateServiceNode()
          This method is public as an implementation side effect.
protected  java.lang.String getURL()
          Get the URL for the database
protected  void incrementDirtyLevel()
          This method is protected as an implementation side effect.
protected  void initConnections()
          This method is protected as an implementation side effect.
protected  void initDatabaseDriver()
          Initializes the database driver.
protected  void initDB(java.lang.String url, java.lang.String user, java.lang.String pwd)
          This method is protected as an implementation side effect.
protected  void initDBMetaData(TWGDbConnection con)
          Instance method to initialize the database related metadata variables.
static boolean isActive()
          Class method to determine if the databases are active.
static boolean isDbChanged()
          Check if Director switches to a different database system.
static boolean isEnabled()
          Class method to determine if the databases are enabled.
protected  void registerTable(java.lang.String key, TWGDatabaseTable tableObject)
          This method is protected as an implementation side effect.
protected  void reInitConnections()
          This method is protected as an implementation side effect.
protected  void removeTable(java.lang.String key)
          This method is protected as an implementation side effect.
protected  void replaceManagedObject(long managedObjId, java.util.Vector rows)
          This method is protected as an implementation side effect.
protected  void resetReadWriteMutex()
          This method is protected as an implementation side effect.
protected  void restoreData(TWGPersistentObjectDictionary dict, boolean do_resolve)
          Restore method for database table object
 void returnConnection(TWGDbConnection conn)
          This method is public as an implementation side effect.
protected  void saveData(TWGPersistentObjectDictionary dict)
          Method for saving persistent object data.
protected  void setDatabaseState(int newState)
          Class method to set database state.
protected  void storeRows(java.util.Vector rows, int connType, TWGDbReply dbReply)
          This method is protected as an implementation side effect.
 java.lang.String toString()
          Convert Database to String for debug
 void UpdateShadowVersion()
          Update object state version.
protected static boolean usingDatabase(java.lang.String db_product_name)
          Class method to determine if any of the databases uses the specified database product.
protected  void waitForIdle()
          This method is protected as an implementation side effect.
 
Methods inherited from class com.tivoli.twg.engine.TWGPersistentObject
Destroy, enableAsyncWrites, fromPersistID, initialize, isNewPersistentStore, isSaveRequired, PersistID, restore, restoreAll, save, save, setSaveRequired, terminate, toPersistID
 
Methods inherited from class com.tivoli.twg.engine.TWGObject
AllObjects, AllObjects, Delete, DumpTWGObjects, FindObject, isDeleted, isNewObject, isPersistent, isPersistent, isValid, isValid, ObjectID, setDistinctObjectID, SetObjectID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TWG_DB_NAME

public static final java.lang.String TWG_DB_NAME
Database name for main Director database. Director has only one database at this time

See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
Database version

See Also:
Constant Field Values

READONLY

public static final int READONLY
Read only database connection type

See Also:
Constant Field Values

UPDATE

public static final int UPDATE
Update database connection type. Each row updated in one database command will be automatically committed to the database as it is issued.

See Also:
Constant Field Values

TRANSACTION

public static final int TRANSACTION
Transaction database connection type. Database rows updated in one database command will be committed to the database after all row updates have completed successfully

See Also:
Constant Field Values

SMALLINT

public static final int SMALLINT
Standard JDBC data types supported by Director JDBC SMALLINT

See Also:
Constant Field Values

INTEGER

public static final int INTEGER
JDBC INTEGER

See Also:
Constant Field Values

REAL

public static final int REAL
JDBC REAL

See Also:
Constant Field Values

DOUBLE

public static final int DOUBLE
JDBC DOUBLE

See Also:
Constant Field Values

CHAR

public static final int CHAR
JDBC CHAR

See Also:
Constant Field Values

VARCHAR

public static final int VARCHAR
JDBC VARCHAR

See Also:
Constant Field Values

DATE

public static final int DATE
JDBC DATE

See Also:
Constant Field Values

DATETIME

public static final int DATETIME
Database type for Datetime. Contains the date plus hours minutes and whole seconds. Fractional seconds are not supported. The data will be stored in an appropriate data type dependent on the database product used.

See Also:
Constant Field Values

allowConvertingToTWGEncoding

public static boolean allowConvertingToTWGEncoding

magicCharacter

public static java.lang.String magicCharacter
Constructor Detail

TWGDatabase

protected TWGDatabase()
Default constructor: do nothing. Used for persistent restore.


TWGDatabase

protected TWGDatabase(java.lang.String url,
                      java.lang.String name,
                      java.lang.String user,
                      java.lang.String pwd)
               throws TWGDbException
This method is public as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Constructor for TWGDatabase

Parameters:
url - - URL for the database
name - - title for the database (used for database object identification)
user - - user id to be used when establishing connections to the database
pwd - - password for user id for connecting to the database
Method Detail

initDB

protected void initDB(java.lang.String url,
                      java.lang.String user,
                      java.lang.String pwd)
               throws TWGDatabaseInitException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Initializes non-persistent data for the database object.

Parameters:
url - - URL for the database
Throws:
TWGDatabaseInitException

initDatabaseDriver

protected void initDatabaseDriver()
                           throws TWGDatabaseInitException

Initializes the database driver. Registers the class for the database driver and calls DriverManager.getDriver. This method is to help work around the occasional "No Suitable Driver" error.

Throws:
TWGDatabaseInitException

initConnections

protected void initConnections()
                        throws TWGDbException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Establish the connections to the database

Throws:
TWGDbException

reInitConnections

protected void reInitConnections()
                          throws TWGDbException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Reestablish connections to a database object that already exists.

Throws:
TWGDbException

setDatabaseState

protected void setDatabaseState(int newState)
Class method to set database state.


isActive

public static boolean isActive()
Class method to determine if the databases are active.


isEnabled

public static boolean isEnabled()
Class method to determine if the databases are enabled.


closeConnections

protected void closeConnections()
                         throws TWGDbException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Close all the connections to a database.

Throws:
TWGDbException

getDatabase

public static TWGDatabase getDatabase(java.lang.String dbname)
                               throws TWGDbException
Class method to get a reference to a TWGDatabase object. This method is used when the caller does not have an object reference for the database.

Parameters:
dbname - - name of the database (used for database object identification)
Returns:
TWGDatabase
Throws:
TWGDbException

compactJetDb

protected boolean compactJetDb()
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release. Class method to compact an MS Access (Jet) database

Returns:
-- true if compact successful false if compact failed.

resetReadWriteMutex

protected void resetReadWriteMutex()
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release. Class method to reset ReadWriteMutex


usingDatabase

protected static boolean usingDatabase(java.lang.String db_product_name)
Class method to determine if any of the databases uses the specified database product.

Parameters:
db_product_name - - the database product name. Examples:
  • MS_JET_DB for MS Jet (Access)
  • MS_SQL_DB for MS SQL Server
  • IBM_DB2_DB for IBM DB2

waitForIdle

protected void waitForIdle()
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Wait until database is idle -- no one is using any connections


getQueryServiceNode

public static com.tivoli.twg.engine.TWGDbQueryServiceNode getQueryServiceNode()
This method is public as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Class method to get a reference to the query service node.

Returns:
TWGDbQueryServiceNode

getUpdateServiceNode

public static com.tivoli.twg.engine.TWGDbUpdateServiceNode getUpdateServiceNode()
This method is public as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Class method to get a reference to the update service node.

Returns:
TWGDbUpdateServiceNode

addConnection

protected TWGDbConnection addConnection()
                                 throws TWGDbException
This method is public as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Instance method to open a TWGDbConnection to this database and add the connection to the pool of available connections for this database

Throws:
TWGDbException
See Also:
TWGDbConnection

returnConnection

public void returnConnection(TWGDbConnection conn)
                      throws TWGDbException
This method is public as an implementation side effect. Do not call or change. Its interface may be changed in a later release. Instance method to return a connection to this database and put it back into to the pool of available connections for this database.

Parameters:
conn - - a TWGDbConnection object reference
Throws:
TWGDbException
See Also:
TWGDbConnection, TWGDbException

storeRows

protected void storeRows(java.util.Vector rows,
                         int connType,
                         TWGDbReply dbReply)
                  throws TWGDbException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release. Instance method to update or insert rows in the database

Parameters:
rows - - A vector of TWGDbStoreRow objects containing the updates
connType - - Type of connection: TWGDatabase.UPDATE TWGDatabase.TRANSACTION
Throws:
TWGDbException
See Also:
TWGDbStoreRow

deleteRows

protected void deleteRows(Vect columnFilters,
                          Vect ops)
                   throws TWGDbException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release. Delete rows in a table of the database.

Parameters:
ops - - Vect containing a set of logical operators.
Throws:
TWGDbException
See Also:
TWGDbColumnFilter

deleteManagedObject

protected void deleteManagedObject(long managedObjId)
                            throws TWGDbException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release. Instance method to delete all rows for a managed object from the set of database that the managed object is in.

Parameters:
managedObjId - - the managed object id
Throws:
TWGDbException

deleteManagedObject

protected void deleteManagedObject(long managedObjId,
                                   StringValueSet table_classes)
                            throws TWGDbException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release. Use DbDeleteManagedObject instead.

Instance method to delete all rows for a managed object from a specified list of table classes.

Parameters:
managedObjId - - the managed object id
table_classes - - a StringValueSet containing the table class names
Throws:
TWGDbException

replaceManagedObject

protected void replaceManagedObject(long managedObjId,
                                    java.util.Vector rows)
                             throws TWGDbException
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

For the specified managed object and the specified tables, all rows for the managed object are deleted from these tables and the new rows supplied are inserted into the tables. This command does not support replacing more than one managed object per request at this time.

Parameters:
managedObjId - - managed object id to delete rows for.
rows - - a list of TWGDbStoreRow objects containing the table names and rows to insert.
Throws:
TWGDbException
See Also:
TWGDbStoreRow

incrementDirtyLevel

protected void incrementDirtyLevel()
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Instance method to increment the dirty indicator for the database. It should be used when changes have occurred to the database (such as creating a new table) that would require connections to the database to be closed and new ones obtained in order to see the changes to the database.

See Also:
TWGDbConnection

initDBMetaData

protected void initDBMetaData(TWGDbConnection con)
                       throws TWGDbException
Instance method to initialize the database related metadata variables. Also initializes database field types according to database product name (for the supported product types).

Throws:
TWGDbException
See Also:
TWGDbConnection, TWGDbException

formatDatetimeValue

public java.lang.String formatDatetimeValue(java.lang.String str)
Formats a datetime value formatted correctly for an SQL statement

Returns:
String datetime value formatted for an SQL statement

formatDateValue

public java.lang.String formatDateValue(java.lang.String str)
Formats a date value correctly for an SQL statement

Returns:
String date value formatted for an SQL statement

getMetaInfo

public TWGDbMetaData getMetaInfo()
Gets metadata about the database.

Returns:
TWGDbMetaData
See Also:
TWGDbMetaData

getProductName

public java.lang.String getProductName()
Gets database product name

Returns:
String containing product name that was obtained from database meta data
See Also:
TWGDbMetaData

getURL

protected java.lang.String getURL()
Get the URL for the database

Returns:
String containing the URL

getDatabaseName

public java.lang.String getDatabaseName()
Get the database name

Returns:
the database name

getColumnTypeName

public java.lang.String getColumnTypeName(int colType)
                                   throws TWGDbException
Get database-specific name of column type

Parameters:
colType -
Returns:
column type name string
Throws:
TWGDbException

findTableObjects

public java.util.Enumeration findTableObjects()
The class method gets all TWGDatabaseTable objects in the database.

Returns:
an enumeration of all the database tables

getTable

public TWGDatabaseTable getTable(java.lang.String tableName)
                          throws TWGDbException
Instance method to get the table for the supplied table name

Parameters:
tableName - - name of the table
Returns:
the table
Throws:
TWGDbException

registerTable

protected void registerTable(java.lang.String key,
                             TWGDatabaseTable tableObject)
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Register a table into the list of tables for this database


removeTable

protected void removeTable(java.lang.String key)
This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Remove a table from the the list of all known tables for this database


getBundleString

public static java.lang.String getBundleString(java.lang.String bundleKey,
                                               java.util.Locale loc)
Look up a value in a resource bundle

Parameters:
loc - - locale for the bundle
Returns:
the string from the bundle. If not found, returns the empty string.

isDbChanged

public static boolean isDbChanged()
Check if Director switches to a different database system. Director supports several database systems. It can switch from one database to another. The switch should be done off line.


flatten

protected void flatten(TWGByteArrayOutputStream data)
Write table contents to a byte array. Used for saveData (persistent store)

Parameters:
data - - the TWGByteArrayOutputStream

saveData

protected void saveData(TWGPersistentObjectDictionary dict)
                 throws TWGPersistentObjectSaveException
Method for saving persistent object data.

Overrides:
saveData in class TWGPersistentObject
Parameters:
dict - - dictionary used to accumulate data
Throws:
TWGPersistentObjectSaveException - thrown to abort save procedure.

restoreData

protected void restoreData(TWGPersistentObjectDictionary dict,
                           boolean do_resolve)
                    throws TWGPersistentObjectRestoreException
Restore method for database table object

Overrides:
restoreData in class TWGPersistentObject
Parameters:
dict - - dictionary containing data to be restored
do_resolve - - true if second pass of restore (do resolve)
Throws:
TWGPersistentObjectRestoreException - if restore aborted

toString

public java.lang.String toString()
Convert Database to String for debug

Returns:
String with a textual description of the database.

getConvertedStatement

protected static java.lang.String getConvertedStatement(java.lang.String theString)
This method converts the java string into the TWG encoding or a the local of the server, dependng on the value of allowConvertingToTWGEncoding.

Throws:
- - SQLException
See Also:
Statement

UpdateShadowVersion

public void UpdateShadowVersion()
Update object state version. This method must call the TWGActiveConsole.nextShadowVersion() to update its internal state_version attribute (a 'long' instance variable). This method should be called by any methods of the object's class or subclasses which modify attributes which are send to the shadow objects on the console).

Specified by:
UpdateShadowVersion in interface TWGBaseShadowedObject
See Also:
TWGShadowedObject

GetShadowVersion

public long GetShadowVersion()
Get object state version. This returns value of state_version.

Specified by:
GetShadowVersion in interface TWGBaseShadowedObject
Returns:
state_version attribute value
See Also:
TWGShadowedObject

GetConShadowClass

public java.lang.String GetConShadowClass()
Get name of console shadow class. This returns the name of TWGConObject subclass which is used to hold the attributes shadowed to the console.

Specified by:
GetConShadowClass in interface TWGBaseShadowedObject
Returns:
com.tivoli.twg.engine.TWGConObject subclass which object shadows to
See Also:
TWGShadowedObject

GetShadowRecord

public byte[] GetShadowRecord(java.util.Locale locale)
Get buffer containing current values of the shadowed attributes to be delivered to the console shadow class. This data is delivered along with the ObjectID (so the ObjectID shouldn't be included in the shadowed data record).

Specified by:
GetShadowRecord in interface TWGBaseShadowedObject
Parameters:
locale - - Locale requested (for any locale-specific content)
Returns:
byte array containing opaque data representation of attribute values to be delivered to the console shadow class.
See Also:
TWGShadowedObject

buildConditionSQL

protected java.lang.String buildConditionSQL(Vect columnFilters,
                                             Vect ops)
                                      throws TWGDbException
Throws:
TWGDbException