1 28 29 package com.caucho.sql.spy; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 34 import java.sql.Connection ; 35 import java.sql.Driver ; 36 import java.sql.DriverPropertyInfo ; 37 import java.sql.SQLException ; 38 import java.util.Hashtable ; 39 import java.util.Map ; 40 import java.util.Properties ; 41 import java.util.logging.Logger ; 42 43 46 public class SpyDriver implements java.sql.Driver { 47 protected final static Logger log = Log.open(SpyDriver.class); 48 protected final static L10N L = new L10N(SpyDriver.class); 49 50 private static int _staticId; 51 private int _id; 52 private int _connCount; 53 54 private Driver _driver; 56 57 60 public SpyDriver(Driver driver) 61 { 62 _driver = driver; 63 _id = _staticId++; 64 } 65 66 public boolean acceptsURL(String url) 67 throws SQLException 68 { 69 try { 70 boolean result = _driver.acceptsURL(url); 71 72 log.info(_id + ":acceptsURL(" + url + ") -> " + result); 73 74 return result; 75 } catch (SQLException e) { 76 log.info(_id + ":exn-acceptURL(" + e + ")"); 77 78 throw e; 79 } 80 } 81 82 public Connection connect(String url, Properties info) 83 throws SQLException 84 { 85 try { 86 Connection conn = _driver.connect(url, info); 87 88 int connId = _connCount++; 89 90 log.info(_id + ":connect(" + url + ",info=" + info + ") -> " + connId + ":" + conn); 91 92 return new SpyConnection(conn, connId); 93 } catch (SQLException e) { 94 log.info(_id + ":exn-connect(" + e + ")"); 95 96 throw e; 97 } 98 } 99 100 public int getMajorVersion() 101 { 102 int result = _driver.getMajorVersion(); 103 104 log.info(_id + ":getMajorVersion() -> " + result); 105 106 return result; 107 } 108 109 public int getMinorVersion() 110 { 111 int result = _driver.getMinorVersion(); 112 113 log.info(_id + ":getMinorVersion() -> " + result); 114 115 return result; 116 } 117 118 public DriverPropertyInfo []getPropertyInfo(String url, Properties info) 119 throws SQLException 120 { 121 try { 122 DriverPropertyInfo []result = _driver.getPropertyInfo(url, info); 123 124 Hashtable <String ,String > cleanInfo 125 = new Hashtable <String ,String >(); 126 127 if (info != null) { 128 for (Map.Entry <Object ,Object > entry : info.entrySet()) { 129 cleanInfo.put((String ) entry.getKey(), (String ) entry.getValue()); 130 } 131 } 132 133 if (cleanInfo.get("password") != null) 134 cleanInfo.put("password", "****"); 135 136 log.info(_id + ":getPropertyInfo(" + url + ") -> " + result); 137 138 return result; 139 } catch (SQLException e) { 140 log.info(_id + ":exn-getPropertyInfo(" + e + ")"); 141 142 throw e; 143 } 144 } 145 146 public boolean jdbcCompliant() 147 { 148 boolean result = _driver.jdbcCompliant(); 149 150 log.info(_id + ":jdbcCompliant() -> " + result); 151 152 return result; 153 } 154 155 public String toString() 156 { 157 return "SpyDriver[id=" + _id + ",driver=" + _driver + "]"; 158 } 159 } 160 | Popular Tags |