Package org.apache.tomcat.dbcp.dbcp2
Class PoolingDataSource<C extends Connection>
- java.lang.Object
-
- org.apache.tomcat.dbcp.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 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 Description voidclose()Closes and free allConnections from the pool.ConnectiongetConnection()Returns aConnectionfrom my pool, according to the contract specified byObjectPool.borrowObject().ConnectiongetConnection(String uname, String passwd)intgetLoginTimeout()ThrowsUnsupportedOperationException.PrintWritergetLogWriter()Returns my log writer.LoggergetParentLogger()protected ObjectPool<C>getPool()booleanisAccessToUnderlyingConnectionAllowed()Returns 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> Tunwrap(Class<T> iface)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
-
-
-
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 RuntimeException, SQLExceptionCloses and free allConnections from the pool.- Specified by:
closein interfaceAutoCloseable- Throws:
RuntimeExceptionSQLException- Since:
- 2.1
-
getConnection
public Connection getConnection() throws SQLException
Returns aConnectionfrom my pool, according to the contract specified byObjectPool.borrowObject().- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
public Connection getConnection(String uname, String passwd) throws SQLException
- Specified by:
getConnectionin interfaceDataSource- Throws:
UnsupportedOperationException- always thrownSQLException
-
getLoginTimeout
public int getLoginTimeout()
ThrowsUnsupportedOperationException.- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
UnsupportedOperationException- As this implementation does not support this feature.
-
getLogWriter
public PrintWriter getLogWriter()
Returns my log writer.- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Returns:
- my log writer
- See Also:
DataSource.getLogWriter()
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
getPool
protected ObjectPool<C> getPool()
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.- Returns:
- true if access to the underlying
Connectionis allowed, false otherwise.
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
- 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- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
UnsupportedOperationException- As this implementation does not support this feature.
-
setLogWriter
public void setLogWriter(PrintWriter out)
Sets my log writer.- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- See Also:
DataSource.setLogWriter(java.io.PrintWriter)
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
-