1 28 29 package com.caucho.sql.spy; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 34 import javax.sql.ConnectionEventListener ; 35 import javax.sql.PooledConnection ; 36 import java.sql.Connection ; 37 import java.sql.SQLException ; 38 import java.util.logging.Logger ; 39 40 43 public class SpyPooledConnection implements javax.sql.PooledConnection { 44 protected final static Logger log = Log.open(SpyPooledConnection.class); 45 protected final static L10N L = new L10N(SpyPooledConnection.class); 46 47 protected int _id; 48 private int _connCount; 49 50 private PooledConnection _pconn; 52 53 56 public SpyPooledConnection(PooledConnection conn, int id) 57 { 58 _pconn = conn; 59 _id = id; 60 } 61 62 public void addConnectionEventListener(ConnectionEventListener listener) 63 { 64 _pconn.addConnectionEventListener(listener); 65 } 66 67 public void removeConnectionEventListener(ConnectionEventListener listener) 68 { 69 _pconn.removeConnectionEventListener(listener); 70 } 71 72 public Connection getConnection() 73 throws SQLException 74 { 75 try { 76 Connection conn = _pconn.getConnection(); 77 78 int connId = _connCount++; 79 80 log.info(_id + ":connect() -> " + connId + ":" + conn); 81 82 return new SpyConnection(conn, connId); 83 } catch (SQLException e) { 84 log.info(_id + ":exn-connect(" + e + ")"); 85 86 throw e; 87 } 88 } 89 90 public void close() 91 throws SQLException 92 { 93 try { 94 _pconn.close(); 95 96 log.info(_id + ":close()"); 97 } catch (SQLException e) { 98 log.info(_id + ":exn-close(" + e + ")"); 99 100 throw e; 101 } 102 } 103 104 public String toString() 105 { 106 return "SpyPooledConnection[id=" + _id + ",conn=" + _pconn + "]"; 107 } 108 } 109 | Popular Tags |