test.tester.model
Class DatabaseBroker

java.lang.Object
  |
  +--test.tester.model.DatabaseBroker

public class DatabaseBroker
extends java.lang.Object

Every query and connection come from here.

     DatabaseBroker broker = DatabaseBroker.getBroker();
     Query q = broker.getQuery("select.all.tableX");
     q.execute();
     ...
 
The name of the query is associated with a Prepared Statement string, which is inside of a properties file, called [vendor].sql, where the vendor is specified inside of Database.properties.
Also manages the connection to the database. The configuration is a config file which is read at the first init() call. You must init it before using the Broker.

In the near future, it will also manages the connection pool.

DatabaseBroker is for now a singleton.


Constructor Summary
protected DatabaseBroker(java.lang.String configFile)
          Protected constructor that loads the driver and set the configuration from the properties file.
 
Method Summary
static DatabaseBroker getBroker()
          Gets the DatabaseBroker singleton instance.
 java.sql.Connection getConnection()
          Gets a connection to the database.
 Query getQuery(java.lang.String queryName)
          Returns a new query, getting it from the queries config file.
static void init(java.lang.String configFile)
          Inits DatabaseBroker with a config file that will be used to load the driver configuration and queries.
 void releaseConnection(java.sql.Connection conn)
          Releases a connection, making it available to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseBroker

protected DatabaseBroker(java.lang.String configFile)
                  throws DAOException
Protected constructor that loads the driver and set the configuration from the properties file. It will also initialize the Database driver.

Method Detail

init

public static void init(java.lang.String configFile)
                 throws DAOException
Inits DatabaseBroker with a config file that will be used to load the driver configuration and queries.

DAOException

getBroker

public static DatabaseBroker getBroker()
                                throws DAOException
Gets the DatabaseBroker singleton instance.

DAOException

getQuery

public Query getQuery(java.lang.String queryName)
               throws DAOException
Returns a new query, getting it from the queries config file.

DAOException

getConnection

public java.sql.Connection getConnection()
                                  throws DAOException
Gets a connection to the database. Maybe from a connection pool. So you need to release it, after use.

DAOException

releaseConnection

public void releaseConnection(java.sql.Connection conn)
                       throws DAOException
Releases a connection, making it available to the pool.

DAOException