# 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`

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 the `createStatement(Object, Method, Object[], Object, long)` method.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final Constructor<?>[]`
`constructors`
the constructors that are used to create statement proxies
`protected static final String`
`CREATE_STATEMENT`
`Connection.createStatement()`
`protected static final int`
`CREATE_STATEMENT_IDX`
Index for `CREATE_STATEMENT` in `STATEMENT_TYPES`
`protected static final String`
`EXECUTE`
`Statement.execute(String)`
`protected static final String`
`EXECUTE_BATCH`
`Statement.executeBatch()`
`protected static final String`
`EXECUTE_QUERY`
`Statement.executeQuery(String)`
`protected static final String[]`
`EXECUTE_TYPES`
Array of execute type method names
`protected static final String`
`EXECUTE_UPDATE`
`Statement.executeUpdate(String)`
`protected static final String`
`GET_GENERATED_KEYS`
`Statement.getGeneratedKeys()`
`protected static final String`
`GET_RESULTSET`
`Statement.getResultSet()`
`protected static final String`
`GET_STATEMENT`
`ResultSet.getStatement()`
`protected static final String`
`PREPARE_CALL`
`Connection.prepareCall(String)`
`protected static final int`
`PREPARE_CALL_IDX`
Index for `PREPARE_CALL` in `STATEMENT_TYPES`
`protected static final String`
`PREPARE_STATEMENT`
`Connection.prepareStatement(String)`
`protected static final int`
`PREPARE_STATEMENT_IDX`
Index for `PREPARE_STATEMENT` in `STATEMENT_TYPES`
`protected static final int`
`RESULTSET_IDX`
Index for `GET_STATEMENT` in `STATEMENT_TYPES`
`protected static final int`
`STATEMENT_TYPE_COUNT`
Count of statement types in `STATEMENT_TYPES`
`protected static final String[]`
`STATEMENT_TYPES`
Array of statement type method names

### Fields inherited from class 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

Modifier and Type
Method
Description
`abstract void`
`closeInvoked()`
Method invoked when the operation `Connection.close()` is invoked.
`abstract Object`
`createStatement(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
`Object`
`invoke(Object proxy, Method method, Object[] args)`
Gets invoked each time an operation on `Connection` is invoked.
`protected boolean`
`isExecute(Method method, boolean process)`
Returns true if the method that is being invoked matches one of the execute types.
`protected boolean`
`isStatement(Method method, boolean process)`
Returns true if the method that is being invoked matches one of the statement types.
`protected boolean`
`process(String[] names, Method method, boolean process)`
Returns true if the method that is being invoked matches one of the method names passed in
`void`
`reset(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`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### CREATE_STATEMENT

protected static final String CREATE_STATEMENT
`Connection.createStatement()`

See Also:
  - Constant Field Values

### CREATE_STATEMENT_IDX

protected static final int CREATE_STATEMENT_IDX
Index for `CREATE_STATEMENT` in `STATEMENT_TYPES`

See Also:
  - Constant Field Values

### PREPARE_STATEMENT

protected static final String PREPARE_STATEMENT
`Connection.prepareStatement(String)`

See Also:
  - Constant Field Values

### PREPARE_STATEMENT_IDX

protected static final int PREPARE_STATEMENT_IDX
Index for `PREPARE_STATEMENT` in `STATEMENT_TYPES`

See Also:
  - Constant Field Values

### PREPARE_CALL

protected static final String PREPARE_CALL
`Connection.prepareCall(String)`

See Also:
  - Constant Field Values

### PREPARE_CALL_IDX

protected static final int PREPARE_CALL_IDX
Index for `PREPARE_CALL` in `STATEMENT_TYPES`

See Also:
  - Constant Field Values

### GET_RESULTSET

protected static final String GET_RESULTSET
`Statement.getResultSet()`

See Also:
  - Constant Field Values

### GET_GENERATED_KEYS

protected static final String GET_GENERATED_KEYS
`Statement.getGeneratedKeys()`

See Also:
  - Constant Field Values

### GET_STATEMENT

protected static final String GET_STATEMENT
`ResultSet.getStatement()`

See Also:
  - Constant Field Values

### RESULTSET_IDX

protected static final int RESULTSET_IDX
Index for `GET_STATEMENT` in `STATEMENT_TYPES`

See Also:
  - Constant Field Values

### STATEMENT_TYPES

protected static final String[] STATEMENT_TYPES
Array of statement type method names

### STATEMENT_TYPE_COUNT

protected static final int STATEMENT_TYPE_COUNT
Count of statement types in `STATEMENT_TYPES`

### EXECUTE

protected static final String EXECUTE
`Statement.execute(String)`

See Also:
  - Constant Field Values

### EXECUTE_QUERY

protected static final String EXECUTE_QUERY
`Statement.executeQuery(String)`

See Also:
  - Constant Field Values

### EXECUTE_UPDATE

protected static final String EXECUTE_UPDATE
`Statement.executeUpdate(String)`

See Also:
  - Constant Field Values

### EXECUTE_BATCH

protected static final String EXECUTE_BATCH
`Statement.executeBatch()`

See Also:
  - Constant Field Values

### EXECUTE_TYPES

protected static final String[] EXECUTE_TYPES
Array of execute type method names

### constructors

protected static final Constructor<?>[] constructors
the constructors that are used to create statement proxies

## Constructor Details

### AbstractCreateStatementInterceptor

public AbstractCreateStatementInterceptor()
Default constructor

## Method Details

### invoke

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
Description copied from class: `JdbcInterceptor`
Gets invoked each time an operation on `Connection` is invoked.

Specified by:
  `invoke` in interface `InvocationHandler`
Overrides:
  `invoke` in class `JdbcInterceptor`
Throws:
  `Throwable`

### getConstructor

protected Constructor<?> getConstructor(int idx, Class<?> clazz) throws NoSuchMethodException
Creates a constructor for a proxy class, if one doesn't already exist

Parameters:
  `idx` - - the index of the constructor
  `clazz` - - the interface that the proxy will implement
Returns:
  - returns a constructor used to create new instances
Throws:
  `NoSuchMethodException` - Constructor not found

### 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`, `PreparedStatement` or `CallableStatement`

Parameters:
  `proxy` - the actual proxy object
  `method` - the method that was called. It will be one of the methods defined in `STATEMENT_TYPES`
  `args` - the arguments to the method
  `statement` - the statement that the underlying connection created
  `time` - Elapsed time
Returns:
  a `Statement` object

### closeInvoked

public abstract void closeInvoked()
Method invoked when the operation `Connection.close()` is invoked.

### isStatement

protected boolean isStatement(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 proxy
  `process` - boolean result used for recursion
Returns:
  returns true if the method name matched

### isExecute

protected boolean isExecute(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 proxy
  `process` - boolean result used for recursion
Returns:
  returns true if the method name matched

### process

protected boolean process(String[] names, 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 intercept
  `method` - the method being invoked on the proxy
  `process` - 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:
  `reset` in class `JdbcInterceptor`
Parameters:
  `parent` - - the connection pool owning the connection
  `con` - - the pooled connection