Class StatementFinalizer
- All Implemented Interfaces:
InvocationHandler
Connection.close()
Useful for applications that don't close the associated statements after being done with a connection.
A statement is tracked with a strong reference until it is closed: an application that forgot about a statement is
exactly the case the interceptor exists for, so finalisation must not depend on that statement still being reachable
when the connection is returned. Statements that the application does close are forgotten by the returned proxy at
the moment close() completes, keeping the tracked list bounded by the statements that are genuinely
still open and closed through that handle. (The removal cannot observe a close that reaches the statement by
another route: an interceptor placed outside this one may swallow the statement's close(), e.g. a
statement cache recycling instead of closing, and a statement the application closes through the driver handle
that unwrap hands back never passes through this proxy; such entries are simply reclaimed at the
connection return, where the renewed close meets a statement already closed as a harmless no-op, as they were
before.)
Tracked statements are handed to the application as proxies implementing the standard JDBC statement interfaces, as
is the statement facade the pool always installs in front of this interceptor and as are the proxies of the other
statement-wrapping interceptors; the driver's own statement class is therefore not reachable by casting. The
Wrapper methods are delegated to the driver, and unwrap is the supported way to reach
driver-specific statement methods. A statement the application reaches that way is still tracked here and is closed,
like any other tracked statement, when the connection is returned - unless an interceptor listed after this one
recycles the statement instead of closing it, as a statement cache beneath this interceptor does.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThin proxy around a tracked statement.protected classEntry that tracks a statement and its allocation stack. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<StatementFinalizer.StatementEntry> Statements created on the associated connection that have not been closed yet.protected final ObjectMonitor guardingstatements.Fields inherited from class AbstractCreateStatementInterceptor
constructors, CREATE_STATEMENT, CREATE_STATEMENT_IDX, EXECUTE, EXECUTE_BATCH, EXECUTE_LARGE_BATCH, EXECUTE_LARGE_UPDATE, EXECUTE_QUERY, EXECUTE_TYPES, EXECUTE_UPDATE, GET_GENERATED_KEYS, GET_RESULTSET, GET_STATEMENT, PREPARE_CALL, PREPARE_CALL_IDX, PREPARE_STATEMENT, PREPARE_STATEMENT_IDX, RESULTSET_IDX, STATEMENT_TYPE_COUNT, STATEMENT_TYPESModifier and TypeFieldDescriptionprotected static final Constructor<?>[]the constructors that are used to create statement proxies.protected static final Stringprotected static final intprotected static final Stringprotected static final Stringprotected static final Stringprotected static final StringStatement.executeLargeUpdate(String)and its overloads, andPreparedStatement.executeLargeUpdate()protected static final Stringprotected static final String[]Array of execute type method namesprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final intprotected static final Stringprotected static final intprotected static final intprotected static final intCount of statement types inAbstractCreateStatementInterceptor.STATEMENT_TYPESprotected static final String[]Array of statement type method namesFields inherited from class JdbcInterceptor
ABORT_VAL, CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VALModifier and TypeFieldDescriptionstatic final StringConnection.abort(java.util.concurrent.Executor)method namestatic final StringConnection.close()method namestatic final Stringstatic final StringPooledConnection.getConnection()method namestatic final Stringstatic final StringConnection.isClosed()method namestatic final StringConnection.isValid(int)method namestatic final StringWrapper.isWrapperFor(Class)method nameprotected Map<String, PoolProperties.InterceptorProperty> Properties for this interceptor.static final StringObject.toString()method namestatic final StringWrapper.unwrap(Class)method name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMethod invoked when the operationConnection.close()is invoked.createStatement(Object proxy, Method method, Object[] args, Object statement, long time) This method will be invoked after a successful statement creation.voidreset(ConnectionPool parent, PooledConnection con) no-op for this interceptor. no state is stored.voidsetProperties(Map<String, PoolProperties.InterceptorProperty> properties) Called during the creation of an interceptor The properties can be set during the configuration of an interceptor Override this method to perform type casts between string values and object propertiesMethods inherited from class AbstractCreateStatementInterceptor
getConstructor, invoke, isExecute, isStatement, processModifier and TypeMethodDescriptionprotected Constructor<?> getConstructor(int idx, Class<?> clazz) Creates a constructor for a proxy class, if one doesn't already exist.Gets invoked each time an operation onConnectionis invoked.protected booleanReturns true if the method that is being invoked matches one of the execute types.protected booleanisStatement(Method method, boolean process) Returns true if the method that is being invoked matches one of the statement types.protected booleanReturns true if the method that is being invoked matches one of the method names passed inMethods inherited from class JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setUseEqualsModifier and TypeMethodDescriptionbooleanCompares a method name (String) to a method (Method)JdbcInterceptor.compare(String,String)Uses reference comparison unless the useEquals property is set to truebooleanPerforms a string comparison, using references unless the useEquals property is set to true.voiddisconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) Called whenConnection.close()is called on the underlying connection.getNext()Returns the next interceptor in the chainReturns the properties configured for this interceptorbooleanTrue if the compare method uses the Object.equals(Object) method, false if comparison is done on a reference level.voidpoolClosed(ConnectionPool pool) This method is invoked by a connection pool when the pool is closed.voidpoolStarted(ConnectionPool pool) This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.voidsetNext(JdbcInterceptor next) configures the next interceptor in the chainvoidsetUseEquals(boolean useEquals) Set to true if string comparisons (for theJdbcInterceptor.compare(String, Method)andJdbcInterceptor.compare(String, String)methods) should use the Object.equals(Object) method The default is false
-
Field Details
-
statements
Statements created on the associated connection that have not been closed yet. Every access must be guarded bystatementsLock. -
statementsLock
Monitor guardingstatements. The pool's cleaner thread may clear the list (throughreset(ConnectionPool, PooledConnection)) while a borrower is still creating or closing statements on an abandoned connection, so subclasses that access the list must hold this lock as well.
-
-
Constructor Details
-
StatementFinalizer
public StatementFinalizer()Default constructor.
-
-
Method Details
-
createStatement
public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) Description copied from class:AbstractCreateStatementInterceptorThis method will be invoked after a successful statement creation. This method can choose to return a wrapper around the statement or return the statement itself. If this method returns a wrapper then it should return a wrapper object that implements one of the following interfaces.Statement,PreparedStatementorCallableStatement- Specified by:
createStatementin classAbstractCreateStatementInterceptor- Parameters:
proxy- the actual proxy objectmethod- the method that was called. It will be one of the methods defined inAbstractCreateStatementInterceptor.STATEMENT_TYPESargs- the arguments to the methodstatement- the statement that the underlying connection createdtime- Elapsed time- Returns:
- a
Statementobject
-
closeInvoked
public void closeInvoked()Description copied from class:AbstractCreateStatementInterceptorMethod invoked when the operationConnection.close()is invoked.- Specified by:
closeInvokedin classAbstractCreateStatementInterceptor
-
setProperties
Description copied from class:JdbcInterceptorCalled during the creation of an interceptor The properties can be set during the configuration of an interceptor Override this method to perform type casts between string values and object properties- Overrides:
setPropertiesin classJdbcInterceptor- Parameters:
properties- The properties
-
reset
Description copied from class:AbstractCreateStatementInterceptorno-op for this interceptor. no state is stored.- Overrides:
resetin classAbstractCreateStatementInterceptor- Parameters:
parent- - the connection pool owning the connectioncon- - the pooled connection
-