EMMA Coverage Report (generated Wed Jul 26 14:28:59 CDT 2006)
[all classes][com.mysql.jdbc.profiler]

COVERAGE SUMMARY FOR SOURCE FILE [ProfileEventSink.java]

nameclass, %method, %block, %line, %
ProfileEventSink.java100% (1/1)100% (5/5)91%  (60/66)90%  (19/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProfileEventSink100% (1/1)100% (5/5)91%  (60/66)90%  (19/21)
ProfileEventSink (Connection): void 100% (1/1)75%  (18/24)78%  (7/9)
<static initializer> 100% (1/1)100% (5/5)100% (1/1)
consumeEvent (ProfilerEvent): void 100% (1/1)100% (13/13)100% (4/4)
getInstance (Connection): ProfileEventSink 100% (1/1)100% (19/19)100% (5/5)
removeInstance (Connection): void 100% (1/1)100% (5/5)100% (2/2)

1/*
2 Copyright (C) 2002-2004 MySQL AB
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of version 2 of the GNU General Public License as 
6 published by the Free Software Foundation.
7 
8 There are special exceptions to the terms and conditions of the GPL 
9 as it is applied to this software. View the full text of the 
10 exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
11 software distribution.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 
23 
24 */
25package com.mysql.jdbc.profiler;
26 
27import com.mysql.jdbc.Connection;
28import com.mysql.jdbc.log.Log;
29 
30import java.sql.SQLException;
31import java.util.HashMap;
32import java.util.Map;
33 
34/**
35 * @author mmatthew
36 */
37public class ProfileEventSink {
38 
39        private static final Map CONNECTIONS_TO_SINKS = new HashMap();
40 
41        private Connection ownerConnection = null;
42 
43        private Log log = null;
44 
45        /**
46         * Returns the ProfileEventSink that handles profiler events for the given
47         * connection.
48         * 
49         * @param conn
50         *            the connection to handle events for
51         * @return the ProfileEventSink that handles profiler events
52         */
53        public static synchronized ProfileEventSink getInstance(Connection conn) {
54                ProfileEventSink sink = (ProfileEventSink) CONNECTIONS_TO_SINKS
55                                .get(conn);
56 
57                if (sink == null) {
58                        sink = new ProfileEventSink(conn);
59                        CONNECTIONS_TO_SINKS.put(conn, sink);
60                }
61 
62                return sink;
63        }
64 
65        /**
66         * Process a profiler event
67         * 
68         * @param evt
69         *            the event to process
70         */
71        public void consumeEvent(ProfilerEvent evt) {
72                if (evt.eventType == ProfilerEvent.TYPE_WARN) {
73                        this.log.logWarn(evt);
74                } else {
75                        this.log.logInfo(evt);
76                }
77        }
78 
79        public static synchronized void removeInstance(Connection conn) {
80                CONNECTIONS_TO_SINKS.remove(conn);
81        }
82 
83        private ProfileEventSink(Connection conn) {
84                this.ownerConnection = conn;
85 
86                try {
87                        this.log = this.ownerConnection.getLog();
88                } catch (SQLException sqlEx) {
89                        throw new RuntimeException("Unable to get logger from connection");
90                }
91        }
92 
93}

[all classes][com.mysql.jdbc.profiler]
EMMA 2.0.4217 (C) Vladimir Roubtsov