org.edg.security.voms.database.connection
Class ConnectionPool

java.lang.Object
  |
  +--org.edg.security.voms.database.connection.ConnectionPool
Direct Known Subclasses:
DirectUpdatePool, QueryPool, UpdatePool

public abstract class ConnectionPool
extends java.lang.Object

A trivial database connection pool implementation. TODO: replace this hack with JNDI/JDBC-based real connection pools.

Version:
$Name: v0_7_0 $
Author:
Karoly Lorentey

Field Summary
private static int DEFAULT_MAX_CONN
          The default number of connections that may be open at once.
private  java.util.LinkedList freeConns
          Queue of connections available for use.
private static java.lang.String jdbcDriver
          The JDBC driver to use.
private static java.lang.String jdbcURL
          The JDBC URL for the database.
private static org.apache.log4j.Logger log
          Logger.
private static int MAX_WAIT_RETRIES
          Do not repeat trying to get a new connection more that this number of times.
protected  int maxConn
          Don't open more than this connections.
protected  java.lang.String name
          The name of this pool (e.g.
private  java.lang.String password
          Database password.
private  java.util.Set usedConns
          Database connections currently in use.
private  java.lang.String username
          Database username.
 
Constructor Summary
protected ConnectionPool(java.lang.String name)
          Constructor.
protected ConnectionPool(java.lang.String name, int maxConn)
           
 
Method Summary
 boolean closeAll()
          Close all free database connections.
protected  java.sql.Connection connect()
          Return a new raw database handle.
protected abstract  ConnectionWrapper createConn()
          Create a brand new connection.
 ConnectionWrapper get()
          Return a ConnectionWrapper object from the connection pool.
private  int numConns()
           
 void release(ConnectionWrapper c)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_MAX_CONN

private static final int DEFAULT_MAX_CONN
The default number of connections that may be open at once.

See Also:
Constant Field Values

MAX_WAIT_RETRIES

private static final int MAX_WAIT_RETRIES
Do not repeat trying to get a new connection more that this number of times. Zero means no limit. Note that in order to fix the first access in the morning problem, the currently opened database handles are tried without looking at this number.

See Also:
Constant Field Values

log

private static final transient org.apache.log4j.Logger log
Logger.


maxConn

protected int maxConn
Don't open more than this connections.


freeConns

private final java.util.LinkedList freeConns
Queue of connections available for use.


usedConns

private final java.util.Set usedConns
Database connections currently in use.


jdbcDriver

private static final java.lang.String jdbcDriver
The JDBC driver to use.


jdbcURL

private static final java.lang.String jdbcURL
The JDBC URL for the database.


username

private final java.lang.String username
Database username.


password

private final java.lang.String password
Database password.


name

protected final java.lang.String name
The name of this pool (e.g. "query").

Constructor Detail

ConnectionPool

protected ConnectionPool(java.lang.String name)
                  throws GeneralDatabaseException
Constructor.


ConnectionPool

protected ConnectionPool(java.lang.String name,
                         int maxConn)
Method Detail

createConn

protected abstract ConnectionWrapper createConn()
                                         throws GeneralDatabaseException
Create a brand new connection. This should be extended in subclasses to set suitable extra connection parameters. Subclasses should also check the functionality of the newly created connection by calling its isFunctional() method.

GeneralDatabaseException

connect

protected final java.sql.Connection connect()
                                     throws GeneralDatabaseException
Return a new raw database handle.

GeneralDatabaseException

numConns

private final int numConns()

get

public ConnectionWrapper get()
                      throws VOMSException
Return a ConnectionWrapper object from the connection pool.

Throws:
GeneralDatabaseException - if a database error prevented the allocation of a connection.
VOMSException

release

public void release(ConnectionWrapper c)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

closeAll

public boolean closeAll()
Close all free database connections. This method is intended to be called during service shutdown. Note that it does not free connections which are currently in use.

Returns:
true if all connections were closed.