1 16 17 package org.apache.commons.dbcp.cpdsadapter; 18 19 import java.util.Map ; 20 import java.sql.Connection ; 21 import java.sql.DatabaseMetaData ; 22 import java.sql.PreparedStatement ; 23 import java.sql.CallableStatement ; 24 import java.sql.Statement ; 25 import java.sql.SQLWarning ; 26 import java.sql.SQLException ; 27 28 40 class ConnectionImpl implements Connection { 41 private static final String CLOSED 42 = "Attempted to use Connection after closed() was called."; 43 44 45 private Connection connection; 46 47 48 private PooledConnectionImpl pooledConnection; 49 50 51 boolean isClosed; 52 53 59 ConnectionImpl(PooledConnectionImpl pooledConnection, 60 Connection connection) { 61 this.pooledConnection = pooledConnection; 62 this.connection = connection; 63 isClosed = false; 64 } 65 66 69 protected void finalize() throws Throwable { 70 if (!isClosed) { 71 throw new SQLException ("A ConnectionImpl was finalized " 76 + "without being closed which will cause leakage of " 77 + " PooledConnections from the ConnectionPool."); 78 } 79 } 80 81 84 private void assertOpen() throws SQLException { 85 if (isClosed) { 86 throw new SQLException (CLOSED); 87 } 88 } 89 90 94 100 public void clearWarnings() throws SQLException { 101 assertOpen(); 102 connection.clearWarnings(); 103 } 104 105 114 public void close() throws SQLException { 115 assertOpen(); 116 isClosed = true; 117 pooledConnection.notifyListeners(); 118 } 119 120 126 public void commit() throws SQLException { 127 assertOpen(); 128 connection.commit(); 129 } 130 131 137 public Statement createStatement() throws SQLException { 138 assertOpen(); 139 return connection.createStatement(); 140 } 141 142 148 public Statement createStatement(int resultSetType, 149 int resultSetConcurrency) 150 throws SQLException { 151 assertOpen(); 152 return connection 153 .createStatement(resultSetType, resultSetConcurrency); 154 } 155 156 162 public boolean getAutoCommit() throws SQLException { 163 assertOpen(); 164 return connection.getAutoCommit(); 165 } 166 167 173 public String getCatalog() throws SQLException { 174 assertOpen(); 175 return connection.getCatalog(); 176 } 177 178 184 public DatabaseMetaData getMetaData() throws SQLException { 185 assertOpen(); 186 return connection.getMetaData(); 187 } 188 189 195 public int getTransactionIsolation() throws SQLException { 196 assertOpen(); 197 return connection.getTransactionIsolation(); 198 } 199 200 206 public Map getTypeMap() throws SQLException { 207 assertOpen(); 208 return connection.getTypeMap(); 209 } 210 211 217 public SQLWarning getWarnings() throws SQLException { 218 assertOpen(); 219 return connection.getWarnings(); 220 } 221 222 227 public boolean isClosed() { 228 return isClosed; 229 } 230 231 237 public boolean isReadOnly() throws SQLException { 238 assertOpen(); 239 return connection.isReadOnly(); 240 } 241 242 248 public String nativeSQL(String sql) throws SQLException { 249 assertOpen(); 250 return connection.nativeSQL(sql); 251 } 252 253 259 public CallableStatement prepareCall(String sql) throws SQLException { 260 assertOpen(); 261 return connection.prepareCall(sql); 262 } 263 264 270 public CallableStatement prepareCall(String sql, int resultSetType, 271 int resultSetConcurrency) 272 throws SQLException { 273 assertOpen(); 274 return connection.prepareCall(sql, resultSetType, resultSetConcurrency); 275 } 276 277 285 public PreparedStatement prepareStatement(String sql) throws SQLException { 286 assertOpen(); 287 return pooledConnection.prepareStatement(sql); 288 } 289 290 298 public PreparedStatement prepareStatement(String sql, int resultSetType, 299 int resultSetConcurrency) 300 throws SQLException { 301 assertOpen(); 302 return pooledConnection 303 .prepareStatement(sql, resultSetType, resultSetConcurrency); 304 } 305 306 312 public void rollback() throws SQLException { 313 assertOpen(); 314 connection.rollback(); 315 } 316 317 323 public void setAutoCommit(boolean b) throws SQLException { 324 assertOpen(); 325 connection.setAutoCommit(b); 326 } 327 328 334 public void setCatalog(String catalog) throws SQLException { 335 assertOpen(); 336 connection.setCatalog(catalog); 337 } 338 339 345 public void setReadOnly(boolean readOnly) throws SQLException { 346 assertOpen(); 347 connection.setReadOnly(readOnly); 348 } 349 350 356 public void setTransactionIsolation(int level) throws SQLException { 357 assertOpen(); 358 connection.setTransactionIsolation(level); 359 } 360 361 367 public void setTypeMap(Map map) throws SQLException { 368 assertOpen(); 369 connection.setTypeMap(map); 370 } 371 372 375 376 377 public int getHoldability() throws SQLException { 378 assertOpen(); 379 return connection.getHoldability(); 380 } 381 382 public void setHoldability(int holdability) throws SQLException { 383 assertOpen(); 384 connection.setHoldability(holdability); 385 } 386 387 public java.sql.Savepoint setSavepoint() throws SQLException { 388 assertOpen(); 389 return connection.setSavepoint(); 390 } 391 392 public java.sql.Savepoint setSavepoint(String name) throws SQLException { 393 assertOpen(); 394 return connection.setSavepoint(name); 395 } 396 397 public void rollback(java.sql.Savepoint savepoint) throws SQLException { 398 assertOpen(); 399 connection.rollback(savepoint); 400 } 401 402 public void releaseSavepoint(java.sql.Savepoint savepoint) 403 throws SQLException { 404 assertOpen(); 405 connection.releaseSavepoint(savepoint); 406 } 407 408 public Statement createStatement(int resultSetType, 409 int resultSetConcurrency, 410 int resultSetHoldability) 411 throws SQLException { 412 assertOpen(); 413 return connection.createStatement(resultSetType, resultSetConcurrency, 414 resultSetHoldability); 415 } 416 417 public PreparedStatement prepareStatement(String sql, int resultSetType, 418 int resultSetConcurrency, 419 int resultSetHoldability) 420 throws SQLException { 421 assertOpen(); 422 return connection.prepareStatement(sql, resultSetType, 423 resultSetConcurrency, 424 resultSetHoldability); 425 } 426 427 public CallableStatement prepareCall(String sql, int resultSetType, 428 int resultSetConcurrency, 429 int resultSetHoldability) 430 throws SQLException { 431 assertOpen(); 432 return connection.prepareCall(sql, resultSetType, 433 resultSetConcurrency, 434 resultSetHoldability); 435 } 436 437 public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) 438 throws SQLException { 439 assertOpen(); 440 return connection.prepareStatement(sql, autoGeneratedKeys); 441 } 442 443 public PreparedStatement prepareStatement(String sql, int columnIndexes[]) 444 throws SQLException { 445 assertOpen(); 446 return connection.prepareStatement(sql, columnIndexes); 447 } 448 449 public PreparedStatement prepareStatement(String sql, String columnNames[]) 450 throws SQLException { 451 assertOpen(); 452 return connection.prepareStatement(sql, columnNames); 453 } 454 455 456 } 457 | Popular Tags |