goldengate.common.database
Class DbConnectionPool

java.lang.Object
  extended by goldengate.common.database.DbConnectionPool

public class DbConnectionPool
extends Object

A simple standalone JDBC connection pool manager.

The public methods of this class are thread-safe.

Nothe that JDBC4 is needed and isValid() must be implemented (not yet in PostGre in April 2012)

Author:
Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
Multi-licensed: EPL/LGPL/MPL., Frederic Bregier
Add TimerTask support to close after some "delay" any still connected sessions

Nested Class Summary
static class DbConnectionPool.TimeoutException
          Thrown in when no free connection becomes available within timeout seconds.
 
Constructor Summary
DbConnectionPool(ConnectionPoolDataSource dataSource)
          Constructs a MiniConnectionPoolManager object with no timeout and no limit.
DbConnectionPool(ConnectionPoolDataSource dataSource, int maxConnections)
          Constructs a MiniConnectionPoolManager object with a timeout of DbConstant.DELAYMAXCONNECTION seconds.
DbConnectionPool(ConnectionPoolDataSource dataSource, int maxConnections, int timeout)
          Constructs a ConnectionPool object.
DbConnectionPool(ConnectionPoolDataSource dataSource, org.jboss.netty.util.Timer timer, long delay)
          Constructs a MiniConnectionPoolManager object with no timeout and no limit.
 
Method Summary
 void dispose()
          Closes all unused pooled connections.
 void freeIdleConnections()
          Release all idle connections
 int getActiveConnections()
          Returns the number of active (open) connections of this pool.
 Connection getConnection()
          Retrieves a connection from the connection pool.
 long getLoginTimeout()
           
 int getMaxConnections()
           
 long getTimeoutForceClose()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbConnectionPool

public DbConnectionPool(ConnectionPoolDataSource dataSource)
Constructs a MiniConnectionPoolManager object with no timeout and no limit.

Parameters:
dataSource - the data source for the connections.

DbConnectionPool

public DbConnectionPool(ConnectionPoolDataSource dataSource,
                        org.jboss.netty.util.Timer timer,
                        long delay)
Constructs a MiniConnectionPoolManager object with no timeout and no limit.

Parameters:
dataSource - the data source for the connections.
timer -
delay - in ms period of time to check existing connections and limit to get a new connection

DbConnectionPool

public DbConnectionPool(ConnectionPoolDataSource dataSource,
                        int maxConnections)
Constructs a MiniConnectionPoolManager object with a timeout of DbConstant.DELAYMAXCONNECTION seconds.

Parameters:
dataSource - the data source for the connections.
maxConnections - the maximum number of connections. 0 means no limit

DbConnectionPool

public DbConnectionPool(ConnectionPoolDataSource dataSource,
                        int maxConnections,
                        int timeout)
Constructs a ConnectionPool object.

Parameters:
dataSource - the data source for the connections.
maxConnections - the maximum number of connections. 0 means no limit
timeout - the maximum time in seconds to wait for a free connection.
Method Detail

freeIdleConnections

public void freeIdleConnections()
Release all idle connections


getMaxConnections

public int getMaxConnections()
Returns:
the max number of connections

getLoginTimeout

public long getLoginTimeout()
Returns:
the Login Timeout in second

getTimeoutForceClose

public long getTimeoutForceClose()
Returns:
the Force Close Timeout in ms

dispose

public void dispose()
             throws SQLException
Closes all unused pooled connections.

Throws:
SQLException - //

getConnection

public Connection getConnection()
                         throws SQLException
Retrieves a connection from the connection pool. If maxConnections connections are already in use, the method waits until a connection becomes available or timeout seconds elapsed. When the application is finished using the connection, it must close it in order to return it to the pool.

Returns:
a new Connection object.
Throws:
DbConnectionPool.TimeoutException - when no connection becomes available within timeout seconds.
SQLException - //

getActiveConnections

public int getActiveConnections()
Returns the number of active (open) connections of this pool. This is the number of Connection objects that have been issued by getConnection() for which Connection.close() has not yet been called.

Returns:
the number of active connections.


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.