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.ConnectionPoolDataSource ; 35 import javax.sql.PooledConnection ; 36 import java.io.PrintWriter ; 37 import java.sql.SQLException ; 38 import java.util.logging.Logger ; 39 40 43 public class SpyConnectionPoolDataSource implements ConnectionPoolDataSource { 44 protected final static Logger log = Log.open(SpyConnectionPoolDataSource.class); 45 protected final static L10N L = new L10N(SpyConnectionPoolDataSource.class); 46 47 private static int _staticId; 48 private int _id; 49 private int _connCount; 50 51 private ConnectionPoolDataSource _dataSource; 53 54 57 public SpyConnectionPoolDataSource(ConnectionPoolDataSource dataSource) 58 { 59 _dataSource = dataSource; 60 _id = _staticId++; 61 } 62 63 66 public PooledConnection getPooledConnection() 67 throws SQLException 68 { 69 try { 70 PooledConnection conn = _dataSource.getPooledConnection(); 71 72 int connId = _connCount++; 73 74 log.info(_id + ":getConnectionPool() -> " + connId + ":" + conn); 75 76 return new SpyPooledConnection(conn, connId); 77 } catch (SQLException e) { 78 log.info(_id + ":exn-connect(" + e + ")"); 79 80 throw e; 81 } 82 } 83 84 87 public PooledConnection getPooledConnection(String user, String password) 88 throws SQLException 89 { 90 try { 91 PooledConnection conn = _dataSource.getPooledConnection(user, password); 92 93 int connId = _connCount++; 94 95 log.info(_id + ":getPooledConnection(" + user + ") -> " + connId + ":" + conn); 96 97 return new SpyPooledConnection(conn, connId); 98 } catch (SQLException e) { 99 log.info(_id + ":exn-connect(" + e + ")"); 100 101 throw e; 102 } 103 } 104 105 108 public int getLoginTimeout() 109 throws SQLException 110 { 111 return _dataSource.getLoginTimeout(); 112 } 113 114 117 public void setLoginTimeout(int timeout) 118 throws SQLException 119 { 120 _dataSource.setLoginTimeout(timeout); 121 } 122 123 126 public PrintWriter getLogWriter() 127 throws SQLException 128 { 129 return _dataSource.getLogWriter(); 130 } 131 132 135 public void setLogWriter(PrintWriter log) 136 throws SQLException 137 { 138 _dataSource.setLogWriter(log); 139 } 140 141 public String toString() 142 { 143 return "SpyConnectionPoolDataSource[id=" + _id + ",data-source=" + _dataSource + "]"; 144 } 145 } 146 | Popular Tags |