Package org.apache.commons.dbcp2
Class PoolingDataSource<C extends java.sql.Connection>
- java.lang.Object
-
- org.apache.commons.dbcp2.PoolingDataSource<C>
-
- Type Parameters:
C
- The connection type
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.sql.Wrapper
,javax.sql.CommonDataSource
,javax.sql.DataSource
- Direct Known Subclasses:
ManagedDataSource
public class PoolingDataSource<C extends java.sql.Connection> extends java.lang.Object implements javax.sql.DataSource, java.lang.AutoCloseable
A simpleDataSource
implementation that obtainsConnection
s from the specifiedObjectPool
.- Since:
- 2.0
- Version:
- $Id: PoolingDataSource.java 1677110 2015-05-01 11:15:22Z sebb $
- Author:
- Rodney Waldhoff, Glenn L. Nielsen, James House, Dirk Verbeeck
-
-
Constructor Summary
Constructors Constructor Description PoolingDataSource(org.apache.commons.pool2.ObjectPool<C> pool)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close and free allConnection
s from the pool.java.sql.Connection
getConnection()
Return aConnection
from my pool, according to the contract specified byObjectPool.borrowObject()
.java.sql.Connection
getConnection(java.lang.String uname, java.lang.String passwd)
ThrowsUnsupportedOperationException
int
getLoginTimeout()
ThrowsUnsupportedOperationException
.java.io.PrintWriter
getLogWriter()
Returns my log writer.java.util.logging.Logger
getParentLogger()
boolean
isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.boolean
isWrapperFor(java.lang.Class<?> iface)
void
setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property.void
setLoginTimeout(int seconds)
ThrowsUnsupportedOperationException
.void
setLogWriter(java.io.PrintWriter out)
Sets my log writer.<T> T
unwrap(java.lang.Class<T> iface)
-
-
-
Constructor Detail
-
PoolingDataSource
public PoolingDataSource(org.apache.commons.pool2.ObjectPool<C> pool)
-
-
Method Detail
-
close
public void close() throws java.lang.Exception
Close and free allConnection
s from the pool.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.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(java.lang.Class<?> iface) throws java.sql.SQLException
- Specified by:
isWrapperFor
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in interfacejavax.sql.CommonDataSource
- Throws:
java.sql.SQLFeatureNotSupportedException
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Return aConnection
from my pool, according to the contract specified byObjectPool.borrowObject()
.- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(java.lang.String uname, java.lang.String passwd) throws java.sql.SQLException
ThrowsUnsupportedOperationException
- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.lang.UnsupportedOperationException
java.sql.SQLException
-
getLogWriter
public java.io.PrintWriter getLogWriter()
Returns my log writer.- Specified by:
getLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
getLogWriter
in interfacejavax.sql.DataSource
- Returns:
- my log writer
- See Also:
DataSource.getLogWriter()
-
getLoginTimeout
public int getLoginTimeout()
ThrowsUnsupportedOperationException
.- Specified by:
getLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
getLoginTimeout
in interfacejavax.sql.DataSource
- Throws:
java.lang.UnsupportedOperationException
- As this implementation does not support this feature.
-
setLoginTimeout
public void setLoginTimeout(int seconds)
ThrowsUnsupportedOperationException
.- Specified by:
setLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
setLoginTimeout
in interfacejavax.sql.DataSource
- Throws:
java.lang.UnsupportedOperationException
- As this implementation does not support this feature.
-
setLogWriter
public void setLogWriter(java.io.PrintWriter out)
Sets my log writer.- Specified by:
setLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
setLogWriter
in interfacejavax.sql.DataSource
- See Also:
DataSource.setLogWriter(java.io.PrintWriter)
-
-