Class PoolableConnection
java.lang.Object
org.apache.tomcat.dbcp.dbcp2.AbandonedTrace
org.apache.tomcat.dbcp.dbcp2.DelegatingConnection<Connection>
org.apache.tomcat.dbcp.dbcp2.PoolableConnection
- All Implemented Interfaces:
- AutoCloseable,- Connection,- Wrapper,- PoolableConnectionMXBean,- 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
- 
Field SummaryFields inherited from interface java.sql.ConnectionTRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
- 
Constructor SummaryConstructorsConstructorDescriptionPoolableConnection(Connection conn, ObjectPool<PoolableConnection> pool, ObjectName jmxName) PoolableConnection(Connection conn, ObjectPool<PoolableConnection> pool, ObjectName jmxObjectName, Collection<String> disconnectSqlCodes, boolean fastFailValidation) PoolableConnection(Connection conn, ObjectPool<PoolableConnection> pool, ObjectName jmxObjectName, Collection<String> disconnectSqlCodes, Collection<String> disconnectionIgnoreSqlCodes, boolean fastFailValidation) Creates a newPoolableConnectioninstance.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAbort my underlyingConnection.voidclose()Returns this instance to my containing pool.Gets the value of theDelegatingConnection.toString()method via a bean getter, so it can be read as a property via JMX.protected voidHandles the given exception by throwing it.booleanisClosed()booleanprotected voidClears the list of objects being traced by this object.voidCloses the underlyingConnection.voidSets the time this object was last used to the current time in milliseconds.voidDeprecated.voidValidates the connection, using the following algorithm: IffastFailValidation(constructor argument) istrueand this connection has previously thrown a fatal disconnection exception, aSQLExceptionis thrown. Ifsqlis null, the driver's #isValid(timeout)is called.Methods inherited from class org.apache.tomcat.dbcp.dbcp2.DelegatingConnectionactivate, checkOpen, clearCachedState, clearWarnings, closeInternal, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDefaultQueryTimeoutDuration, getDelegate, getDelegateInternal, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleExceptionNoThrow, innermostDelegateEquals, isClosedInternal, isReadOnly, isValid, isValid, isWrapperFor, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCacheState, setCatalog, setClientInfo, setClientInfo, setClosedInternal, setDefaultQueryTimeout, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, toString, unwrapMethods inherited from class org.apache.tomcat.dbcp.dbcp2.AbandonedTraceaddTrace, clearTrace, close, getLastUsed, getLastUsedInstant, getTrace, removeThisTrace, removeTrace, setLastUsed, setLastUsedMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.sql.ConnectionbeginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValidMethods inherited from interface org.apache.tomcat.dbcp.dbcp2.PoolableConnectionMXBeanclearCachedState, clearWarnings, getAutoCommit, getCacheState, getCatalog, getHoldability, getSchema, getTransactionIsolation, isReadOnly, setAutoCommit, setCacheState, setCatalog, setHoldability, setReadOnly, setSchema, setTransactionIsolation
- 
Constructor Details- 
PoolableConnection- Parameters:
- conn- my underlying connection
- pool- the pool to which I should return when closed
- jmxName- JMX name
 
- 
PoolableConnectionpublic PoolableConnection(Connection conn, ObjectPool<PoolableConnection> pool, ObjectName jmxObjectName, Collection<String> disconnectSqlCodes, boolean fastFailValidation) - Parameters:
- conn- my underlying connection
- pool- the pool to which I should return when closed
- jmxObjectName- JMX name
- disconnectSqlCodes- SQL State codes considered fatal disconnection errors
- fastFailValidation- true means fatal disconnection errors cause subsequent validations to fail immediately (no attempt to run query or isValid)
 
- 
PoolableConnectionpublic PoolableConnection(Connection conn, ObjectPool<PoolableConnection> pool, ObjectName jmxObjectName, Collection<String> disconnectSqlCodes, Collection<String> disconnectionIgnoreSqlCodes, boolean fastFailValidation) Creates a newPoolableConnectioninstance.- Parameters:
- conn- my underlying connection
- pool- the pool to which I should return when closed
- jmxObjectName- JMX name
- disconnectSqlCodes- SQL State codes considered fatal disconnection errors
- disconnectionIgnoreSqlCodes- SQL State codes that should be ignored when determining fatal disconnection errors
- fastFailValidation- true means fatal disconnection errors cause subsequent validations to fail immediately (no attempt to run query or isValid)
- Since:
- 2.13.0
 
 
- 
- 
Method Details- 
abortAbort my underlyingConnection.- Specified by:
- abortin interface- Connection
- Overrides:
- abortin class- DelegatingConnection<Connection>
- Throws:
- SQLException
- Since:
- 2.9.0
 
- 
closeReturns this instance to my containing pool.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Connection
- Specified by:
- closein interface- PoolableConnectionMXBean
- Overrides:
- closein class- DelegatingConnection<Connection>
- Throws:
- SQLException- Ignored here, for subclasses.
 
- 
getDisconnectionSqlCodes- Returns:
- The disconnection SQL codes.
- Since:
- 2.6.0
 
- 
getToStringGets the value of theDelegatingConnection.toString()method via a bean getter, so it can be read as a property via JMX.- Specified by:
- getToStringin interface- PoolableConnectionMXBean
- Returns:
- the value of the Object.toString().
 
- 
handleExceptionDescription copied from class:DelegatingConnectionHandles the given exception by throwing it.- Overrides:
- handleExceptionin class- DelegatingConnection<Connection>
- Parameters:
- e- the exception to throw.
- Throws:
- SQLException- the exception to throw.
 
- 
isClosedSeeConnection.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 interface- Connection
- Specified by:
- isClosedin interface- PoolableConnectionMXBean
- Overrides:
- isClosedin class- DelegatingConnection<Connection>
- Returns:
- See Connection.isClosed().
- Throws:
- SQLException- See- Connection.isClosed().
 
- 
isFastFailValidationpublic boolean isFastFailValidation()- Returns:
- Whether to fail-fast.
- Since:
- 2.6.0
 
- 
passivateDescription copied from class:DelegatingConnectionClears the list of objects being traced by this object.- Overrides:
- passivatein class- DelegatingConnection<Connection>
- Throws:
- SQLException- Thrown if not all traced objects were closed.
 
- 
reallyCloseCloses the underlyingConnection.- Specified by:
- reallyClosein interface- PoolableConnectionMXBean
- Throws:
- SQLException- Thrown if the connection can be closed.
 
- 
setLastUsedpublic void setLastUsed()Description copied from class:AbandonedTraceSets the time this object was last used to the current time in milliseconds.- Overrides:
- setLastUsedin class- AbandonedTrace
 
- 
validateValidates 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- The validation SQL query.
- timeoutDuration- The validation timeout in seconds.
- Throws:
- SQLException- Thrown when validation fails or an SQLException occurs during validation
- Since:
- 2.10.0
 
- If 
- 
validateDeprecated.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- The validation SQL query.
- timeoutSeconds- The validation timeout in seconds.
- Throws:
- SQLException- Thrown when validation fails or an SQLException occurs during validation
 
- If 
 
- 
validate(String, Duration).