2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2016 - 2017 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 * Licensed to the Apache Software Foundation (ASF) under one or more
23 * contributor license agreements. See the NOTICE file distributed with
24 * this work for additional information regarding copyright ownership.
25 * The ASF licenses this file to You under the Apache License, Version 2.0
26 * (the "License"); you may not use this file except in compliance with
27 * the License. You may obtain a copy of the License at
29 * http://www.apache.org/licenses/LICENSE-2.0
31 * Unless required by applicable law or agreed to in writing, software
32 * distributed under the License is distributed on an "AS IS" BASIS,
33 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34 * See the License for the specific language governing permissions and
35 * limitations under the License.
38 package org.apache.tomcat.jdbc.pool.interceptor;
40 import java.lang.reflect.Method;
42 import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
43 import org.apache.tomcat.jdbc.pool.PooledConnection;
44 import org.apache.tomcat.jdbc.pool.ProxyConnection;
47 * Class that resets the abandoned timer on any activity on the
48 * Connection or any successful query executions.
49 * This interceptor is useful for when you have a {@link org.apache.tomcat.jdbc.pool.PoolConfiguration#setRemoveAbandonedTimeout(int)}
50 * that is fairly low, and you want to reset the abandoned time each time any operation on the connection is performed
51 * This is useful for batch processing programs that use connections for extensive amount of times.
54 public class ResetAbandonedTimer extends AbstractQueryReport {
56 public ResetAbandonedTimer() {
59 public boolean resetTimer() {
60 boolean result = false;
61 JdbcInterceptor interceptor = this.getNext();
62 while (interceptor!=null && result==false) {
63 if (interceptor instanceof ProxyConnection) {
64 PooledConnection con = ((ProxyConnection)interceptor).getConnection();
66 con.setTimestamp(System.currentTimeMillis());
72 interceptor = interceptor.getNext();
79 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
80 Object result = super.invoke(proxy, method, args);
86 protected void prepareCall(String query, long time) {
91 protected void prepareStatement(String sql, long time) {
97 public void closeInvoked() {
102 protected String reportQuery(String query, Object[] args, String name,long start, long delta) {
104 return super.reportQuery(query, args, name, start, delta);
108 protected String reportSlowQuery(String query, Object[] args, String name,long start, long delta) {
110 return super.reportSlowQuery(query, args, name, start, delta);