org.fcrepo.server.storage
Class ConnectionPool

java.lang.Object
  extended by org.fcrepo.server.storage.ConnectionPool

public class ConnectionPool
extends Object

Provides a dispenser for database Connection Pools.

Author:
Ross Wayland, Chris Wilper

Constructor Summary
ConnectionPool(String driver, String url, String username, String password, DDLConverter ddlConverter, int maxActive, int maxIdle, long maxWait, int minIdle, long minEvictableIdleTimeMillis, int numTestsPerEvictionRun, long timeBetweenEvictionRunsMillis, String validationQuery, boolean testOnBorrow, boolean testOnReturn, boolean testWhileIdle, byte whenExhaustedAction)
          Constructs a ConnectionPool that can provide TableCreatingConnections.
ConnectionPool(String driver, String url, String username, String password, int maxActive, int maxIdle, long maxWait, int minIdle, long minEvictableIdleTimeMillis, int numTestsPerEvictionRun, long timeBetweenEvictionRunsMillis, String validationQuery, boolean testOnBorrow, boolean testOnReturn, boolean testWhileIdle, byte whenExhaustedAction)
           Constructs a ConnectionPool based on the calling arguments.
 
Method Summary
 void close()
           Closes the underlying data source
 void free(Connection connection)
           Releases the specified connection and returns it to the pool.
 Connection getReadOnlyConnection()
           Gets the next available connection.
 Connection getReadWriteConnection()
           Gets the next available connection.
 TableCreatingConnection getTableCreatingConnection()
          Gets a TableCreatingConnection.
protected  void setConnectionProperties(Map<String,String> props)
           
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool(String driver,
                      String url,
                      String username,
                      String password,
                      int maxActive,
                      int maxIdle,
                      long maxWait,
                      int minIdle,
                      long minEvictableIdleTimeMillis,
                      int numTestsPerEvictionRun,
                      long timeBetweenEvictionRunsMillis,
                      String validationQuery,
                      boolean testOnBorrow,
                      boolean testOnReturn,
                      boolean testWhileIdle,
                      byte whenExhaustedAction)
               throws SQLException

Constructs a ConnectionPool based on the calling arguments.

Parameters:
driver - The JDBC driver class name.
url - The JDBC connection URL.
username - The database user name.
password - The database password.
maxActive - Maximum number of active instances in pool.
maxIdle - Maximum number of idle instances in pool.
maxWait - Maximum amount of time in milliseconds the borrowObject() method should wait when whenExhaustedAction is set to WHEN_EXHAUSTED_BLOCK.
minIdle - Minimum of idle instances in pool.
minEvictableIdleTimeMillis - Minimum amount of time in milliseconds an object can be idle in pool before eligible for eviction (if applicable).
numTestsPerEvictionRun - Number of objects to be examined on each run of idle evictor thread (if applicable).
timeBetweenEvictionRunsMillis - Time in milliseconds to sleep between runs of the idle object evictor thread.
validationQuery - Query to run when validation connections, e.g. SELECT 1.
testOnBorrow - When true objects are validated before borrowed from the pool.
testOnReturn - When true, objects are validated before returned to hte pool.
testWhileIdle - When true, objects are validated by the idle object evictor thread.
whenExhaustedAction - Action to take when a new object is requested and the the pool has reached maximum number of active objects.
Throws:
SQLException - If the connection pool cannot be established for any reason.

ConnectionPool

public ConnectionPool(String driver,
                      String url,
                      String username,
                      String password,
                      DDLConverter ddlConverter,
                      int maxActive,
                      int maxIdle,
                      long maxWait,
                      int minIdle,
                      long minEvictableIdleTimeMillis,
                      int numTestsPerEvictionRun,
                      long timeBetweenEvictionRunsMillis,
                      String validationQuery,
                      boolean testOnBorrow,
                      boolean testOnReturn,
                      boolean testWhileIdle,
                      byte whenExhaustedAction)
               throws SQLException
Constructs a ConnectionPool that can provide TableCreatingConnections.

Parameters:
driver - The JDBC driver class name.
url - The JDBC connection URL.
username - The database user name.
password - The he database password.
ddlConverter - The DDLConverter that the TableCreatingConnections should use when createTable(TableSpec) is called.
maxActive - Maximum number of active instances in pool.
maxIdle - Maximum number of idle instances in pool.
maxWait - Maximum amount of time in milliseconds the borrowObject() method should wait when whenExhaustedAction is set to WHEN_EXHAUSTED_BLOCK.
minIdle - Minimum of idle instances in pool.
minEvictableIdleTimeMillis - Minimum amount of time in milliseconds an object can be idle in pool before eligible for eviction (if applicable).
numTestsPerEvictionRun - Number of objects to be examined on each run of idle evictor thread (if applicable).
timeBetweenEvictionRunsMillis - Time in milliseconds to sleep between runs of the idle object evictor thread.
validationQuery - Query to run when validation connections, e.g. SELECT 1.
testOnBorrow - When true objects are validated before borrowed from the pool.
testOnReturn - When true, objects are validated before returned to hte pool.
testWhileIdle - When true, objects are validated by the idle object evictor thread.
whenExhaustedAction - Action to take when a new object is requested and the the pool has reached maximum number of active objects.
Throws:
SQLException - If the connection pool cannot be established for any reason.
Method Detail

setConnectionProperties

protected void setConnectionProperties(Map<String,String> props)

getTableCreatingConnection

public TableCreatingConnection getTableCreatingConnection()
                                                   throws SQLException
Gets a TableCreatingConnection.

This derives from the same pool, but wraps the Connection in an appropriate TableCreatingConnection before returning it.

Returns:
The next available Connection from the pool, wrapped as a TableCreatingException, or null if this ConnectionPool hasn't been configured with a DDLConverter (see constructor).
Throws:
SQLException - If there is any propblem in getting the SQL connection.

getReadOnlyConnection

public Connection getReadOnlyConnection()
                                 throws SQLException

Gets the next available connection. Connection is read-only, see getReadWriteConnection() for performing updates

Returns:
The next available connection.
Throws:
SQLException - If the maximum number of connections has been reached or there is some other problem in obtaining the connection.

getReadWriteConnection

public Connection getReadWriteConnection()
                                  throws SQLException

Gets the next available connection. Connection is read-write, only use if updates are to be performed, otherwise use getReadOnlyConnection()

Returns:
The next available connection.
Throws:
SQLException - If the maximum number of connections has been reached or there is some other problem in obtaining the connection.

free

public void free(Connection connection)

Releases the specified connection and returns it to the pool.

Parameters:
connection - A JDBC connection.

toString

public String toString()

Overrides:
toString in class Object

close

public void close()

Closes the underlying data source



Copyright © 2012 DuraSpace. All Rights Reserved.