Class PoolableConnection
java.lang.Object
org.datanucleus.store.rdbms.datasource.dbcp2.AbandonedTrace
org.datanucleus.store.rdbms.datasource.dbcp2.DelegatingConnection<Connection>
org.datanucleus.store.rdbms.datasource.dbcp2.PoolableConnection
- All Implemented Interfaces:
AutoCloseable
,Connection
,Wrapper
,TrackedUse
,PoolableConnectionMXBean
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final Collection
<String> SQL_STATE codes considered to signal fatal conditions.private final boolean
Whether or not to fast fail validation after fatal connection errorsprivate boolean
Indicate that unrecoverable SQLException was thrown when using this connection.private final ObjectNameWrapper
private String
private static MBeanServer
private final ObjectPool
<PoolableConnection> The pool to which I should return.private PreparedStatement
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Constructor Summary
ConstructorsConstructorDescriptionPoolableConnection
(Connection conn, ObjectPool<PoolableConnection> pool, ObjectName jmxName) PoolableConnection
(Connection conn, ObjectPool<PoolableConnection> pool, ObjectName jmxObjectName, Collection<String> disconnectSqlCodes, boolean fastFailValidation) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Returns me to my pool.Expose theDelegatingConnection.toString()
method via a bean getter so it can be read as a property via JMX.protected void
boolean
isClosed()
private boolean
Checks the SQLState of the input exception and any nested SQLExceptions it wraps.boolean
protected void
void
Actually close my underlyingConnection
.void
Validates the connection, using the following algorithm: IffastFailValidation
(constructor argument) istrue
and this connection has previously thrown a fatal disconnection exception, aSQLException
is thrown. Ifsql
is null, the driver's #isValid(timeout)
is called.Methods inherited from class org.datanucleus.store.rdbms.datasource.dbcp2.DelegatingConnection
abort, activate, checkOpen, clearCachedState, clearWarnings, closeInternal, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDelegate, getDelegateInternal, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleExceptionNoThrow, innermostDelegateEquals, isClosedInternal, isReadOnly, isValid, isWrapperFor, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCacheState, setCatalog, setClientInfo, setClientInfo, setClosedInternal, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, toString, unwrap
Methods inherited from class org.datanucleus.store.rdbms.datasource.dbcp2.AbandonedTrace
addTrace, clearTrace, getLastUsed, getTrace, removeThisTrace, removeTrace, setLastUsed, setLastUsed
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
Methods inherited from interface org.datanucleus.store.rdbms.datasource.dbcp2.PoolableConnectionMXBean
clearCachedState, clearWarnings, getAutoCommit, getCacheState, getCatalog, getHoldability, getSchema, getTransactionIsolation, isReadOnly, setAutoCommit, setCacheState, setCatalog, setHoldability, setReadOnly, setSchema, setTransactionIsolation
-
Field Details
-
MBEAN_SERVER
-
pool
The pool to which I should return. -
jmxObjectName
-
validationPreparedStatement
-
lastValidationSql
-
fatalSqlExceptionThrown
private boolean fatalSqlExceptionThrownIndicate that unrecoverable SQLException was thrown when using this connection. Such a connection should be considered broken and not pass validation in the future. -
disconnectionSqlCodes
SQL_STATE codes considered to signal fatal conditions. Overrides the defaults inUtils.DISCONNECTION_SQL_CODES
(plus anything starting withUtils.DISCONNECTION_SQL_CODE_PREFIX
). -
fastFailValidation
private final boolean fastFailValidationWhether or not to fast fail validation after fatal connection errors
-
-
Constructor Details
-
PoolableConnection
public PoolableConnection(Connection conn, ObjectPool<PoolableConnection> pool, ObjectName jmxObjectName, Collection<String> disconnectSqlCodes, boolean fastFailValidation) - Parameters:
conn
- my underlying connectionpool
- the pool to which I should return when closedjmxObjectName
- 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
- Parameters:
conn
- my underlying connectionpool
- the pool to which I should return when closedjmxName
- JMX name
-
-
Method Details
-
passivate
- Overrides:
passivate
in classDelegatingConnection<Connection>
- Throws:
SQLException
-
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:
isClosed
in interfaceConnection
- Specified by:
isClosed
in interfacePoolableConnectionMXBean
- Overrides:
isClosed
in classDelegatingConnection<Connection>
- Throws:
SQLException
-
close
Returns me to my pool.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Specified by:
close
in interfacePoolableConnectionMXBean
- Overrides:
close
in classDelegatingConnection<Connection>
- Throws:
SQLException
-
reallyClose
Actually close my underlyingConnection
.- Specified by:
reallyClose
in interfacePoolableConnectionMXBean
- Throws:
SQLException
-
getToString
Expose theDelegatingConnection.toString()
method via a bean getter so it can be read as a property via JMX.- Specified by:
getToString
in interfacePoolableConnectionMXBean
-
validate
Validates the connection, using the following algorithm:- If
fastFailValidation
(constructor argument) istrue
and this connection has previously thrown a fatal disconnection exception, aSQLException
is thrown. - If
sql
is null, the driver's #isValid(timeout)
is called. If it returnsfalse
,SQLException
is thrown; otherwise, this method returns successfully. - If
sql
is not null, it is executed as a query and if the resultingResultSet
contains at least one row, this method returns successfully. If not,SQLException
is 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
-
isDisconnectionSqlException
Checks the SQLState of the input exception and any nested SQLExceptions it wraps.If
disconnectionSqlCodes
has been set, sql states are compared to those in the configured list of fatal exception codes. If this property is not set, codes are compared against the default codes inUtils.DISCONNECTION_SQL_CODES
and in this case anything starting with #{link Utils.DISCONNECTION_SQL_CODE_PREFIX} is considered a disconnection.- Parameters:
e
- SQLException to be examined- Returns:
- true if the exception signals a disconnection
-
handleException
- Overrides:
handleException
in classDelegatingConnection<Connection>
- Throws:
SQLException
-
getDisconnectionSqlCodes
- Returns:
- The disconnection SQL codes.
- Since:
- 2.6.0
-
isFastFailValidation
public boolean isFastFailValidation()- Returns:
- Whether to fail-fast.
- Since:
- 2.6.0
-