Package org.apache.commons.dbcp2
Class PoolingDataSource<C extends Connection>
java.lang.Object
org.apache.commons.dbcp2.PoolingDataSource<C>
- Type Parameters:
C- The connection type
- All Implemented Interfaces:
AutoCloseable,Wrapper,CommonDataSource,DataSource
- Direct Known Subclasses:
ManagedDataSource
public class PoolingDataSource<C extends Connection>
extends Object
implements DataSource, AutoCloseable
- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classPoolGuardConnectionWrapper is a Connection wrapper that makes sure a closed connection cannot be used anymore. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanControls access to the underlying connectionprivate static final org.apache.commons.logging.Logprivate PrintWriterMy log writer.private final org.apache.commons.pool2.ObjectPool<C> -
Constructor Summary
ConstructorsConstructorDescriptionPoolingDataSource(org.apache.commons.pool2.ObjectPool<C> pool) Constructs a new instance backed by the given connection pool. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes and free allConnections from the pool.Returns aConnectionfrom my pool, according to the contract specified byObjectPool.borrowObject().getConnection(String userName, String password) intThrowsUnsupportedOperationException.Returns my log writer.protected org.apache.commons.pool2.ObjectPool<C> getPool()booleanReturns the value of the accessToUnderlyingConnectionAllowed property.booleanisWrapperFor(Class<?> iface) voidsetAccessToUnderlyingConnectionAllowed(boolean allow) Sets the value of the accessToUnderlyingConnectionAllowed property.voidsetLoginTimeout(int seconds) ThrowsUnsupportedOperationException.voidsetLogWriter(PrintWriter out) Sets my log writer.<T> T
-
Field Details
-
log
private static final org.apache.commons.logging.Log log -
accessToUnderlyingConnectionAllowed
private boolean accessToUnderlyingConnectionAllowedControls access to the underlying connection -
logWriter
My log writer. -
pool
-
-
Constructor Details
-
PoolingDataSource
Constructs a new instance backed by the given connection pool.- Parameters:
pool- the given connection pool.
-
-
Method Details
-
close
Closes and free allConnections from the pool.- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException- Since:
- 2.1
-
getConnection
Returns aConnectionfrom my pool, according to the contract specified byObjectPool.borrowObject().- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
UnsupportedOperationException- always thrownSQLException
-
getLoginTimeout
public int getLoginTimeout()ThrowsUnsupportedOperationException.- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Throws:
UnsupportedOperationException- As this implementation does not support this feature.
-
getLogWriter
Returns my log writer.- Specified by:
getLogWriterin interfaceCommonDataSource- Returns:
- my log writer
- See Also:
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
getPool
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()Returns the value of the accessToUnderlyingConnectionAllowed property.- Returns:
- true if access to the underlying
Connectionis allowed, false otherwise.
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
setAccessToUnderlyingConnectionAllowed
public void setAccessToUnderlyingConnectionAllowed(boolean allow) Sets the value of the accessToUnderlyingConnectionAllowed property. It controls if the PoolGuard allows access to the underlying connection. (Default: false)- Parameters:
allow- Access to the underlying connection is granted when true.
-
setLoginTimeout
public void setLoginTimeout(int seconds) ThrowsUnsupportedOperationException.- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Throws:
UnsupportedOperationException- As this implementation does not support this feature.
-
setLogWriter
Sets my log writer.- Specified by:
setLogWriterin interfaceCommonDataSource- See Also:
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-