1 | /* |
---|
2 | Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
---|
3 | |
---|
4 | |
---|
5 | The MySQL Connector/J is licensed under the terms of the GPLv2 |
---|
6 | <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors. |
---|
7 | There are special exceptions to the terms and conditions of the GPLv2 as it is applied to |
---|
8 | this software, see the FLOSS License Exception |
---|
9 | <http://www.mysql.com/about/legal/licensing/foss-exception.html>. |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify it under the terms |
---|
12 | of the GNU General Public License as published by the Free Software Foundation; version 2 |
---|
13 | of the License. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
---|
16 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
17 | See the GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License along with this |
---|
20 | program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth |
---|
21 | Floor, Boston, MA 02110-1301 USA |
---|
22 | |
---|
23 | */ |
---|
24 | |
---|
25 | package com.mysql.jdbc.jdbc2.optional; |
---|
26 | |
---|
27 | import java.sql.SQLException; |
---|
28 | |
---|
29 | import java.util.HashMap; |
---|
30 | import java.util.Iterator; |
---|
31 | import java.util.Map; |
---|
32 | |
---|
33 | import javax.sql.StatementEvent; |
---|
34 | import javax.sql.StatementEventListener; |
---|
35 | |
---|
36 | import com.mysql.jdbc.ConnectionImpl; |
---|
37 | |
---|
38 | public class JDBC4SuspendableXAConnection extends SuspendableXAConnection { |
---|
39 | |
---|
40 | private Map<StatementEventListener, StatementEventListener> statementEventListeners; |
---|
41 | |
---|
42 | public JDBC4SuspendableXAConnection(ConnectionImpl connection) throws SQLException { |
---|
43 | super(connection); |
---|
44 | |
---|
45 | this.statementEventListeners = new HashMap<StatementEventListener, StatementEventListener>(); |
---|
46 | } |
---|
47 | |
---|
48 | public synchronized void close() throws SQLException { |
---|
49 | super.close(); |
---|
50 | |
---|
51 | if (this.statementEventListeners != null) { |
---|
52 | this.statementEventListeners.clear(); |
---|
53 | |
---|
54 | this.statementEventListeners = null; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | /** |
---|
60 | * Registers a <code>StatementEventListener</code> with this <code>PooledConnection</code> object. Components that |
---|
61 | * wish to be notified when <code>PreparedStatement</code>s created by the |
---|
62 | * connection are closed or are detected to be invalid may use this method |
---|
63 | * to register a <code>StatementEventListener</code> with this <code>PooledConnection</code> object. |
---|
64 | * <p> |
---|
65 | * @param listener an component which implements the <code>StatementEventListener</code> |
---|
66 | * interface that is to be registered with this <code>PooledConnection</code> object |
---|
67 | * <p> |
---|
68 | * @since 1.6 |
---|
69 | */ |
---|
70 | public void addStatementEventListener(StatementEventListener listener) { |
---|
71 | synchronized (this.statementEventListeners) { |
---|
72 | this.statementEventListeners.put(listener, listener); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * Removes the specified <code>StatementEventListener</code> from the list of |
---|
78 | * components that will be notified when the driver detects that a |
---|
79 | * <code>PreparedStatement</code> has been closed or is invalid. |
---|
80 | * <p> |
---|
81 | * @param listener the component which implements the |
---|
82 | * <code>StatementEventListener</code> interface that was previously |
---|
83 | * registered with this <code>PooledConnection</code> object |
---|
84 | * <p> |
---|
85 | * @since 1.6 |
---|
86 | */ |
---|
87 | public void removeStatementEventListener(StatementEventListener listener) { |
---|
88 | synchronized (this.statementEventListeners) { |
---|
89 | this.statementEventListeners.remove(listener); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | void fireStatementEvent(StatementEvent event) throws SQLException { |
---|
94 | synchronized (this.statementEventListeners) { |
---|
95 | for (StatementEventListener listener : this.statementEventListeners.keySet()) { |
---|
96 | listener.statementClosed(event); |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | } |
---|