|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl
org.apache.ojb.broker.accesslayer.ConnectionFactoryDBCPImpl
public class ConnectionFactoryDBCPImpl
ConnectionFactory implementation using Commons DBCP and Commons Pool API to pool connections. Based on a proposal of Dirk Verbeek - Thanks.
| Field Summary | |
|---|---|
static String |
PARAM_NAME_POOL_STATEMENTS
|
static String |
PARAM_NAME_STATEMENT_POOL_MAX_TOTAL
|
static String |
PARAM_NAME_UNWRAP_ALLOWED
|
| Constructor Summary | |
|---|---|
ConnectionFactoryDBCPImpl()
|
|
| Method Summary | |
|---|---|
Connection |
checkOutJdbcConnection(JdbcConnectionDescriptor jcd)
Returns a valid JDBC Connection. |
protected org.apache.commons.dbcp.ConnectionFactory |
createConnectionFactory(JdbcConnectionDescriptor jcd)
Creates a DriverManager-based ConnectionFactory for creating the Connection instances to feed into the object pool of the specified jcd-alias. |
protected org.apache.commons.pool.ObjectPool |
createConnectionPool(org.apache.commons.pool.impl.GenericObjectPool.Config config,
org.apache.commons.dbcp.AbandonedConfig ac)
|
protected org.apache.commons.pool.ObjectPool |
createObjectPool(org.apache.commons.pool.impl.GenericObjectPool.Config config)
Deprecated. since OJB 1.0.4, please use createConnectionPool(org.apache.commons.pool.impl.GenericObjectPool.Config, org.apache.commons.dbcp.AbandonedConfig) |
protected org.apache.commons.dbcp.PoolingDataSource |
createPoolingDataSource(org.apache.commons.pool.ObjectPool connectionPool)
Deprecated. since OJB 1.0.4, please use wrapAsDataSource(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor, org.apache.commons.pool.ObjectPool) |
protected org.apache.commons.pool.KeyedObjectPoolFactory |
createStatementPoolFactory(JdbcConnectionDescriptor jcd)
|
protected DataSource |
getDataSource(JdbcConnectionDescriptor jcd)
Returns the DBCP DataSource for the specified connection descriptor, after creating a new DataSource if needed. |
void |
releaseAllResources()
Closes all managed pools. |
void |
releaseJdbcConnection(JdbcConnectionDescriptor jcd,
Connection con)
Releases a Connection after use. |
protected org.apache.commons.pool.ObjectPool |
setupPool(JdbcConnectionDescriptor jcd)
Returns a new ObjectPool for the specified connection descriptor. |
protected DataSource |
wrapAsDataSource(JdbcConnectionDescriptor jcd,
org.apache.commons.pool.ObjectPool connectionPool)
Wraps the specified object pool for connections as a DataSource. |
| Methods inherited from class org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl |
|---|
getDbURL, getJcdDescription, getJdbcProperties, getJdbcProperties, initializeJdbcConnection, lookupConnection, newConnectionFromDataSource, newConnectionFromDriverManager, releaseConnection |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String PARAM_NAME_UNWRAP_ALLOWED
public static final String PARAM_NAME_POOL_STATEMENTS
public static final String PARAM_NAME_STATEMENT_POOL_MAX_TOTAL
| Constructor Detail |
|---|
public ConnectionFactoryDBCPImpl()
| Method Detail |
|---|
public Connection checkOutJdbcConnection(JdbcConnectionDescriptor jcd)
throws LookupException
ConnectionFactoryAbstractImplNote: This method is never called for a jdbc-connection-descriptor that uses datasources, OJB only manages connections from DriverManager.
Note: If the concrete implementation does not callback to
ConnectionFactoryAbstractImpl.newConnectionFromDriverManager(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor)
when creating a new Connection, it must call
ConnectionFactoryAbstractImpl.initializeJdbcConnection(java.sql.Connection, org.apache.ojb.broker.metadata.JdbcConnectionDescriptor)
so that the platform implementation can peform any RDBMS-specific init tasks for newly
created Connection objetcs.
checkOutJdbcConnection in class ConnectionFactoryAbstractImpljcd - the connection descriptor for which to return a validated Connection
LookupException - if a valid Connection could not be obtained
public void releaseJdbcConnection(JdbcConnectionDescriptor jcd,
Connection con)
throws LookupException
ConnectionFactoryAbstractImplNote: This method is never called for a jdbc-connection-descriptor that uses datasources, OJB only manages connections from DriverManager.
releaseJdbcConnection in class ConnectionFactoryAbstractImpljcd - the connection descriptor for which the connection was createdcon - the connection to release.
Callers must guarantee that the passed connection was obtained by calling
ConnectionFactoryAbstractImpl.checkOutJdbcConnection(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor).
LookupException - if errors occured during release of object. Typically happens
if return of object to pool fails in a pooled implementation.public void releaseAllResources()
releaseAllResources in interface ConnectionFactoryreleaseAllResources in class ConnectionFactoryAbstractImpl
protected DataSource getDataSource(JdbcConnectionDescriptor jcd)
throws LookupException
jcd - the descriptor for which to return a DataSource
LookupException - if pool is not in cache and cannot be createdprotected org.apache.commons.pool.ObjectPool setupPool(JdbcConnectionDescriptor jcd)
jcd - the connection descriptor for which to set up the pool
protected org.apache.commons.pool.ObjectPool createConnectionPool(org.apache.commons.pool.impl.GenericObjectPool.Config config,
org.apache.commons.dbcp.AbandonedConfig ac)
protected org.apache.commons.pool.KeyedObjectPoolFactory createStatementPoolFactory(JdbcConnectionDescriptor jcd)
protected DataSource wrapAsDataSource(JdbcConnectionDescriptor jcd,
org.apache.commons.pool.ObjectPool connectionPool)
jcd - the OJB connection descriptor for the pool to be wrappedconnectionPool - the connection pool to be wrapped
protected org.apache.commons.dbcp.ConnectionFactory createConnectionFactory(JdbcConnectionDescriptor jcd)
NB! If you override this method to specify your own ConnectionFactory
you must make sure that you follow OJB's lifecycle contract defined in the
Platform API - ie that you call
initializeJdbcConnection when a new Connection is created. For convenience, use
ConnectionFactoryAbstractImpl.initializeJdbcConnection(java.sql.Connection, org.apache.ojb.broker.metadata.JdbcConnectionDescriptor) instead of Platform call.
The above is automatically true if you re-use the inner class ConPoolFactory
below and just override this method for additional user-defined "tweaks".
jcd - the jdbc-connection-alias for which we are creating a ConnectionFactory
Platform API.protected org.apache.commons.pool.ObjectPool createObjectPool(org.apache.commons.pool.impl.GenericObjectPool.Config config)
createConnectionPool(org.apache.commons.pool.impl.GenericObjectPool.Config, org.apache.commons.dbcp.AbandonedConfig)
protected org.apache.commons.dbcp.PoolingDataSource createPoolingDataSource(org.apache.commons.pool.ObjectPool connectionPool)
wrapAsDataSource(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor, org.apache.commons.pool.ObjectPool)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||