butler.sql.metadata
Class DatabaseBroker

java.lang.Object
  extended by butler.sql.metadata.DatabaseBroker
Direct Known Subclasses:
DefaultDatabaseBroker

public abstract class DatabaseBroker
extends java.lang.Object

Broker for database objects. This class is normally the starting point for using the butler.sql package. Normally using butler starts with the following call.

     db = DatabaseBroker.getInstance().getDatabase("my-alias");
 

Author:
Fredrik Bertilsson
See Also:
DefaultDatabaseBroker

Field Summary
protected  ButlerDriver _driver
           
protected  SchemaParser _schemaParser
           
protected  javax.transaction.TransactionManager _tm
           
 
Constructor Summary
protected DatabaseBroker()
           
 
Method Summary
 void commit()
           
 void completeRequest(boolean success)
          Deprecated. Use getTransactionManager().commit()
 java.lang.Object getContext()
          Returns an user context object that an implementation of butler.sql.metadata.Authorizator would use for extracting a user name.
 Database getDatabase(java.lang.String alias)
          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()
           
static Database getDB(java.lang.String alias)
           
 Schema getDefaultSchema()
          Returns the default schema.
 ButlerDriver getDriver()
          Returns the driver which is used for database operations.
static DatabaseBroker getInstance()
          Returns the DatabaseBroker that should be used.
 Schema getSchema(java.lang.String path)
          Returns the schema for the given path.
 SchemaParser getSchemaParser()
           
 Table getTable(java.lang.String path)
          Returns the table for the given path.
 javax.transaction.TransactionManager getTransactionManager()
           
 javax.transaction.UserTransaction getUserTransaction()
           
 void initRequest()
          Deprecated. Use getTransactionManager().begin()
 void registerChangedRecord(Record rec)
           
 void saveRecords()
           
static void setInstance(DatabaseBroker instance)
          Assigns the singelton DatabaseBroker instance to the given object.
 void setSchemaParser(SchemaParser parser)
           
 void unregisterChangedRecord(Record rec)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tm

protected javax.transaction.TransactionManager _tm

_driver

protected ButlerDriver _driver

_schemaParser

protected SchemaParser _schemaParser
Constructor Detail

DatabaseBroker

protected DatabaseBroker()
Method Detail

getInstance

public static DatabaseBroker getInstance()
                                  throws java.lang.Exception
Returns the DatabaseBroker that should be used. If the DatabaseBroker is set by a preceding call to setInstance(), the assigned DatabaseBroker will be returned.
If the Context.INITIAL_CONTEXT_FACTORY system property is assigned, JNDI will be used to look up the broker with the JNDI name "java:comp/env/bean/DatabaseBroker".
Otherwise a singelton instance of DefaultDatabaseBroker will be returned.

Throws:
java.lang.Exception

getDB

public static Database getDB(java.lang.String alias)
                      throws java.lang.Exception
Throws:
java.lang.Exception

setInstance

public static void setInstance(DatabaseBroker instance)
Assigns the singelton DatabaseBroker instance to the given object. This method can be used if a custom subclass of DatabaseBroker should be used. In such case this method should be called in the startup phase for the application.


getDatabaseNames

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

Throws:
java.lang.Exception

getDatabases

public java.util.Map getDatabases()
                           throws java.lang.Exception
Throws:
java.lang.Exception

getDatabase

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

Throws:
java.lang.Exception

getSchema

public Schema getSchema(java.lang.String path)
                 throws java.lang.Exception
Returns the schema for the given path. The path is given as a string in the format database.catalog.schema

Throws:
java.lang.Exception

getDefaultSchema

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

Throws:
java.lang.Exception

getDriver

public ButlerDriver getDriver()
                       throws java.lang.Exception
Returns the driver which is used for database operations.

Throws:
java.lang.Exception

getContext

public java.lang.Object getContext()
                            throws java.lang.Exception
Returns an user context object that an implementation of butler.sql.metadata.Authorizator would use for extracting a user name. In this base class, null is returned.

Throws:
java.lang.Exception

initRequest

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

Performs necessary initialation for a server request. This method is called by middelware request handlers. This is normally used for transaction handling logic.


completeRequest

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

Performs necessary completions for a server request. This method is called by middelware request handlers. This is normally used for transaction handling logic.

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

commit

public void commit()
            throws java.lang.Exception
Throws:
java.lang.Exception

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()

getUserTransaction

public javax.transaction.UserTransaction getUserTransaction()
                                                     throws java.lang.Exception
Throws:
java.lang.Exception

getSchemaParser

public SchemaParser getSchemaParser()

setSchemaParser

public void setSchemaParser(SchemaParser parser)

getTable

public Table getTable(java.lang.String path)
               throws java.lang.Exception
Returns the table for the given path. The path is given as a string in the format database.catalog.schema.table

Throws:
java.lang.Exception

registerChangedRecord

public void registerChangedRecord(Record rec)

unregisterChangedRecord

public void unregisterChangedRecord(Record rec)

saveRecords

public void saveRecords()
                 throws java.lang.Exception
Throws:
java.lang.Exception