source: Ballon/out/artifacts/geisa_artifact/WEB-INF/lib/mysql-connector-java-5.1.21/src/com/mysql/jdbc/jdbc2/optional/JDBC4MysqlPooledConnection.java

Last change on this file was 766, checked in by npipsl, 11 years ago
File size: 3.9 KB
Line 
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
25package com.mysql.jdbc.jdbc2.optional;
26
27import java.sql.SQLException;
28
29import java.util.HashMap;
30import java.util.Iterator;
31import java.util.Map;
32
33import javax.sql.StatementEvent;
34import javax.sql.StatementEventListener;
35
36
37/**
38 * This class is used to wrap and return a physical connection within a logical
39 * handle. It also registers and notifies ConnectionEventListeners of any
40 * ConnectionEvents
41 *
42 * @see javax.sql.PooledConnection
43 * @see org.gjt.mm.mysql.jdbc2.optional.LogicalHandle
44 * @author Todd Wolff <todd.wolff_at_prodigy.net>
45 */
46public class JDBC4MysqlPooledConnection extends MysqlPooledConnection {
47
48        private Map<StatementEventListener, StatementEventListener> statementEventListeners;
49
50        public JDBC4MysqlPooledConnection(com.mysql.jdbc.Connection connection) {
51                super(connection);
52               
53                this.statementEventListeners = new HashMap<StatementEventListener, StatementEventListener>();
54        }
55       
56        public synchronized void close() throws SQLException {
57                super.close();
58               
59                if (this.statementEventListeners != null) {
60                        this.statementEventListeners.clear();
61                       
62                        this.statementEventListeners = null;
63                }
64        }
65       
66       
67        /**
68         * Registers a <code>StatementEventListener</code> with this <code>PooledConnection</code> object.  Components that
69         * wish to be notified when  <code>PreparedStatement</code>s created by the
70     * connection are closed or are detected to be invalid may use this method
71     * to register a <code>StatementEventListener</code> with this <code>PooledConnection</code> object.
72         * <p>
73         * @param listener      an component which implements the <code>StatementEventListener</code>
74         *                                      interface that is to be registered with this <code>PooledConnection</code> object
75         * <p>
76         * @since 1.6
77         */
78        public void addStatementEventListener(StatementEventListener listener) {
79                synchronized (this.statementEventListeners) {
80                        this.statementEventListeners.put(listener, listener);
81                }
82        }
83       
84        /**
85         * Removes the specified <code>StatementEventListener</code> from the list of
86         * components that will be notified when the driver detects that a
87         * <code>PreparedStatement</code> has been closed or is invalid.
88         * <p>
89         * @param listener      the component which implements the
90         *                                      <code>StatementEventListener</code> interface that was previously
91         *                                      registered with this <code>PooledConnection</code> object
92         * <p>
93         * @since 1.6
94         */
95        public void removeStatementEventListener(StatementEventListener listener) {
96                synchronized (this.statementEventListeners) {
97                        this.statementEventListeners.remove(listener);
98                }
99        }
100       
101        void fireStatementEvent(StatementEvent event) throws SQLException {
102                synchronized (this.statementEventListeners) {
103                        for (StatementEventListener listener : this.statementEventListeners.keySet()) {
104                                listener.statementClosed(event);
105                        }
106                }
107        }
108}
Note: See TracBrowser for help on using the repository browser.