1 /*
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
18 package org.apache.commons.dbcp.managed;
19
20 import java.sql.Connection;
21 import java.sql.SQLException;
22
23 import org.apache.commons.dbcp.AbandonedConfig;
24 import org.apache.commons.dbcp.PoolableConnection;
25 import org.apache.commons.pool.ObjectPool;
26
27 /**
28 * PoolableConnection that unregisters from TransactionRegistry on Connection real destroy.
29 *
30 * @see PoolableConnection
31 * @version $Revision$ $Date$
32 */
33 public class PoolableManagedConnection extends PoolableConnection {
34 private final TransactionRegistry transactionRegistry;
35
36 /**
37 * Create a PoolableManagedConnection.
38 *
39 * @param transactionRegistry transaction registry
40 * @param conn underlying connection
41 * @param pool connection pool
42 * @param config abandoned configuration settings
43 */
44 public PoolableManagedConnection(TransactionRegistry transactionRegistry, Connection conn, ObjectPool pool, AbandonedConfig config) {
45 super(conn, pool, config);
46 this.transactionRegistry = transactionRegistry;
47 }
48
49 /**
50 * Create a PoolableManagedConnection.
51 *
52 * @param transactionRegistry transaction registry
53 * @param conn underlying connection
54 * @param pool connection pool
55 */
56 public PoolableManagedConnection(TransactionRegistry transactionRegistry, Connection conn, ObjectPool pool) {
57 super(conn, pool);
58 this.transactionRegistry = transactionRegistry;
59 }
60
61
62 /**
63 * Actually close the underlying connection.
64 */
65 public void reallyClose() throws SQLException {
66 try {
67 super.reallyClose();
68 } finally {
69 transactionRegistry.unregisterConnection(this);
70 }
71 }
72 }