/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.tomcat.jdbc.pool.interceptor;

import java.lang.reflect.Method;

import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
import org.apache.tomcat.jdbc.pool.PooledConnection;
import org.apache.tomcat.jdbc.pool.ProxyConnection;

/**
 * Class that resets the abandoned timer on any activity on the
 * Connection or any successful query executions.
 * This interceptor is useful for when you have a {@link org.apache.tomcat.jdbc.pool.PoolConfiguration#setRemoveAbandonedTimeout(int)}
 * that is fairly low, and you want to reset the abandoned time each time any operation on the connection is performed
 * This is useful for batch processing programs that use connections for extensive amount of times.
 *
 */
public class ResetAbandonedTimer extends AbstractQueryReport {

    public ResetAbandonedTimer() {
    }

    public boolean resetTimer() {
        boolean result = false;
        JdbcInterceptor interceptor = this.getNext();
        while (interceptor!=null && result==false) {
            if (interceptor instanceof ProxyConnection) {
                PooledConnection con = ((ProxyConnection)interceptor).getConnection();
                if (con!=null) {
                    con.setTimestamp(System.currentTimeMillis());
                    result = true;
                } else {
                    break;
                }
            }
            interceptor = interceptor.getNext();
        }
        return result;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = super.invoke(proxy, method, args);
        resetTimer();
        return result;
    }

    @Override
    protected void prepareCall(String query, long time) {
        resetTimer();
    }

    @Override
    protected void prepareStatement(String sql, long time) {
        resetTimer();

    }

    @Override
    public void closeInvoked() {
        resetTimer();
    }

    @Override
    protected String reportQuery(String query, Object[] args, String name,long start, long delta) {
        resetTimer();
        return super.reportQuery(query, args, name, start, delta);
    }

    @Override
    protected String reportSlowQuery(String query, Object[] args, String name,long start, long delta) {
        resetTimer();
        return super.reportSlowQuery(query, args, name, start, delta);
    }
}

@@ -927,31 +927,30 @@
 bc.pool.
-JdbcInterceptor
+ConnectionPool
 ;%0Aimport
@@ -999,60 +999,8 @@
 ion;
-%0Aimport org.apache.tomcat.jdbc.pool.ProxyConnection;
 %0A%0A/*
@@ -1540,16 +1540,52 @@
 port %7B%0A%0A
+    private PooledConnection pcon;%0A%0A
     publ
@@ -1626,174 +1626,192 @@
     
-public boolean resetTimer() %7B%0A        boolean result = false;%0A        JdbcInterceptor interceptor = this.getNext();%0A        while (interceptor!=null && result==fa
+@Override%0A    public void reset(ConnectionPool parent, PooledConnection con) %7B%0A        super.reset(parent, con);%0A        if (con == null) %7B%0A            this.pcon = null;%0A        %7D e
 lse
-)
  %7B%0A 
@@ -1825,53 +1825,24 @@
     
-if (interceptor instanceof ProxyConnection) %7B
+this.pcon = con;
 %0A   
@@ -1850,95 +1850,83 @@
     
+%7D%0A
     
+%7D%0A%0A
     
-PooledConnection con = ((ProxyConnection)interceptor).getConnection();%0A        
+public boolean resetTimer() %7B%0A        boolean result = false;%0A
     
@@ -1937,13 +1937,16 @@
 if (
+p
 con
+ 
 !=
+ 
 null
@@ -1961,24 +1961,17 @@
         
-        
+p
 con.setT
@@ -2020,24 +2020,16 @@
         
-    
-    
 result =
@@ -2039,141 +2039,8 @@
 ue;%0A
-                %7D else %7B%0A                    break;%0A                %7D%0A            %7D%0A            interceptor = interceptor.getNext();%0A
     
@@ -2075,17 +2075,16 @@
 %0A    %7D%0A%0A
-%0A
     @Ove

Simplify the code. Not need to search the JdbcInterceptor chain to get PooledConnection.