java.lang.Object
com.aoapps.sql.wrapper.ConnectionWrapperImpl
com.aoapps.sql.tracker.ConnectionTrackerImpl
- All Implemented Interfaces:
ConnectionTracker
,OnCloseHandler
,TrackedArrays
,TrackedBlobs
,TrackedCallableStatements
,TrackedClobs
,TrackedDatabaseMetaDatas
,TrackedInputStreams
,TrackedNClobs
,TrackedOutputStreams
,TrackedParameterMetaDatas
,TrackedPreparedStatements
,TrackedReaders
,TrackedRefs
,TrackedResultSetMetaDatas
,TrackedResultSets
,TrackedRowIds
,TrackedSavepoints
,TrackedSQLDatas
,TrackedSQLInputs
,TrackedSQLOutputs
,TrackedSQLXMLs
,TrackedStatements
,TrackedStructs
,TrackedWriters
,ConnectionWrapper
,Wrapper
,AutoCloseable
,Connection
,Wrapper
Tracks a
Connection
for unclosed or unfreed objects.- Author:
- AO Industries, Inc.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Level
The logging level that enables allocation stack trace logging.Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Constructor Summary
ConstructorDescriptionConnectionTrackerImpl
(DriverTracker driver, Connection wrapped) Creates a newConnection
tracker.ConnectionTrackerImpl
(Connection wrapped) Creates a newConnection
tracker. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Calls onClose handlers, clears all tracking, then callsdoAbort(java.util.concurrent.Executor)
.void
addOnClose
(Runnable onCloseHandler) Will call the handler once on close/free.protected void
Clears all tracking.void
close()
Calls onClose handlers, closes all tracked objects, rolls-back any transaction in-progress and puts back in auto-commit mode, then callsdoClose()
.protected Throwable
closeTracked
(Throwable t0, String sourceMethod) Closes / frees all tracked objects except savepoints, which are expected to be closed by a followingrollback()
.void
commit()
Removes tracking of savepoints while committing the transaction.protected void
Performs the actual abort, called once all onClose handlers completed and all tracking cleared.protected void
doClose()
Performs the actual close, called once all onClose handlers completed and all tracked objects closed.final Map
<Array, ArrayTrackerImpl> Gets all the arrays that have not yet been freed.final Map
<Blob, BlobTrackerImpl> Gets all the blobs that have not yet been freed.Gets all the callable statements that have not yet been closed.final Map
<Clob, ClobTrackerImpl> Gets all the clobs that have not yet been freed.Gets all the meta data that have not yet been closed.final Map
<InputStream, InputStreamTracker> Gets all the input streams that have not yet been closed.final Map
<NClob, NClobTrackerImpl> Gets all the nclobs that have not yet been freed.final Map
<OutputStream, OutputStreamTracker> Gets all the output streams that have not yet been closed.Gets all the meta data that have not yet been closed.Gets all the prepared statements that have not yet been closed.final Map
<Reader, ReaderTracker> Gets all the readers that have not yet been closed.final Map
<Ref, RefTrackerImpl> Gets all the refs that have not yet been closed.Gets all the meta data that have not yet been closed.final Map
<ResultSet, ResultSetTrackerImpl> Gets all the result sets that have not yet been closed.final Map
<RowId, RowIdTrackerImpl> Gets all the row IDs that have not yet been closed.final Map
<Savepoint, SavepointTrackerImpl> Gets all the savepoints that have not yet been released.final Map
<SQLData, SQLDataTrackerImpl> Gets all the SQL datas that have not yet been closed.final Map
<SQLInput, SQLInputTrackerImpl> Gets all the SQL inputs that have not yet been closed.final Map
<SQLOutput, SQLOutputTrackerImpl> Gets all the SQL outputs that have not yet been closed.final Map
<SQLXML, SQLXMLTrackerImpl> Gets all the SQL XMLs that have not yet been freed.final Map
<Statement, StatementTrackerImpl> Gets all the statements that have not yet been closed.final Map
<Struct, StructTrackerImpl> Gets all the structs that have not yet been closed.final Map
<Writer, WriterTracker> Gets all the writers that have not yet been closed.protected ArrayTrackerImpl
newArrayWrapper
(StatementWrapperImpl stmtWrapper, Array array) protected BlobTrackerImpl
newBlobWrapper
(Blob blob) protected CallableStatementTrackerImpl
protected ClobTrackerImpl
newClobWrapper
(Clob clob) protected DatabaseMetaDataTrackerImpl
newDatabaseMetaDataWrapper
(DatabaseMetaData metaData) protected InputStreamTracker
protected NClobTrackerImpl
newNClobWrapper
(NClob nclob) protected OutputStreamTracker
protected ParameterMetaDataTrackerImpl
newParameterMetaDataWrapper
(ParameterMetaData metaData) protected PreparedStatementTrackerImpl
protected ReaderTracker
protected RefTrackerImpl
newRefWrapper
(Ref ref) protected ResultSetMetaDataTrackerImpl
newResultSetMetaDataWrapper
(ResultSetMetaData metaData) protected ResultSetTrackerImpl
newResultSetWrapper
(StatementWrapperImpl stmtWrapper, ResultSet results) protected RowIdTrackerImpl
newRowIdWrapper
(RowId rowId) protected SavepointTrackerImpl
newSavepointWrapper
(Savepoint savepoint) protected SQLDataTrackerImpl
newSQLDataWrapper
(SQLData sqlData) protected SQLInputTrackerImpl
newSQLInputWrapper
(SQLInput sqlInput) protected SQLOutputTrackerImpl
newSQLOutputWrapper
(SQLOutput sqlOutput) protected SQLXMLTrackerImpl
newSQLXMLWrapper
(SQLXML sqlXml) protected StatementTrackerImpl
newStatementWrapper
(Statement stmt) protected StructTrackerImpl
newStructWrapper
(Struct struct) protected WriterTracker
newWriterWrapper
(Writer out) protected Throwable
Releases all tracked savepoints.void
releaseSavepoint
(Savepoint savepoint) Removes tracking while releasing the savepoint.void
rollback()
Removes tracking of savepoints while rolling-back the transaction.void
Removes tracking of all savepoints after the given savepoint, the rolls-back to the given savepoint.void
setAutoCommit
(boolean autoCommit) Removes tracking of savepoints when auto-commit mode is enabled (which commits any transaction in-progress).Methods inherited from class com.aoapps.sql.wrapper.ConnectionWrapperImpl
createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getDriver, getMetaData, getWrapped, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, setSavepoint, setSavepoint, toString, unwrapArray, unwrapBlob, unwrapClob, unwrapInputStream, unwrapNClob, unwrapReader, unwrapRef, unwrapRowId, unwrapSavepoint, unwrapSQLXML, unwrapStruct, wrapArray, wrapBlob, wrapCallableStatement, wrapClob, wrapDatabaseMetaData, wrapInputStream, wrapNClob, wrapOutputStream, wrapParameterMetaData, wrapPreparedStatement, wrapReader, wrapRef, wrapResultSet, wrapResultSetMetaData, wrapRowId, wrapSavepoint, wrapSQLData, wrapSQLInput, wrapSQLOutput, wrapSQLXML, wrapStatement, wrapStruct, wrapWriter
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 com.aoapps.sql.wrapper.ConnectionWrapper
clearWarnings, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, getWrapped, getWrappedConnection, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap
Methods inherited from interface com.aoapps.sql.wrapper.Wrapper
isWrapperFor, unwrap
-
Field Details
-
ALLOCATION_STACKTRACE_LOG_LEVEL
The logging level that enables allocation stack trace logging.
-
-
Constructor Details
-
ConnectionTrackerImpl
Creates a newConnection
tracker. -
ConnectionTrackerImpl
Creates a newConnection
tracker.
-
-
Method Details
-
getAllocationStacktrace
-
getAllocationLogger
-
addOnClose
Description copied from interface:OnCloseHandler
Will call the handler once on close/free.- Specified by:
addOnClose
in interfaceOnCloseHandler
-
getTrackedArrays
Description copied from interface:TrackedArrays
Gets all the arrays that have not yet been freed.- Specified by:
getTrackedArrays
in interfaceTrackedArrays
- Returns:
- The mapping from wrapped array to tracker without any defensive copy.
- See Also:
-
getTrackedBlobs
Description copied from interface:TrackedBlobs
Gets all the blobs that have not yet been freed.- Specified by:
getTrackedBlobs
in interfaceTrackedBlobs
- Returns:
- The mapping from wrapped blob to tracker without any defensive copy.
- See Also:
-
getTrackedCallableStatements
Description copied from interface:TrackedCallableStatements
Gets all the callable statements that have not yet been closed.- Specified by:
getTrackedCallableStatements
in interfaceTrackedCallableStatements
- Returns:
- The mapping from wrapped callable statement to tracker without any defensive copy.
- See Also:
-
getTrackedClobs
Description copied from interface:TrackedClobs
Gets all the clobs that have not yet been freed. This only containsClob
, please see other method forNClob
.- Specified by:
getTrackedClobs
in interfaceTrackedClobs
- Returns:
- The mapping from wrapped clob to tracker without any defensive copy.
- See Also:
-
getTrackedDatabaseMetaDatas
Description copied from interface:TrackedDatabaseMetaDatas
Gets all the meta data that have not yet been closed. Meta datas are assumed to be closed with their connection.- Specified by:
getTrackedDatabaseMetaDatas
in interfaceTrackedDatabaseMetaDatas
- Returns:
- The mapping from wrapped meta data to tracker without any defensive copy.
- See Also:
-
getTrackedInputStreams
Description copied from interface:TrackedInputStreams
Gets all the input streams that have not yet been closed.- Specified by:
getTrackedInputStreams
in interfaceTrackedInputStreams
- Returns:
- The mapping from wrapped input stream to tracker without any defensive copy.
- See Also:
-
getTrackedNClobs
Description copied from interface:TrackedNClobs
Gets all the nclobs that have not yet been freed.- Specified by:
getTrackedNClobs
in interfaceTrackedNClobs
- Returns:
- The mapping from wrapped nclob to tracker without any defensive copy.
- See Also:
-
getTrackedOutputStreams
Description copied from interface:TrackedOutputStreams
Gets all the output streams that have not yet been closed.- Specified by:
getTrackedOutputStreams
in interfaceTrackedOutputStreams
- Returns:
- The mapping from wrapped output stream to tracker without any defensive copy.
- See Also:
-
getTrackedParameterMetaDatas
Description copied from interface:TrackedParameterMetaDatas
Gets all the meta data that have not yet been closed. Meta datas are assumed to be closed with their prepared statement.- Specified by:
getTrackedParameterMetaDatas
in interfaceTrackedParameterMetaDatas
- Returns:
- The mapping from wrapped meta data to tracker without any defensive copy.
- See Also:
-
getTrackedPreparedStatements
Description copied from interface:TrackedPreparedStatements
Gets all the prepared statements that have not yet been closed. This only containsPreparedStatement
, please see other method forCallableStatement
.- Specified by:
getTrackedPreparedStatements
in interfaceTrackedPreparedStatements
- Returns:
- The mapping from wrapped prepared statement to tracker without any defensive copy.
- See Also:
-
getTrackedReaders
Description copied from interface:TrackedReaders
Gets all the readers that have not yet been closed.- Specified by:
getTrackedReaders
in interfaceTrackedReaders
- Returns:
- The mapping from wrapped reader to tracker without any defensive copy.
- See Also:
-
getTrackedRefs
Description copied from interface:TrackedRefs
Gets all the refs that have not yet been closed. Refs are assumed to be closed with their connection.- Specified by:
getTrackedRefs
in interfaceTrackedRefs
- Returns:
- The mapping from wrapped ref to tracker without any defensive copy.
- See Also:
-
getTrackedResultSets
Description copied from interface:TrackedResultSets
Gets all the result sets that have not yet been closed.- Specified by:
getTrackedResultSets
in interfaceTrackedResultSets
- Returns:
- The mapping from wrapped result set to tracker without any defensive copy.
- See Also:
-
getTrackedResultSetMetaDatas
Description copied from interface:TrackedResultSetMetaDatas
Gets all the meta data that have not yet been closed. Meta datas are assumed to be closed with their result set.- Specified by:
getTrackedResultSetMetaDatas
in interfaceTrackedResultSetMetaDatas
- Returns:
- The mapping from wrapped meta data to tracker without any defensive copy.
- See Also:
-
getTrackedRowIds
Description copied from interface:TrackedRowIds
Gets all the row IDs that have not yet been closed. Row IDs are assumed to be closed with their connection.- Specified by:
getTrackedRowIds
in interfaceTrackedRowIds
- Returns:
- The mapping from wrapped row ID to tracker without any defensive copy.
- See Also:
-
getTrackedSQLDatas
Description copied from interface:TrackedSQLDatas
Gets all the SQL datas that have not yet been closed.- Specified by:
getTrackedSQLDatas
in interfaceTrackedSQLDatas
- Returns:
- The mapping from wrapped SQL data to tracker without any defensive copy.
- See Also:
-
getTrackedSQLInputs
Description copied from interface:TrackedSQLInputs
Gets all the SQL inputs that have not yet been closed.- Specified by:
getTrackedSQLInputs
in interfaceTrackedSQLInputs
- Returns:
- The mapping from wrapped SQL input to tracker without any defensive copy.
- See Also:
-
getTrackedSQLOutputs
Description copied from interface:TrackedSQLOutputs
Gets all the SQL outputs that have not yet been closed.- Specified by:
getTrackedSQLOutputs
in interfaceTrackedSQLOutputs
- Returns:
- The mapping from wrapped SQL output to tracker without any defensive copy.
- See Also:
-
getTrackedSQLXMLs
Description copied from interface:TrackedSQLXMLs
Gets all the SQL XMLs that have not yet been freed.- Specified by:
getTrackedSQLXMLs
in interfaceTrackedSQLXMLs
- Returns:
- The mapping from wrapped SQL XML to tracker without any defensive copy.
- See Also:
-
getTrackedSavepoints
Description copied from interface:TrackedSavepoints
Gets all the savepoints that have not yet been released.- Specified by:
getTrackedSavepoints
in interfaceTrackedSavepoints
- Returns:
- The mapping from wrapped savepoint to tracker without any defensive copy.
- See Also:
-
getTrackedStatements
Description copied from interface:TrackedStatements
Gets all the statements that have not yet been closed. This only containsStatement
, please see other methods forPreparedStatement
andCallableStatement
.- Specified by:
getTrackedStatements
in interfaceTrackedStatements
- Returns:
- The mapping from wrapped statement to tracker without any defensive copy.
- See Also:
-
getTrackedStructs
Description copied from interface:TrackedStructs
Gets all the structs that have not yet been closed. Structs are assumed to be closed with their connection.- Specified by:
getTrackedStructs
in interfaceTrackedStructs
- Returns:
- The mapping from wrapped struct to tracker without any defensive copy.
- See Also:
-
getTrackedWriters
Description copied from interface:TrackedWriters
Gets all the writers that have not yet been closed.- Specified by:
getTrackedWriters
in interfaceTrackedWriters
- Returns:
- The mapping from wrapped writer to tracker without any defensive copy.
- See Also:
-
closeTracked
Closes / frees all tracked objects except savepoints, which are expected to be closed by a followingrollback()
. -
clearTracking
protected void clearTracking()Clears all tracking. -
releaseAllTrackedSavepoints
Releases all tracked savepoints. -
newArrayWrapper
- Overrides:
newArrayWrapper
in classConnectionWrapperImpl
-
newBlobWrapper
- Overrides:
newBlobWrapper
in classConnectionWrapperImpl
-
newCallableStatementWrapper
- Overrides:
newCallableStatementWrapper
in classConnectionWrapperImpl
-
newClobWrapper
- Overrides:
newClobWrapper
in classConnectionWrapperImpl
-
newDatabaseMetaDataWrapper
- Overrides:
newDatabaseMetaDataWrapper
in classConnectionWrapperImpl
-
newInputStreamWrapper
- Overrides:
newInputStreamWrapper
in classConnectionWrapperImpl
-
newNClobWrapper
- Overrides:
newNClobWrapper
in classConnectionWrapperImpl
-
newOutputStreamWrapper
- Overrides:
newOutputStreamWrapper
in classConnectionWrapperImpl
-
newParameterMetaDataWrapper
- Overrides:
newParameterMetaDataWrapper
in classConnectionWrapperImpl
-
newPreparedStatementWrapper
- Overrides:
newPreparedStatementWrapper
in classConnectionWrapperImpl
-
newReaderWrapper
- Overrides:
newReaderWrapper
in classConnectionWrapperImpl
-
newRefWrapper
- Overrides:
newRefWrapper
in classConnectionWrapperImpl
-
newResultSetWrapper
protected ResultSetTrackerImpl newResultSetWrapper(StatementWrapperImpl stmtWrapper, ResultSet results) - Overrides:
newResultSetWrapper
in classConnectionWrapperImpl
-
newResultSetMetaDataWrapper
- Overrides:
newResultSetMetaDataWrapper
in classConnectionWrapperImpl
-
newRowIdWrapper
- Overrides:
newRowIdWrapper
in classConnectionWrapperImpl
-
newSQLDataWrapper
- Overrides:
newSQLDataWrapper
in classConnectionWrapperImpl
-
newSQLInputWrapper
- Overrides:
newSQLInputWrapper
in classConnectionWrapperImpl
-
newSQLOutputWrapper
- Overrides:
newSQLOutputWrapper
in classConnectionWrapperImpl
-
newSQLXMLWrapper
- Overrides:
newSQLXMLWrapper
in classConnectionWrapperImpl
-
newSavepointWrapper
- Overrides:
newSavepointWrapper
in classConnectionWrapperImpl
-
newStatementWrapper
- Overrides:
newStatementWrapper
in classConnectionWrapperImpl
-
newStructWrapper
- Overrides:
newStructWrapper
in classConnectionWrapperImpl
-
newWriterWrapper
- Overrides:
newWriterWrapper
in classConnectionWrapperImpl
-
setAutoCommit
Removes tracking of savepoints when auto-commit mode is enabled (which commits any transaction in-progress).- Specified by:
setAutoCommit
in interfaceConnection
- Specified by:
setAutoCommit
in interfaceConnectionTracker
- Specified by:
setAutoCommit
in interfaceConnectionWrapper
- Throws:
SQLException
- See Also:
-
commit
Removes tracking of savepoints while committing the transaction.- Specified by:
commit
in interfaceConnection
- Specified by:
commit
in interfaceConnectionTracker
- Specified by:
commit
in interfaceConnectionWrapper
- Throws:
SQLException
- See Also:
-
rollback
Removes tracking of savepoints while rolling-back the transaction.- Specified by:
rollback
in interfaceConnection
- Specified by:
rollback
in interfaceConnectionTracker
- Specified by:
rollback
in interfaceConnectionWrapper
- Throws:
SQLException
- See Also:
-
close
Calls onClose handlers, closes all tracked objects, rolls-back any transaction in-progress and puts back in auto-commit mode, then callsdoClose()
.This default implementation calls
doClose()
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Specified by:
close
in interfaceConnectionTracker
- Specified by:
close
in interfaceConnectionWrapper
- Overrides:
close
in classConnectionWrapperImpl
- Throws:
SQLException
- See Also:
-
rollback
Removes tracking of all savepoints after the given savepoint, the rolls-back to the given savepoint.- Specified by:
rollback
in interfaceConnection
- Specified by:
rollback
in interfaceConnectionTracker
- Specified by:
rollback
in interfaceConnectionWrapper
- Overrides:
rollback
in classConnectionWrapperImpl
- Throws:
SQLException
- See Also:
-
releaseSavepoint
Removes tracking while releasing the savepoint.- Specified by:
releaseSavepoint
in interfaceConnection
- Specified by:
releaseSavepoint
in interfaceConnectionTracker
- Specified by:
releaseSavepoint
in interfaceConnectionWrapper
- Overrides:
releaseSavepoint
in classConnectionWrapperImpl
- Throws:
SQLException
- See Also:
-
abort
Calls onClose handlers, clears all tracking, then callsdoAbort(java.util.concurrent.Executor)
. Trusts the underlying implementation ofConnection.abort(java.util.concurrent.Executor)
will free all resources.This default implementation calls
doAbort(java.util.concurrent.Executor)
.- Specified by:
abort
in interfaceConnection
- Specified by:
abort
in interfaceConnectionTracker
- Specified by:
abort
in interfaceConnectionWrapper
- Overrides:
abort
in classConnectionWrapperImpl
- Throws:
SQLException
- See Also:
-
doClose
Performs the actual close, called once all onClose handlers completed and all tracked objects closed.This default implementation calls
super.close()
- Throws:
SQLException
- See Also:
-
doAbort
Performs the actual abort, called once all onClose handlers completed and all tracking cleared.This default implementation calls
super.abort(executor)
- Throws:
SQLException
- See Also:
-