Class AbstractCreateStatementInterceptor
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.JdbcInterceptor
-
- org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
- Direct Known Subclasses:
AbstractQueryReport,QueryTimeoutInterceptor,StatementDecoratorInterceptor,StatementFacade,StatementFinalizer
public abstract class AbstractCreateStatementInterceptor extends JdbcInterceptor
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 thecreateStatement(Object, Method, Object[], Object, long)method.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.reflect.Constructor<?>[]constructorsthe constructors that are used to create statement proxiesprotected static java.lang.StringCREATE_STATEMENTConnection.createStatement()protected static intCREATE_STATEMENT_IDXIndex forCREATE_STATEMENTinSTATEMENT_TYPESprotected static java.lang.StringEXECUTEStatement.execute(java.lang.String)protected static java.lang.StringEXECUTE_BATCHStatement.executeBatch()protected static java.lang.StringEXECUTE_QUERYStatement.executeQuery(java.lang.String)protected static java.lang.String[]EXECUTE_TYPESArray of execute type method namesprotected static java.lang.StringEXECUTE_UPDATEStatement.executeUpdate(java.lang.String)protected static java.lang.StringGET_GENERATED_KEYSStatement.getGeneratedKeys()protected static java.lang.StringGET_RESULTSETStatement.getResultSet()protected static java.lang.StringGET_STATEMENTResultSet.getStatement()protected static java.lang.StringPREPARE_CALLConnection.prepareCall(String)protected static intPREPARE_CALL_IDXIndex forPREPARE_CALLinSTATEMENT_TYPESprotected static java.lang.StringPREPARE_STATEMENTConnection.prepareStatement(String)protected static intPREPARE_STATEMENT_IDXIndex forPREPARE_STATEMENTinSTATEMENT_TYPESprotected static intRESULTSET_IDXIndex forGET_STATEMENTinSTATEMENT_TYPESprotected static intSTATEMENT_TYPE_COUNTCount of statement types inSTATEMENT_TYPESprotected static java.lang.String[]STATEMENT_TYPESArray of statement type method names-
Fields inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor
CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL
-
-
Constructor Summary
Constructors Constructor Description AbstractCreateStatementInterceptor()Default constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidcloseInvoked()Method invoked when the operationConnection.close()is invoked.abstract java.lang.ObjectcreateStatement(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args, java.lang.Object statement, long time)This method will be invoked after a successful statement creation.protected java.lang.reflect.Constructor<?>getConstructor(int idx, java.lang.Class<?> clazz)Creates a constructor for a proxy class, if one doesn't already existjava.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)Gets invoked each time an operation onConnectionis invoked.protected booleanisExecute(java.lang.reflect.Method method, boolean process)Returns true if the method that is being invoked matches one of the execute types.protected booleanisStatement(java.lang.reflect.Method method, boolean process)Returns true if the method that is being invoked matches one of the statement types.protected booleanprocess(java.lang.String[] names, java.lang.reflect.Method method, boolean process)Returns 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 org.apache.tomcat.jdbc.pool.JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEquals
-
-
-
-
Field Detail
-
CREATE_STATEMENT
protected static final java.lang.String CREATE_STATEMENT
Connection.createStatement()- See Also:
- Constant Field Values
-
CREATE_STATEMENT_IDX
protected static final int CREATE_STATEMENT_IDX
Index forCREATE_STATEMENTinSTATEMENT_TYPES- See Also:
- Constant Field Values
-
PREPARE_STATEMENT
protected static final java.lang.String PREPARE_STATEMENT
Connection.prepareStatement(String)- See Also:
- Constant Field Values
-
PREPARE_STATEMENT_IDX
protected static final int PREPARE_STATEMENT_IDX
Index forPREPARE_STATEMENTinSTATEMENT_TYPES- See Also:
- Constant Field Values
-
PREPARE_CALL
protected static final java.lang.String PREPARE_CALL
Connection.prepareCall(String)- See Also:
- Constant Field Values
-
PREPARE_CALL_IDX
protected static final int PREPARE_CALL_IDX
Index forPREPARE_CALLinSTATEMENT_TYPES- See Also:
- Constant Field Values
-
GET_RESULTSET
protected static final java.lang.String GET_RESULTSET
Statement.getResultSet()- See Also:
- Constant Field Values
-
GET_GENERATED_KEYS
protected static final java.lang.String GET_GENERATED_KEYS
Statement.getGeneratedKeys()- See Also:
- Constant Field Values
-
GET_STATEMENT
protected static final java.lang.String GET_STATEMENT
ResultSet.getStatement()- See Also:
- Constant Field Values
-
RESULTSET_IDX
protected static final int RESULTSET_IDX
Index forGET_STATEMENTinSTATEMENT_TYPES- See Also:
- Constant Field Values
-
STATEMENT_TYPES
protected static final java.lang.String[] STATEMENT_TYPES
Array of statement type method names
-
STATEMENT_TYPE_COUNT
protected static final int STATEMENT_TYPE_COUNT
Count of statement types inSTATEMENT_TYPES
-
EXECUTE
protected static final java.lang.String EXECUTE
Statement.execute(java.lang.String)- See Also:
- Constant Field Values
-
EXECUTE_QUERY
protected static final java.lang.String EXECUTE_QUERY
Statement.executeQuery(java.lang.String)- See Also:
- Constant Field Values
-
EXECUTE_UPDATE
protected static final java.lang.String EXECUTE_UPDATE
Statement.executeUpdate(java.lang.String)- See Also:
- Constant Field Values
-
EXECUTE_BATCH
protected static final java.lang.String EXECUTE_BATCH
Statement.executeBatch()- See Also:
- Constant Field Values
-
EXECUTE_TYPES
protected static final java.lang.String[] EXECUTE_TYPES
Array of execute type method names
-
constructors
protected static final java.lang.reflect.Constructor<?>[] constructors
the constructors that are used to create statement proxies
-
-
Method Detail
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.ThrowableDescription copied from class:JdbcInterceptorGets invoked each time an operation onConnectionis invoked.- Specified by:
invokein interfacejava.lang.reflect.InvocationHandler- Overrides:
invokein classJdbcInterceptor- Throws:
java.lang.Throwable
-
getConstructor
protected java.lang.reflect.Constructor<?> getConstructor(int idx, java.lang.Class<?> clazz) throws java.lang.NoSuchMethodExceptionCreates a constructor for a proxy class, if one doesn't already exist- Parameters:
idx- - the index of the constructorclazz- - the interface that the proxy will implement- Returns:
- - returns a constructor used to create new instances
- Throws:
java.lang.NoSuchMethodException- Constructor not found
-
createStatement
public abstract java.lang.Object createStatement(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args, java.lang.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
protected boolean isStatement(java.lang.reflect.Method method, boolean process)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
protected boolean isExecute(java.lang.reflect.Method method, boolean process)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
protected boolean process(java.lang.String[] names, java.lang.reflect.Method method, boolean 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
public void reset(ConnectionPool parent, PooledConnection con)
no-op for this interceptor. no state is stored.- Specified by:
resetin classJdbcInterceptor- Parameters:
parent- - the connection pool owning the connectioncon- - the pooled connection
-
-