* @version 1.0
*/
public abstract class AbstractCreateStatementInterceptor extends JdbcInterceptor {
- public static final String[] statements = {"createStatement","prepareStatement","prepareCall"};
- public static final String[] executes = {"execute","executeQuery","executeUpdate","executeBatch"};
+ protected static final String CREATE_STATEMENT = "createStatement";
+ protected static final int CREATE_STATEMENT_IDX = 0;
+ protected static final String PREPARE_STATEMENT = "prepareStatement";
+ protected static final int PREPARE_STATEMENT_IDX = 1;
+ protected static final String PREPARE_CALL = "prepareCall";
+ protected static final int PREPARE_IDX = 2;
+
+ protected static final String[] STATEMENT_TYPES = {CREATE_STATEMENT, PREPARE_STATEMENT, PREPARE_CALL};
+ protected static final int STATEMENT_TYPE_COUNT = STATEMENT_TYPES.length;
+
+ protected static final String EXECUTE = "execute";
+ protected static final String EXECUTE_QUERY = "executeQuery";
+ protected static final String EXECUTE_UPDATE = "executeUpdate";
+ protected static final String EXECUTE_BATCH = "executeBatch";
+
+ protected static final String[] EXECUTE_TYPES = {EXECUTE, EXECUTE_QUERY, EXECUTE_UPDATE, EXECUTE_BATCH};
public AbstractCreateStatementInterceptor() {
super();
return super.invoke(proxy, method, args);
} else {
boolean process = false;
- process = process(statements, method, process);
+ process = isStatement(method, process);
if (process) {
long start = System.currentTimeMillis();
Object statement = super.invoke(proxy,method,args);
* If this method returns a wrapper then it should return a wrapper object that implements one of the following interfaces.
* {@link java.sql.Statement}, {@link java.sql.PreparedStatement} or {@link java.sql.CallableStatement}
* @param proxy the actual proxy object
- * @param method the method that was called. It will be one of the methods defined in {@link #statements}
+ * @param method the method that was called. It will be one of the methods defined in {@link #STATEMENT_TYPES}
* @param args the arguments to the method
* @param statement the statement that the underlying connection created
* @return a {@link java.sql.Statement} object
public abstract void closeInvoked();
/**
+ * Returns true if the method that is being invoked matches one of the statement types.
+ *
+ * @param method the method being invoked on the proxy
+ * @param process boolean result used for recursion
+ * @return returns true if the method name matched
+ */
+ protected boolean isStatement(Method method, boolean process){
+ return process(STATEMENT_TYPES, method, process);
+ }
+
+ /**
+ * Returns true if the method that is being invoked matches one of the execute types.
+ *
+ * @param method the method being invoked on the proxy
+ * @param process boolean result used for recursion
+ * @return returns true if the method name matched
+ */
+ protected boolean isExecute(Method method, boolean process){
+ return process(EXECUTE_TYPES, method, process);
+ }
+
+ /*
* Returns true if the method that is being invoked matches one of the method names passed in
* @param names list of method names that we want to intercept
* @param method the method being invoked on the proxy
* the constructors that are used to create statement proxies
*/
protected static final Constructor<?>[] constructors =
- new Constructor[AbstractCreateStatementInterceptor.statements.length];
+ new Constructor[AbstractCreateStatementInterceptor.STATEMENT_TYPE_COUNT];
public AbstractQueryReport() {
//extract the query string
String sql = (query==null && args!=null && args.length>0)?(String)args[0]:query;
//if we do batch execution, then we name the query 'batch'
- if (sql==null && compare(executes[3],name)) {
+ if (sql==null && compare(EXECUTE_BATCH,name)) {
sql = "batch";
}
return sql;
//extract the query string
String sql = (query==null && args!=null && args.length>0)?(String)args[0]:query;
//if we do batch execution, then we name the query 'batch'
- if (sql==null && compare(executes[3],name)) {
+ if (sql==null && compare(EXECUTE_BATCH,name)) {
sql = "batch";
}
return sql;
//extract the query string
String sql = (query==null && args!=null && args.length>0)?(String)args[0]:query;
//if we do batch execution, then we name the query 'batch'
- if (sql==null && compare(executes[3],name)) {
+ if (sql==null && compare(EXECUTE_BATCH,name)) {
sql = "batch";
}
return sql;
String name = method.getName();
String sql = null;
Constructor<?> constructor = null;
- if (compare(statements[0],name)) {
+ if (compare(CREATE_STATEMENT,name)) {
//createStatement
- constructor = getConstructor(0,Statement.class);
- }else if (compare(statements[1],name)) {
+ constructor = getConstructor(CREATE_STATEMENT_IDX,Statement.class);
+ }else if (compare(PREPARE_STATEMENT,name)) {
//prepareStatement
sql = (String)args[0];
- constructor = getConstructor(1,PreparedStatement.class);
+ constructor = getConstructor(PREPARE_STATEMENT_IDX,PreparedStatement.class);
if (sql!=null) {
prepareStatement(sql, time);
}
- }else if (compare(statements[2],name)) {
+ }else if (compare(PREPARE_CALL,name)) {
//prepareCall
sql = (String)args[0];
- constructor = getConstructor(2,CallableStatement.class);
+ constructor = getConstructor(PREPARE_IDX,CallableStatement.class);
prepareCall(sql,time);
}else {
//do nothing, might be a future unsupported method
if (closed) throw new SQLException("Statement closed.");
boolean process = false;
//check to see if we are about to execute a query
- process = process(executes, method, process);
+ process = isExecute( method, process);
//if we are executing, get the current time
long start = (process)?System.currentTimeMillis():0;
Object result = null;