Class AbstractCreateStatementInterceptor
- All Implemented Interfaces:
InvocationHandler
- Direct Known Subclasses:
AbstractQueryReport, QueryTimeoutInterceptor, StatementDecoratorInterceptor, StatementFacade, StatementFinalizer
createStatement(Object, Method, Object[], Object, long) method.
Subclass contract. The base intercepts three things on the connection proxy, and a subclass participates in each of them:
- the statement creation path, through
createStatement(Object, Method, Object[], Object, long), which receives the created statement and the monotonic elapsed time and returns what the application will hold; - the close path, through
closeInvoked(), fired on everyConnection.close()before the close reaches the pool, while the connection is still alive; - the borrow-start path: this base holds no per-borrow state and its
reset(ConnectionPool, PooledConnection)is a no-op, so any per-borrow state a subclass keeps must be cleared by the subclass's own reset override - the pool fans out reset, not anything in this class.
Proxy classes come from the constructor cache described at getConstructor(int, Class); each index there is
bound to one interface and a subclass must keep it that way.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final intIndex forCREATE_STATEMENTinSTATEMENT_TYPESprotected 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 intIndex forPREPARE_CALLinSTATEMENT_TYPESprotected static final Stringprotected static final intIndex forPREPARE_STATEMENTinSTATEMENT_TYPESprotected static final intIndex inconstructorsof theResultSetproxy constructor.protected static final intCount of statement types inSTATEMENT_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_VAL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidMethod invoked when the operationConnection.close()is invoked.abstract ObjectcreateStatement(Object proxy, Method method, Object[] args, Object statement, long time) This method will be invoked after a successful statement creation.protected static longelapsedMillis(long startNanos) Measures the milliseconds elapsed since theSystem.nanoTime()reading taken atstartNanos, rounded to the nearest millisecond.protected Constructor<?> getConstructor(int idx, Class<?> clazz) Hands out the proxy constructor cached for this index.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, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEquals, unregisterMBean
-
Field Details
-
CREATE_STATEMENT
-
CREATE_STATEMENT_IDX
protected static final int CREATE_STATEMENT_IDXIndex forCREATE_STATEMENTinSTATEMENT_TYPES- See Also:
-
PREPARE_STATEMENT
-
PREPARE_STATEMENT_IDX
protected static final int PREPARE_STATEMENT_IDXIndex forPREPARE_STATEMENTinSTATEMENT_TYPES- See Also:
-
PREPARE_CALL
-
PREPARE_CALL_IDX
-
GET_RESULTSET
-
GET_GENERATED_KEYS
-
GET_STATEMENT
-
RESULTSET_IDX
protected static final int RESULTSET_IDXIndex inconstructorsof theResultSetproxy constructor. This is not an index intoSTATEMENT_TYPES: the cache carries one slot beyond the statement types, for the result set handles of subclasses that wrap statement-level calls such asStatement.getResultSet()andResultSet.getStatement().- See Also:
-
STATEMENT_TYPES
Array of statement type method names -
STATEMENT_TYPE_COUNT
protected static final int STATEMENT_TYPE_COUNTCount of statement types inSTATEMENT_TYPES -
EXECUTE
-
EXECUTE_QUERY
-
EXECUTE_UPDATE
-
EXECUTE_BATCH
-
EXECUTE_LARGE_UPDATE
Statement.executeLargeUpdate(String)and its overloads, andPreparedStatement.executeLargeUpdate()- See Also:
-
EXECUTE_LARGE_BATCH
-
EXECUTE_TYPES
Array of execute type method names
-
-
Constructor Details
-
AbstractCreateStatementInterceptor
public AbstractCreateStatementInterceptor()Default constructor
-
-
Method Details
-
invoke
Description copied from class:JdbcInterceptorGets invoked each time an operation onConnectionis invoked.The base implementation passes the call to the
nextinterceptor in the chain. When there is no next interceptor, the call fails fast with aNullPointerException: a chain built by the pool always ends in theProxyConnectionterminal, so reaching this case means a chain was hand-built without a terminal link. Interceptors that do not answer a call themselves continue it withsuper.invoke(proxy, method, args).- Specified by:
invokein interfaceInvocationHandler- Overrides:
invokein classJdbcInterceptor- Throws:
Throwable
-
elapsedMillis
protected static long elapsedMillis(long startNanos) Measures the milliseconds elapsed since theSystem.nanoTime()reading taken atstartNanos, rounded to the nearest millisecond.An interval is measured with the monotonic clock. Had it been measured with the wall clock instead, an NTP correction, a manual set, or resuming a suspended VM between the two readings could have made the difference negative, and a negative duration is never over the slow query threshold while the statistics book it as if it were real.
- Parameters:
startNanos- theSystem.nanoTime()reading the measurement began with- Returns:
- the elapsed time in milliseconds
-
getConstructor
Hands out the proxy constructor cached for this index. The method is safe for concurrent use: the only writer of the cache is this class's initializer, whose writes the JVM publishes to every thread that uses the class, so reading a slot needs no locking;newInstanceon the returned constructor runs as it always has, outside this method. If the initializer failed to populate the index, a constructor for the requested interface is computed on demand and returned without being cached, so such calls return equivalent, but not necessarily identical, objects.- Parameters:
idx- - the index of the constructorclazz- - the interface that the proxy will implement- Returns:
- - returns a constructor used to create new instances
- Throws:
NoSuchMethodException- Constructor not foundIllegalStateException- The index is already cached for a proxy class that does not implementclazz. Every use of an index in this shared cache must pass an interface that the cached proxy implements.
-
createStatement
public abstract Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) This 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,PreparedStatementorCallableStatementAn implementation must not make the statement reachable from any other code before it returns, because if this method throws then the statement is closed on a best-effort basis by the interceptor base class before the throwable is propagated to the application.
- Parameters:
proxy- the actual proxy objectmethod- the method that was called. It will be one of the methods defined inSTATEMENT_TYPESargs- the arguments to the methodstatement- the statement that the underlying connection createdtime- elapsed time in milliseconds, measured with the monotonic clock- Returns:
- a
Statementobject
-
closeInvoked
public abstract void closeInvoked()Method invoked when the operationConnection.close()is invoked. It runs before the close is passed down the chain, so that a hook can still reach the connection while it is alive - statements must be closed before the session is handed to the next borrower. Implementation of this method should be thought through with care, as no actions should trigger an exception. An interceptor that nevertheless throws is isolated: the exception is logged and ignored, the remaining interceptors in the chain still receive the close, and the connection is returned to the pool as it would have been. The fatal virtual machine errors the pool never swallows are the exception: those propagate. -
isStatement
Returns true if the method that is being invoked matches one of the statement types.- Parameters:
method- the method being invoked on the proxyprocess- initial accumulator value, passfalse- Returns:
- returns true if the method name matched
-
isExecute
Returns true if the method that is being invoked matches one of the execute types.- Parameters:
method- the method being invoked on the proxyprocess- initial accumulator value, passfalse- Returns:
- returns true if the method name matched
-
process
Returns true if the method that is being invoked matches one of the method names passed in- Parameters:
names- list of method names that we want to interceptmethod- the method being invoked on the proxyprocess- initial accumulator value, passfalse- Returns:
- returns true if the method name matched
-
reset
no-op for this interceptor. no state is stored.- Specified by:
resetin classJdbcInterceptor- Parameters:
parent- - the connection pool owning the connectioncon- - the pooled connection
-