butler.sql.metadata
Class DefaultDatabaseBroker

java.lang.Object
  extended by butler.sql.metadata.DatabaseBroker
      extended by butler.sql.metadata.DefaultDatabaseBroker

public class DefaultDatabaseBroker
extends DatabaseBroker

Default subclass of DatabaseBroker. This subclass creates Database objects from a configuration file.

The configuration file should be located in the current working directory (user.dir) and have the name "databases.xml", or the complete path could be given by the system property butler.config.file.

If the system property catalina.home is set (means that butler is used in a servlet engine environment), connection pooling will be used. Otherwise, for swing clients, pooling will not be used.

The format of the configuration file is described in the DTD below.

Author:
Fredrik Bertilsson
See Also:
Databases DTD

Nested Class Summary
static class DefaultDatabaseBroker.Factory
          Factory for creating JNDI resources.
 
Field Summary
 
Fields inherited from class butler.sql.metadata.DatabaseBroker
_driver, _schemaParser, _tm
 
Constructor Summary
DefaultDatabaseBroker()
           
 
Method Summary
 void completeRequest(boolean success)
          Deprecated. Use DatabaseBroker.getInstance().getTransactionManager().commit()
 Database getDatabase(java.lang.String name)
          Returns the database with the given alias.
 java.util.Iterator getDatabaseNames()
          Returns an iteraton of all names of databases registered to this DatabaseBroker.
 java.util.Map getDatabases()
           
 Schema getDefaultSchema()
          Returns the default schema.
 java.lang.String getFile()
          Returns the full path of the configuration file.
 java.lang.Object getRequestContext()
           
 Schema getSchema(java.lang.String alias)
          Returns the schema with the given alias.
 void initRequest()
          Deprecated. Use DatabaseBroker.getInstance().getTransactionManager().begin()
 void setDriver(ButlerDriver driver)
           
 void setFile(java.lang.String name)
          Sets full path of the configuration file.
 void setPassword(java.lang.String pwd)
          Sets the current user password.
 void setRequestContext(java.lang.Object requestContext)
           
 void setUser(java.lang.String user)
          Sets the current user name.
 
Methods inherited from class butler.sql.metadata.DatabaseBroker
commit, getContext, getDB, getDriver, getInstance, getSchemaParser, getTable, getTransactionManager, getUserTransaction, registerChangedRecord, saveRecords, setInstance, setSchemaParser, unregisterChangedRecord
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultDatabaseBroker

public DefaultDatabaseBroker()
Method Detail

setUser

public void setUser(java.lang.String user)
Sets the current user name.


setPassword

public void setPassword(java.lang.String pwd)
Sets the current user password.


setFile

public void setFile(java.lang.String name)
             throws java.lang.Exception
Sets full path of the configuration file.

Throws:
java.lang.Exception

getFile

public java.lang.String getFile()
Returns the full path of the configuration file.


getDatabaseNames

public java.util.Iterator getDatabaseNames()
                                    throws java.lang.Exception
Returns an iteraton of all names of databases registered to this DatabaseBroker.

Overrides:
getDatabaseNames in class DatabaseBroker
Throws:
java.lang.Exception

getDatabases

public java.util.Map getDatabases()
                           throws java.lang.Exception
Overrides:
getDatabases in class DatabaseBroker
Throws:
java.lang.Exception

getDatabase

public Database getDatabase(java.lang.String name)
                     throws java.lang.Exception
Returns the database with the given alias.

Overrides:
getDatabase in class DatabaseBroker
Throws:
java.lang.Exception

getSchema

public Schema getSchema(java.lang.String alias)
                 throws java.lang.Exception
Returns the schema with the given alias. This is an convenience method for getting a schema, normally a schema is retrieved by retrieving database, catalog and schema.

Overrides:
getSchema in class DatabaseBroker
Throws:
java.lang.Exception

getDefaultSchema

public Schema getDefaultSchema()
                        throws java.lang.Exception
Returns the default schema.

Overrides:
getDefaultSchema in class DatabaseBroker
Throws:
java.lang.Exception

setDriver

public void setDriver(ButlerDriver driver)

getRequestContext

public java.lang.Object getRequestContext()
                                   throws java.lang.Exception
Throws:
java.lang.Exception

setRequestContext

public void setRequestContext(java.lang.Object requestContext)

initRequest

public void initRequest()
Deprecated. Use DatabaseBroker.getInstance().getTransactionManager().begin()

Description copied from class: DatabaseBroker
Performs necessary initialation for a server request. This method is called by middelware request handlers. This is normally used for transaction handling logic.

Overrides:
initRequest in class DatabaseBroker

completeRequest

public void completeRequest(boolean success)
                     throws java.sql.SQLException
Deprecated. Use DatabaseBroker.getInstance().getTransactionManager().commit()

Commits or rollbacks all used jdbc connections, and returns them to the connection pool, if the connection pool is used.

Overrides:
completeRequest in class DatabaseBroker
Parameters:
success - Tells if the request was a success or ended with an exception.
Throws:
java.sql.SQLException