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.
37 package org.apache.tomcat.jdbc.pool;
39 import java.lang.reflect.Method;
40 import java.lang.reflect.Proxy;
41 import java.sql.SQLException;
44 * A DisposableConnectionFacade object is the top most interceptor that wraps an
45 * object of type {@link PooledConnection}. The ProxyCutOffConnection intercepts
48 * <li>{@link java.sql.Connection#close()} - returns the connection to the
49 * pool then breaks the link between cutoff and the next interceptor.
50 * May be called multiple times.</li>
51 * <li>{@link java.lang.Object#toString()} - returns a custom string for this
54 * By default method comparisons is done on a String reference level, unless the
55 * {@link PoolConfiguration#setUseEquals(boolean)} has been called with a
56 * <code>true</code> argument.
58 public class DisposableConnectionFacade extends JdbcInterceptor {
59 protected DisposableConnectionFacade(JdbcInterceptor interceptor) {
60 setUseEquals(interceptor.isUseEquals());
65 public void reset(ConnectionPool parent, PooledConnection con) {
71 public int hashCode() {
72 return System.identityHashCode(this);
76 public boolean equals(Object obj) {
81 public Object invoke(Object proxy, Method method, Object[] args)
83 if (compare(EQUALS_VAL, method)) {
84 return Boolean.valueOf(
85 this.equals(Proxy.getInvocationHandler(args[0])));
86 } else if (compare(HASHCODE_VAL, method)) {
87 return Integer.valueOf(this.hashCode());
88 } else if (getNext()==null) {
89 if (compare(ISCLOSED_VAL, method)) {
92 else if (compare(CLOSE_VAL, method)) {
95 else if (compare(ISVALID_VAL, method)) {
101 return super.invoke(proxy, method, args);
102 } catch (NullPointerException e) {
103 if (getNext() == null) {
104 if (compare(TOSTRING_VAL, method)) {
105 return "DisposableConnectionFacade[null]";
107 throw new SQLException(
108 "PooledConnection has already been closed.");
113 if (compare(CLOSE_VAL, method)) {