javatools.db
Class DbManager

java.lang.Object
  |
  +--javatools.db.DbManager

public class DbManager
extends java.lang.Object

A class to manage all the other DbDatabases. Usually there will be only one DbManager object, thus you should use singleton() to access it.

e.g. DbDatabase db = DbManager.singleton().getDatabase("foo");


Field Summary
(package private)  java.util.Map databaseNameMap
           
(package private)  java.util.Map nameDatabaseMap
           
(package private)  Props props
           
(package private) static DbManager single
           
 
Constructor Summary
DbManager()
           
 
Method Summary
 void close()
          Close ALL connections associated with this database.
 void commit()
          Perform a commit on ALL connections associated with this database.
 void commitClose()
          Commit and close ALL connections associated with this database.
 DbDatabase getDatabase(java.lang.String name)
          Return the database associated with this name.
 DbDatabase getDatabase(java.lang.String name, java.lang.String driver, java.lang.String connectString, java.lang.String userName, java.lang.String password)
          Return the database object associated with this name or parameters.
 java.util.Map getDatabaseNameMap()
          Return a Map that maps DbDatabases to names.
 java.util.Map getNameDatabaseMap()
          Return a Map that maps names to DbDatabases.
 Props getProps()
          Return a properties object for the db subsystem.
 void rollback()
          Perform a rollback on ALL connections associated with this database.
 void rollbackClose()
          Rollback and close ALL connections associated with this database.
static DbManager singleton()
          Return THE DbManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

single

static DbManager single

nameDatabaseMap

java.util.Map nameDatabaseMap

databaseNameMap

java.util.Map databaseNameMap

props

Props props
Constructor Detail

DbManager

public DbManager()
Method Detail

singleton

public static DbManager singleton()
Return THE DbManager.

Returns:
Description of the Returned Value

getNameDatabaseMap

public java.util.Map getNameDatabaseMap()
Return a Map that maps names to DbDatabases.

Returns:
The nameDatabaseMap value

getDatabaseNameMap

public java.util.Map getDatabaseNameMap()
Return a Map that maps DbDatabases to names.

Returns:
The databaseNameMap value

getProps

public Props getProps()
               throws java.io.IOException
Return a properties object for the db subsystem. Currently we always use a "db.properties" that is found on the classpath.

Returns:
The props value
Throws:
java.io.IOException - Description of Exception

getDatabase

public DbDatabase getDatabase(java.lang.String name,
                              java.lang.String driver,
                              java.lang.String connectString,
                              java.lang.String userName,
                              java.lang.String password)
                       throws DbException
Return the database object associated with this name or parameters. If you don't give a name DbManager won't be able to cache DbDatabase objects, so giving a name is recommended. Usually the name will be just something which identifies this application. Once a DbDatabase is in the cache you can use the getDatabase(name) with one argument. Alternatively you can always use the one argument version and the parameters will come from the db.properties file.

Parameters:
name - An arbitrary name used to identify this DbDatabase.
driver - The Java JDBC driver class name.
connectString - The JDBC connect string.
userName - The database connect user name.
password - The database connect password.
Returns:
The database value
Throws:
DbException - Description of Exception

getDatabase

public DbDatabase getDatabase(java.lang.String name)
                       throws DbException
Return the database associated with this name. If the database is already in the cache we return that, otherwise we attempt to read a db properties file and get a connect configuration from that with . . For example, you could have a notional database called "foo". Then in your db.properties file you might have a setup like:
 foo.driver  = oracle.jdbc.driver.OracleDriver
 foo.connect = jdbc:oracle:thin:@dbdev01:1521:devu02
 foo.userId = foouserid
 foo.password = foopassword
 
In terms of where the db.properties file will be located, that is determined by the javatools.util.Props class.

Parameters:
name - The name in the cache and/or in the db.properties file.
Returns:
The database value
Throws:
DbException - Description of Exception
See Also:
Props

commitClose

public void commitClose()
                 throws DbException
Commit and close ALL connections associated with this database.

Throws:
DbException - Description of Exception

rollbackClose

public void rollbackClose()
                   throws DbException
Rollback and close ALL connections associated with this database.

Throws:
DbException - Description of Exception

commit

public void commit()
            throws DbException
Perform a commit on ALL connections associated with this database.

Throws:
DbException - Description of Exception

rollback

public void rollback()
              throws DbException
Perform a rollback on ALL connections associated with this database.

Throws:
DbException - Description of Exception

close

public void close()
           throws DbException
Close ALL connections associated with this database.

Throws:
DbException - Description of Exception