org.mycore.backend.sql
Class MCRSQLConnectionPool

java.lang.Object
  extended by org.mycore.backend.sql.MCRSQLConnectionPool

public class MCRSQLConnectionPool
extends Object

This class implements a pool of database connections to a relational database like DB2, using JDBC. Other classes get a connection from the pool when they need one and release the connection after their work has finished.

Version:
$Revision: 13253 $ $Date: 2008-03-07 09:05:51 +0100 $
Author:
Frank Lützenkirchen, Jens Kupferschmidt
See Also:
MCRSQLConnection

Field Summary
protected  Vector<MCRSQLConnection> freeConnections
          The internal list of free connections
(package private) static long maxAge
          The maximum age a connection can be before it is reconnected
protected  int maxNumConnections
          The maximum number of connections that will be built
(package private) static int maxUsages
          The maximum number of usages of this connection *
(package private) static String password
           
protected static MCRSQLConnectionPool singleton
          The connection pool singleton
(package private) static String url
           
protected  Vector<MCRSQLConnection> usedConnections
          The internal list of connections that are currently in use
(package private) static String userID
           
 
Constructor Summary
protected MCRSQLConnectionPool()
          Builds the connection pool singleton.
 
Method Summary
 void finalize()
          Finalizer, closes all connections in this connection pool
 MCRSQLConnection getConnection()
          Gets a free connection from the pool.
static MCRSQLConnectionPool instance()
          Returns the connection pool singleton.
(package private)  void releaseConnection(MCRSQLConnection connection)
          Releases a connection, indicating that it is not used any more and should be returned to to pool of free connections.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

protected static MCRSQLConnectionPool singleton
The connection pool singleton


freeConnections

protected Vector<MCRSQLConnection> freeConnections
The internal list of free connections


usedConnections

protected Vector<MCRSQLConnection> usedConnections
The internal list of connections that are currently in use


maxNumConnections

protected int maxNumConnections
The maximum number of connections that will be built


maxUsages

static int maxUsages
The maximum number of usages of this connection *


maxAge

static long maxAge
The maximum age a connection can be before it is reconnected


url

static String url

userID

static String userID

password

static String password
Constructor Detail

MCRSQLConnectionPool

protected MCRSQLConnectionPool()
                        throws MCRPersistenceException
Builds the connection pool singleton.

Throws:
MCRPersistenceException - if the JDBC driver could not be loaded
Method Detail

instance

public static MCRSQLConnectionPool instance()
                                     throws MCRPersistenceException
Returns the connection pool singleton.

Throws:
MCRPersistenceException - if the JDBC driver could not be loaded or initial connections could not be created

getConnection

public MCRSQLConnection getConnection()
                               throws MCRPersistenceException
Gets a free connection from the pool. When this connection is not used any more by the invoker, he is responsible for returning it into the pool by invoking the release() method of the connection.

Returns:
a free connection for your personal use
Throws:
MCRPersistenceException - if there was a problem while building the connection
See Also:
MCRSQLConnection.release()

releaseConnection

void releaseConnection(MCRSQLConnection connection)
Releases a connection, indicating that it is not used any more and should be returned to to pool of free connections. This method is invoked when you call the method release() of the MCRSQLConnection object.

Parameters:
connection - the connection that has been used
See Also:
MCRSQLConnection.release()

finalize

public void finalize()
Finalizer, closes all connections in this connection pool

Overrides:
finalize in class Object