2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.tomcat.jdbc.pool.interceptor;
19 import java.lang.reflect.Method;
21 import org.apache.tomcat.jdbc.pool.ConnectionPool;
22 import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
23 import org.apache.tomcat.jdbc.pool.PooledConnection;
29 public abstract class AbstractCreateStatementInterceptor extends JdbcInterceptor {
30 public static final String[] statements = {"createStatement","prepareStatement","prepareCall"};
31 public static final String[] executes = {"execute","executeQuery","executeUpdate","executeBatch"};
33 public AbstractCreateStatementInterceptor() {
38 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
39 if (compare(CLOSE_VAL,method)) {
41 return super.invoke(proxy, method, args);
43 boolean process = false;
44 process = process(statements, method, process);
46 long start = System.currentTimeMillis();
47 Object statement = super.invoke(proxy,method,args);
48 long delta = System.currentTimeMillis() - start;
49 return createStatement(proxy,method,args,statement, delta);
51 return super.invoke(proxy,method,args);
57 * This method should return a wrapper object around a
58 * {@link java.sql.Statement}, {@link java.sql.PreparedStatement} or {@link java.sql.CallableStatement}
63 * @return a {@link java.sql.Statement} object
65 public abstract Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time);
67 public abstract void closeInvoked();
69 protected boolean process(String[] names, Method method, boolean process) {
70 final String name = method.getName();
71 for (int i=0; (!process) && i<names.length; i++) {
72 process = compare(names[i],name);
77 public void reset(ConnectionPool parent, PooledConnection con) {