anvil.database
Class ConnectionManager

java.lang.Object
  |
  +--anvil.database.ConnectionManager

public class ConnectionManager
extends java.lang.Object

Class providing interface for acquiring and releasing JDBC connections. Usage:


   import java.sql.*;
   import anvil.database.*;

   ConnectionManager manager = ...;
  
   PooledConnection connImpl = null;
   Connection conn = null;
 
   try {

     connImpl = manager.acquire("njet");
     conn = (Connection)connImpl.getConnection();
     // do some work

   } catch (NoConnectionPoolException e) {
     // handle error
   } catch (CannotReturnPooledConnectionException e) {
     // handle error
   } catch (SQLException e) {
     // It is recommended that the connection is closed in case of SQLException. 
     // When the connection is closed the Connection.isClosed() method returns 
     // false and connection will be removed from the queue by the house-keeping 
     // thread after a short while.
     if (conn!= null) {
       conn.close();
     }
   } finally {
     if (connImpl != null) {
       connImpl.release();
     }
   }
   
 

Version:
$Revision: 1.9 $
Author:
Jani Lehtimäki

Constructor Summary
ConnectionManager()
          Constructs connection manager.
 
Method Summary
 PooledConnection acquire(java.lang.String connectionKey)
          Acquires connection of given type.
 PooledConnection acquire(java.lang.String connectionKey, int timeout)
          Acquires connection of given type, overriding the connection reserve timeout.
 void addPool(ConnectionPool pool)
           
 java.util.Iterator getAccessQueues()
          Gets the iterator of ConnectionAccessQueues.
 boolean hasPool(java.lang.String pool)
           
 void stop()
          Shuts down the connection manager and all related classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManager

public ConnectionManager()
Constructs connection manager.

Method Detail

hasPool

public boolean hasPool(java.lang.String pool)

addPool

public void addPool(ConnectionPool pool)

getAccessQueues

public java.util.Iterator getAccessQueues()
Gets the iterator of ConnectionAccessQueues.

Returns:
Iterator
See Also:
ConnectionAccessQueue

acquire

public PooledConnection acquire(java.lang.String connectionKey)
                         throws NoConnectionPoolException,
                                CannotReturnPooledConnectionException
Acquires connection of given type.

Parameters:
connectionKey - Type of connection
Returns:
Instance of ConnectionManager
Throws:
NoConnectionPoolException - If connectionKey was null or given pool has not been configured.
CannotReturnPooledConnectionException - If connection couldn't be constructed, propably due the acquire timeout.

acquire

public PooledConnection acquire(java.lang.String connectionKey,
                                int timeout)
                         throws NoConnectionPoolException,
                                CannotReturnPooledConnectionException
Acquires connection of given type, overriding the connection reserve timeout.

Parameters:
connectionKey - Type of connection
timeout - Timeout override in seconds (if > 0)
Returns:
Instance of ConnectionManager
Throws:
NoConnectionPoolException - If connectionKey was null or given pool has not been configured.
CannotReturnPooledConnectionException - If connection couldn't be constructed, propably due the acquire timeout.

stop

public void stop()
Shuts down the connection manager and all related classes. Shutdown is complete when this method finishes.