1 package com.github.davidmoten.rx.jdbc; 2 3 import java.sql.Array; 4 import java.sql.Blob; 5 import java.sql.CallableStatement; 6 import java.sql.Clob; 7 import java.sql.Connection; 8 import java.sql.DatabaseMetaData; 9 import java.sql.NClob; 10 import java.sql.PreparedStatement; 11 import java.sql.SQLClientInfoException; 12 import java.sql.SQLException; 13 import java.sql.SQLWarning; 14 import java.sql.SQLXML; 15 import java.sql.Savepoint; 16 import java.sql.Statement; 17 import java.sql.Struct; 18 import java.util.Map; 19 import java.util.Properties; 20 import java.util.concurrent.CountDownLatch; 21 import java.util.concurrent.Executor; 22 23 public class CountingConnection implements Connection { 24 25 private final Connection con; 26 27 private final CountDownLatch closesLatch; 28 29 public CountingConnection(Connection con, CountDownLatch closesLatch) { 30 this.con = con; 31 this.closesLatch = closesLatch; 32 } 33 34 @Override 35 public <T> T unwrap(Class<T> iface) throws SQLException { 36 return con.unwrap(iface); 37 } 38 39 @Override 40 public boolean isWrapperFor(Class<?> iface) throws SQLException { 41 return con.isWrapperFor(iface); 42 } 43 44 @Override 45 public Statement createStatement() throws SQLException { 46 return con.createStatement(); 47 } 48 49 @Override 50 public PreparedStatement prepareStatement(String sql) throws SQLException { 51 return con.prepareStatement(sql); 52 } 53 54 @Override 55 public CallableStatement prepareCall(String sql) throws SQLException { 56 return con.prepareCall(sql); 57 } 58 59 @Override 60 public String nativeSQL(String sql) throws SQLException { 61 return con.nativeSQL(sql); 62 } 63 64 @Override 65 public void setAutoCommit(boolean autoCommit) throws SQLException { 66 con.setAutoCommit(autoCommit); 67 } 68 69 @Override 70 public boolean getAutoCommit() throws SQLException { 71 return con.getAutoCommit(); 72 } 73 74 @Override 75 public void commit() throws SQLException { 76 con.commit(); 77 } 78 79 @Override 80 public void rollback() throws SQLException { 81 con.rollback(); 82 } 83 84 @Override 85 public void close() throws SQLException { 86 con.close(); 87 closesLatch.countDown(); 88 } 89 90 @Override 91 public boolean isClosed() throws SQLException { 92 return con.isClosed(); 93 } 94 95 @Override 96 public DatabaseMetaData getMetaData() throws SQLException { 97 return con.getMetaData(); 98 } 99 100 @Override 101 public void setReadOnly(boolean readOnly) throws SQLException { 102 con.setReadOnly(readOnly); 103 } 104 105 @Override 106 public boolean isReadOnly() throws SQLException { 107 return con.isReadOnly(); 108 } 109 110 @Override 111 public void setCatalog(String catalog) throws SQLException { 112 con.setCatalog(catalog); 113 } 114 115 @Override 116 public String getCatalog() throws SQLException { 117 return con.getCatalog(); 118 } 119 120 @Override 121 public void setTransactionIsolation(int level) throws SQLException { 122 con.setTransactionIsolation(level); 123 } 124 125 @Override 126 public int getTransactionIsolation() throws SQLException { 127 return con.getTransactionIsolation(); 128 } 129 130 @Override 131 public SQLWarning getWarnings() throws SQLException { 132 return con.getWarnings(); 133 } 134 135 @Override 136 public void clearWarnings() throws SQLException { 137 con.clearWarnings(); 138 } 139 140 @Override 141 public Statement createStatement(int resultSetType, int resultSetConcurrency) 142 throws SQLException { 143 return con.createStatement(resultSetType, resultSetConcurrency); 144 } 145 146 @Override 147 public PreparedStatement prepareStatement(String sql, int resultSetType, 148 int resultSetConcurrency) throws SQLException { 149 return con.prepareStatement(sql, resultSetType, resultSetConcurrency); 150 } 151 152 @Override 153 public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) 154 throws SQLException { 155 return con.prepareCall(sql, resultSetType, resultSetConcurrency); 156 } 157 158 @Override 159 public Map<String, Class<?>> getTypeMap() throws SQLException { 160 return con.getTypeMap(); 161 } 162 163 @Override 164 public void setTypeMap(Map<String, Class<?>> map) throws SQLException { 165 con.setTypeMap(map); 166 } 167 168 @Override 169 public void setHoldability(int holdability) throws SQLException { 170 con.setHoldability(holdability); 171 } 172 173 @Override 174 public int getHoldability() throws SQLException { 175 return con.getHoldability(); 176 } 177 178 @Override 179 public Savepoint setSavepoint() throws SQLException { 180 return con.setSavepoint(); 181 } 182 183 @Override 184 public Savepoint setSavepoint(String name) throws SQLException { 185 return con.setSavepoint(name); 186 } 187 188 @Override 189 public void rollback(Savepoint savepoint) throws SQLException { 190 con.rollback(savepoint); 191 } 192 193 @Override 194 public void releaseSavepoint(Savepoint savepoint) throws SQLException { 195 con.releaseSavepoint(savepoint); 196 } 197 198 @Override 199 public Statement createStatement(int resultSetType, int resultSetConcurrency, 200 int resultSetHoldability) throws SQLException { 201 return con.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); 202 } 203 204 @Override 205 public PreparedStatement prepareStatement(String sql, int resultSetType, 206 int resultSetConcurrency, int resultSetHoldability) throws SQLException { 207 return con.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 208 } 209 210 @Override 211 public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, 212 int resultSetHoldability) throws SQLException { 213 return con.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 214 } 215 216 @Override 217 public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) 218 throws SQLException { 219 return con.prepareStatement(sql, autoGeneratedKeys); 220 } 221 222 @Override 223 public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { 224 return con.prepareStatement(sql, columnIndexes); 225 } 226 227 @Override 228 public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { 229 return con.prepareStatement(sql, columnNames); 230 } 231 232 @Override 233 public Clob createClob() throws SQLException { 234 return con.createClob(); 235 } 236 237 @Override 238 public Blob createBlob() throws SQLException { 239 return con.createBlob(); 240 } 241 242 @Override 243 public NClob createNClob() throws SQLException { 244 return con.createNClob(); 245 } 246 247 @Override 248 public SQLXML createSQLXML() throws SQLException { 249 return con.createSQLXML(); 250 } 251 252 @Override 253 public boolean isValid(int timeout) throws SQLException { 254 return con.isValid(timeout); 255 } 256 257 @Override 258 public void setClientInfo(String name, String value) throws SQLClientInfoException { 259 con.setClientInfo(name, value); 260 } 261 262 @Override 263 public void setClientInfo(Properties properties) throws SQLClientInfoException { 264 con.setClientInfo(properties); 265 } 266 267 @Override 268 public String getClientInfo(String name) throws SQLException { 269 return con.getClientInfo(name); 270 } 271 272 @Override 273 public Properties getClientInfo() throws SQLException { 274 return con.getClientInfo(); 275 } 276 277 @Override 278 public Array createArrayOf(String typeName, Object[] elements) throws SQLException { 279 return con.createArrayOf(typeName, elements); 280 } 281 282 @Override 283 public Struct createStruct(String typeName, Object[] attributes) throws SQLException { 284 return con.createStruct(typeName, attributes); 285 } 286 287 @Override 288 public void setSchema(String schema) throws SQLException { 289 con.setSchema(schema); 290 } 291 292 @Override 293 public String getSchema() throws SQLException { 294 return con.getSchema(); 295 } 296 297 @Override 298 public void abort(Executor executor) throws SQLException { 299 con.abort(executor); 300 } 301 302 @Override 303 public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { 304 con.setNetworkTimeout(executor, milliseconds); 305 } 306 307 @Override 308 public int getNetworkTimeout() throws SQLException { 309 return con.getNetworkTimeout(); 310 } 311 }