Class QueryTimeoutInterceptor
- All Implemented Interfaces:
InvocationHandler
Statement.
The timeout is applied by the createStatement hook, which only runs for statement-creation calls that pass
through this interceptor. When combined with StatementCache, this interceptor must therefore be listed
before StatementCache in the
jdbcInterceptors configuration. A
statement cache hit is served by the cache without invoking the rest of the chain, and a statement recycled into the
cache has its query timeout reset to zero, so an interceptor listed after the cache never sees the reuse and the
cached statement executes with no timeout. Listed before the cache, the hook runs for every creation request,
including the ones the cache serves, and the timeout is re-applied to the reused statement.
Whether a configured timeout actually interrupts a query is up to the driver. A driver that refuses
Statement.setQueryTimeout(int) does not stop the statement from being handed out - the pool cannot enforce a
timeout itself, so such a statement runs unbounded - and the refusal is reported once per physical connection rather
than once per statement, so that the log says what is not in effect without repeating itself for every statement
that connection creates.
-
Field Summary
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 TypeMethodDescriptionvoidNo-op; the refusal record belongs to the physical connection, not to the borrow, so ending a borrow has nothing here to clean up.createStatement(Object proxy, Method method, Object[] args, Object statement, long time) Sets the query timeout on the created statement if it is aStatementand the timeout value is positive.voiddisconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) Forgets the reported refusal, as the physical connection this interceptor is attached to is gone: the session that replaces it gets its own refusal recorded and its own warning, the way it gets its own driver to answer the call.voidsetProperties(Map<String, PoolProperties.InterceptorProperty> properties) Initializes thequeryTimeoutproperty from the provided configuration map.Methods inherited from class AbstractCreateStatementInterceptor
getConstructor, invoke, isExecute, isStatement, process, resetModifier 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 invoidreset(ConnectionPool parent, PooledConnection con) no-op for this interceptor. no state is stored.Methods inherited from class JdbcInterceptor
compare, compare, 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.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
-
Constructor Details
-
QueryTimeoutInterceptor
public QueryTimeoutInterceptor()Default constructor.
-
-
Method Details
-
setProperties
Initializes thequeryTimeoutproperty from the provided configuration map. A value that is not an integer is not applied and is warned about: the timeout keeps the value it has - for a fresh instance the one-second default - so a misconfigured pool behaves as the default and the warning says so as the bad value is configured. The pool configures an interceptor instance once at pool start, once per physical connection chain, and once when the pool stops, so the report shares the per-connection reporting volume of the driver refusal below.- Overrides:
setPropertiesin classJdbcInterceptor- Parameters:
properties- map of interceptor properties
-
createStatement
public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) Sets the query timeout on the created statement if it is aStatementand the timeout value is positive.- Specified by:
createStatementin classAbstractCreateStatementInterceptor- Parameters:
proxy- the actual proxy objectmethod- the method that was calledargs- the arguments to the methodstatement- the statement that the underlying connection createdtime- elapsed time in milliseconds- Returns:
- the (possibly wrapped) statement object
-
disconnected
Forgets the reported refusal, as the physical connection this interceptor is attached to is gone: the session that replaces it gets its own refusal recorded and its own warning, the way it gets its own driver to answer the call.- Overrides:
disconnectedin classJdbcInterceptor- Parameters:
parent- - the connection pool that this connection belongs tocon- - the pooled connection that holds this connectionfinalizing- - if this connection is finalizing. True means that the pooled connection will not reconnect the underlying connection
-
closeInvoked
public void closeInvoked()No-op; the refusal record belongs to the physical connection, not to the borrow, so ending a borrow has nothing here to clean up.- Specified by:
closeInvokedin classAbstractCreateStatementInterceptor
-