Class AbstractCreateStatementInterceptor
java.lang.Object
org.apache.tomcat.jdbc.pool.JdbcInterceptor
org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
- All Implemented Interfaces:
InvocationHandler
- Direct Known Subclasses:
AbstractQueryReport, QueryTimeoutInterceptor, StatementDecoratorInterceptor, StatementFacade, StatementFinalizer
Abstraction interceptor. This component intercepts all calls to create some type of SQL statement. By extending this
class, one can intercept queries and update statements by overriding the
createStatement(Object, Method, Object[], Object, long) method.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Constructor<?>[]the constructors that are used to create statement proxies.protected 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 forGET_STATEMENTinSTATEMENT_TYPESprotected 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_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 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 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, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, 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 chainvoidsetProperties(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 propertiesvoidsetUseEquals(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
-
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
-
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 -
constructors
the constructors that are used to create statement proxies. The cache is shared by all subclasses loaded through the same class loader, so every use of an index must pass an interface that the cached proxy implements, in practice always the same one;getConstructor(int, Class)enforces this. The canonical entries are populated by this class's initializer, which the JVM runs once and whose writes it publishes to every thread that uses the class, so reading a slot throughgetConstructor(int, Class)needs no locking; writing an element directly from a subclass bypasses that guarantee and is the subclass's own responsibility.
-
-
Constructor Details
-
AbstractCreateStatementInterceptor
public AbstractCreateStatementInterceptor()Default constructor
-
-
Method Details
-
invoke
Description copied from class:JdbcInterceptorGets invoked each time an operation onConnectionis invoked.- Specified by:
invokein interfaceInvocationHandler- Overrides:
invokein classJdbcInterceptor- Throws:
Throwable
-
getConstructor
Creates a constructor for a proxy class, if one doesn't already exist. The canonical entries are published by this class's initializer, so on the normal path the method only reads a safely published slot and is safe for concurrent use;newInstanceon the returned constructor runs as it always has, outside this method.- 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,PreparedStatementorCallableStatement- 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- Returns:
- a
Statementobject
-
closeInvoked
public abstract void closeInvoked()Method invoked when the operationConnection.close()is invoked. -
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- boolean result used for recursion- 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- boolean result used for recursion- 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- boolean result used for recursion- 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
-