Class PoolableConnection
java.lang.Object
org.apache.commons.dbcp2.AbandonedTrace
org.apache.commons.dbcp2.DelegatingConnection<Connection>
org.apache.commons.dbcp2.PoolableConnection
- All Implemented Interfaces:
AutoCloseable, Connection, Wrapper, PoolableConnectionMXBean, org.apache.commons.pool2.TrackedUse
- Direct Known Subclasses:
PoolableManagedConnection
public class PoolableConnection
extends DelegatingConnection<Connection>
implements PoolableConnectionMXBean
A delegating connection that, rather than closing the underlying
connection, returns itself to an
ObjectPool when
closed.- Since:
- 2.0
- Version:
- $Id: PoolableConnection.java 1658644 2015-02-10 08:59:07Z tn $
- Author:
- Rodney Waldhoff, Glenn L. Nielsen, James House
-
Field Summary
Fields inherited from interface Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
ConstructorsConstructorDescriptionPoolableConnection(Connection conn, org.apache.commons.pool2.ObjectPool<PoolableConnection> pool, ObjectName jmxName) PoolableConnection(Connection conn, org.apache.commons.pool2.ObjectPool<PoolableConnection> pool, ObjectName jmxName, Collection<String> disconnectSqlCodes, boolean fastFailValidation) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Returns me to my pool.Expose theDelegatingConnection.toString()method via a bean getter so it can be read as a property via JMX.booleanisClosed()voidActually close my underlyingConnection.voidValidates the connection, using the following algorithm: IffastFailValidation(constructor argument) istrueand this connection has previously thrown a fatal disconnection exception, aSQLExceptionis thrown.Methods inherited from class DelegatingConnection
abort, clearCachedState, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDelegate, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, innermostDelegateEquals, isReadOnly, isValid, isWrapperFor, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCacheState, setCatalog, setClientInfo, setClientInfo, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, toString, unwrapMethods inherited from class AbandonedTrace
getLastUsedMethods inherited from interface Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValidMethods inherited from interface PoolableConnectionMXBean
clearCachedState, clearWarnings, getAutoCommit, getCacheState, getCatalog, getHoldability, getSchema, getTransactionIsolation, isReadOnly, setAutoCommit, setCacheState, setCatalog, setHoldability, setReadOnly, setSchema, setTransactionIsolation
-
Constructor Details
-
PoolableConnection
public PoolableConnection(Connection conn, org.apache.commons.pool2.ObjectPool<PoolableConnection> pool, ObjectName jmxName, Collection<String> disconnectSqlCodes, boolean fastFailValidation) - Parameters:
conn- my underlying connectionpool- the pool to which I should return when closedjmxName- JMX namedisconnectSqlCodes- SQL_STATE codes considered fatal disconnection errorsfastFailValidation- true means fatal disconnection errors cause subsequent validations to fail immediately (no attempt to run query or isValid)
-
PoolableConnection
public PoolableConnection(Connection conn, org.apache.commons.pool2.ObjectPool<PoolableConnection> pool, ObjectName jmxName) - Parameters:
conn- my underlying connectionpool- the pool to which I should return when closedjmxName- JMX name
-
-
Method Details
-
isClosed
This method should not be used by a client to determine whether or not a connection should be return to the connection pool (by calling
close()). Clients should always attempt to return a connection to the pool once it is no longer required.- Specified by:
isClosedin interfaceConnection- Specified by:
isClosedin interfacePoolableConnectionMXBean- Overrides:
isClosedin classDelegatingConnection<Connection>- Throws:
SQLException
-
close
Returns me to my pool.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Specified by:
closein interfacePoolableConnectionMXBean- Overrides:
closein classDelegatingConnection<Connection>- Throws:
SQLException
-
reallyClose
Actually close my underlyingConnection.- Specified by:
reallyClosein interfacePoolableConnectionMXBean- Throws:
SQLException
-
getToString
Expose theDelegatingConnection.toString()method via a bean getter so it can be read as a property via JMX.- Specified by:
getToStringin interfacePoolableConnectionMXBean
-
validate
Validates the connection, using the following algorithm:- If
fastFailValidation(constructor argument) istrueand this connection has previously thrown a fatal disconnection exception, aSQLExceptionis thrown. - If
sqlis null, the driver's #isValid(timeout)is called. If it returnsfalse,SQLExceptionis thrown; otherwise, this method returns successfully. - If
sqlis not null, it is executed as a query and if the resultingResultSetcontains at least one row, this method returns successfully. If not,SQLExceptionis thrown.
- Parameters:
sql- validation querytimeout- validation timeout- Throws:
SQLException- if validation fails or an SQLException occurs during validation
- If
-