1 28 29 30 package com.caucho.tools.profiler; 31 32 import com.caucho.util.L10N; 33 34 import javax.sql.DataSource ; 35 import java.io.PrintWriter ; 36 import java.sql.Connection ; 37 import java.sql.SQLException ; 38 39 public final class DataSourceWrapper 40 implements DataSource 41 { 42 private static final L10N L = new L10N(DataSourceWrapper.class); 43 44 private final DataSource _dataSource; 45 private final ProfilerPoint _profilerPoint; 46 47 public DataSourceWrapper(ProfilerPoint profilerPoint, DataSource dataSource) 48 { 49 _profilerPoint = profilerPoint; 50 _dataSource = dataSource; 51 } 52 53 private Connection wrap(Connection connection) 54 { 55 return new ConnectionWrapper(_profilerPoint, connection); 56 } 57 58 public Connection getConnection() 59 throws SQLException 60 { 61 return wrap(_dataSource.getConnection()); 62 } 63 64 public Connection getConnection(String username, String password) 65 throws SQLException 66 { 67 return wrap(_dataSource.getConnection(username, password)); 68 } 69 70 public PrintWriter getLogWriter() 71 throws SQLException 72 { 73 Profiler profiler = _profilerPoint.start(); 74 75 try { 76 return _dataSource.getLogWriter(); 77 } 78 finally { 79 profiler.finish(); 80 } 81 } 82 83 public void setLogWriter(PrintWriter out) 84 throws SQLException 85 { 86 Profiler profiler = _profilerPoint.start(); 87 88 try { 89 _dataSource.setLogWriter(out); 90 } 91 finally { 92 profiler.finish(); 93 } 94 } 95 96 public void setLoginTimeout(int seconds) 97 throws SQLException 98 { 99 Profiler profiler = _profilerPoint.start(); 100 101 try { 102 _dataSource.setLoginTimeout(seconds); 103 } 104 finally { 105 profiler.finish(); 106 } 107 } 108 109 public int getLoginTimeout() 110 throws SQLException 111 { 112 Profiler profiler = _profilerPoint.start(); 113 114 try { 115 return _dataSource.getLoginTimeout(); 116 } 117 finally { 118 profiler.finish(); 119 } 120 } 121 122 public String toString() 123 { 124 return "DataSourceWrapper[" + _profilerPoint.getName() + "]"; 125 } 126 } 127 | Popular Tags |