fc.jdbc
Class ConnectionMgr

java.lang.Object
  extended by fc.jdbc.ConnectionMgr
Direct Known Subclasses:
PooledConnectionMgr, SimpleConnectionMgr

public abstract class ConnectionMgr
extends Object

This class implements the gateway to a SQL Database. It should be used to request connections.


Constructor Summary
ConnectionMgr(Log log, PropertyMgr props)
          Constructs a new ConnectionMgr.
ConnectionMgr(Log log, PropertyMgr props, String prefix)
          Constructs a new ConnectionMgr.
ConnectionMgr(PropertyMgr props)
          Delegates to ConnectionMgr(Log, PropertyMgr) with logging to Log.getDefault().
ConnectionMgr(PropertyMgr props, String prefix)
          Delegates to ConnectionMgr(Log, PropertyMgr) with logging to Log.getDefault() and using the specified prefix for property names.
ConnectionMgr(String jdbc_url, String jdbc_driver, String jdbc_user, String jdbc_password, String jdbc_catalog)
          Creates a new ConnectionMgr with logging to logging to Log.getDefault().
 
Method Summary
 boolean close()
          Closes the ConnectionMgr.
 Connection getConnection()
          Returns a connection if successful, otherwise throws a SQLException.
 DBName getDBName()
          Returns the dbname corresponding that the database connected to by this connection manager.
 Driver getDriver()
          Returns the Driver that this connection manager is using to connect to the database.
 String getURL()
          Returns the jdbc url that this connection manager is using,
 void setCatalog(String name)
          If set, the ConnectionMgr will always return connections set to the specified catalog.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionMgr

public ConnectionMgr(String jdbc_url,
                     String jdbc_driver,
                     String jdbc_user,
                     String jdbc_password,
                     String jdbc_catalog)
              throws Exception
Creates a new ConnectionMgr with logging to logging to Log.getDefault().

Parameters:
jdbc.url -
jdbc.driver -
jdbc.user -
jdbc.password -
jdbc.catalog - optional, sets the default and can be null
Throws:
Exception

ConnectionMgr

public ConnectionMgr(PropertyMgr props)
              throws Exception
Delegates to ConnectionMgr(Log, PropertyMgr) with logging to Log.getDefault().

Throws:
Exception

ConnectionMgr

public ConnectionMgr(PropertyMgr props,
                     String prefix)
              throws Exception
Delegates to ConnectionMgr(Log, PropertyMgr) with logging to Log.getDefault() and using the specified prefix for property names.

Throws:
Exception

ConnectionMgr

public ConnectionMgr(Log log,
                     PropertyMgr props)
              throws Exception
Constructs a new ConnectionMgr. The default implementation does not use a connection pool but creates new Connections, whenever needed. Expects the following properties, which should accessible via the specified fc.app.PropertyMgr.
  1. jdbc.url
  2. jdbc.driver
  3. jdbc.user
  4. jdbc.password
  5. An optional jdbc.catalog property sets the default jdbc catalog. Can be null.
Throws an Exception if this object cannot be constructed for some reason.

Throws:
Exception

ConnectionMgr

public ConnectionMgr(Log log,
                     PropertyMgr props,
                     String prefix)
              throws Exception
Constructs a new ConnectionMgr. The default implementation does not use a connection pool but creates new Connections, whenever needed. Expects the following properties, which should accessible via the specified fc.app.PropertyMgr.
  1. jdbc.url
  2. jdbc.driver
  3. jdbc.user
  4. jdbc.password
  5. An optional jdbc.catalog property sets the default jdbc catalog. Can be null.
The optional prefix parameter (if not null) is prepended to each property name before it is accessed from the property manager. For example:
jdbc.url
becomes:
prefixjdbc.url
Throws an Exception if this object cannot be constructed for some reason.

Throws:
Exception
Method Detail

getDriver

public Driver getDriver()
Returns the Driver that this connection manager is using to connect to the database.


getDBName

public DBName getDBName()
                 throws SQLException
Returns the dbname corresponding that the database connected to by this connection manager. Useful for writing database specific code as/when applicable.

Throws:
SQLException

setCatalog

public void setCatalog(String name)
If set, the ConnectionMgr will always return connections set to the specified catalog. Set this to null to return connections not set to any catalog.


getConnection

public Connection getConnection()
                         throws SQLException
Returns a connection if successful, otherwise throws a SQLException. The returned has the default JDBC properties, including being in auto-commit mode (which means that it automatically commits changes after executing each statement).

Throws:
SQLException

close

public boolean close()
Closes the ConnectionMgr. After this call, no more connections can be checked out and any existing checked out connections are closed. Does not throw an Exception but returns false (instead) if the ConnectionMgr could not be closed. Calls the handleMgrShutdown() method inside a synchronized block.

Returns:
true if connection manager closed successfully, false otherwise

getURL

public String getURL()
Returns the jdbc url that this connection manager is using,


toString

public String toString()
Overrides:
toString in class Object