01: package net.sourceforge.squirrel_sql.jdbcproxy;
02:
03: import java.sql.SQLException;
04: import java.util.HashMap;
05: import java.util.Iterator;
06: import java.util.Properties;
07:
08: /*
09: * Copyright (C) 2006 Rob Manning
10: * manningr@users.sourceforge.net
11: *
12: * This library is free software; you can redistribute it and/or
13: * modify it under the terms of the GNU Lesser General Public
14: * License as published by the Free Software Foundation; either
15: * version 2.1 of the License, or (at your option) any later version.
16: *
17: * This library is distributed in the hope that it will be useful,
18: * but WITHOUT ANY WARRANTY; without even the implied warranty of
19: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20: * Lesser General Public License for more details.
21: *
22: * You should have received a copy of the GNU Lesser General Public
23: * License along with this library; if not, write to the Free Software
24: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25: */
26:
27: public class ProxyMethodManager {
28:
29: private static Properties _props = null;
30:
31: private static HashMap<String, Long> methodsCalled = new HashMap<String, Long>();
32:
33: public static void setDriverProperties(Properties props) {
34: _props = props;
35: }
36:
37: public static void check(String className, String methodName)
38: throws SQLException {
39: String key = className + "." + methodName;
40: if (methodsCalled.containsKey(key)) {
41: Long count = methodsCalled.get(key);
42: methodsCalled.put(key, Long.valueOf(count.longValue() + 1));
43: } else {
44: methodsCalled.put(key, Long.valueOf(1));
45: }
46: if (_props.containsKey(key)) {
47: String info = (String) _props.get(key);
48: if (info != null && !"".equals(info)) {
49: throw new SQLException(info);
50: }
51: }
52: }
53:
54: public static void printMethodsCalled() {
55: if (trackMethods()) {
56: for (Iterator<String> iter = methodsCalled.keySet()
57: .iterator(); iter.hasNext();) {
58: String key = iter.next();
59: Long count = methodsCalled.get(key);
60: System.out.println(key + " -> " + count.longValue());
61: }
62: }
63: }
64:
65: private static boolean trackMethods() {
66: boolean result = false;
67: String key = ProxyDriver.TRACK_METHOD_CALLS_KEY;
68: if (_props.containsKey(key)) {
69: String info = (String) _props.get(key);
70: if (info != null && "true".equalsIgnoreCase(info)) {
71: result = true;
72: }
73: }
74: return result;
75: }
76: }
|