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
-
-
Constructor Summary
Constructors Constructor and Description PoolingDataSource(ObjectPool<C> pool)
Constructs a new instance backed by the given connection pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description void
close()
Closes and free allConnection
s from the pool.Connection
getConnection()
Returns aConnection
from my pool, according to the contract specified byObjectPool.borrowObject()
.Connection
getConnection(String uname, String passwd)
int
getLoginTimeout()
ThrowsUnsupportedOperationException
.PrintWriter
getLogWriter()
Returns my log writer.Logger
getParentLogger()
protected ObjectPool<C>
getPool()
boolean
isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.boolean
isWrapperFor(Class<?> iface)
void
setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property.void
setLoginTimeout(int seconds)
ThrowsUnsupportedOperationException
.void
setLogWriter(PrintWriter out)
Sets my log writer.<T> T
unwrap(Class<T> iface)
-
-
-
Constructor Detail
-
PoolingDataSource
public PoolingDataSource(ObjectPool<C> pool)
Constructs a new instance backed by the given connection pool.- Parameters:
pool
- the given connection pool.
-
-
Method Detail
-
close
public void close() throws Exception
Closes and free allConnection
s from the pool.- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
- Since:
- 2.1
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.- Returns:
- true if access to the underlying
Connection
is allowed, false otherwise.
-
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.
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
getConnection
public Connection getConnection() throws SQLException
Returns aConnection
from my pool, according to the contract specified byObjectPool.borrowObject()
.- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getConnection
public Connection getConnection(String uname, String passwd) throws SQLException
- Specified by:
getConnection
in interfaceDataSource
- Throws:
UnsupportedOperationException
- always thrownSQLException
-
getLogWriter
public PrintWriter getLogWriter()
Returns my log writer.- Specified by:
getLogWriter
in interfaceCommonDataSource
- Returns:
- my log writer
- See Also:
CommonDataSource.getLogWriter()
-
getLoginTimeout
public int getLoginTimeout()
ThrowsUnsupportedOperationException
.- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Throws:
UnsupportedOperationException
- As this implementation does not support this feature.
-
setLoginTimeout
public void setLoginTimeout(int seconds)
ThrowsUnsupportedOperationException
.- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Throws:
UnsupportedOperationException
- As this implementation does not support this feature.
-
setLogWriter
public void setLogWriter(PrintWriter out)
Sets my log writer.- Specified by:
setLogWriter
in interfaceCommonDataSource
- See Also:
CommonDataSource.setLogWriter(java.io.PrintWriter)
-
getPool
protected ObjectPool<C> getPool()
-
-