1 23 24 package org.dbforms.conprovider; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import java.sql.CallableStatement ; 30 import java.sql.Connection ; 31 import java.sql.DatabaseMetaData ; 32 import java.sql.PreparedStatement ; 33 import java.sql.SQLException ; 34 import java.sql.SQLWarning ; 35 import java.sql.Statement ; 36 37 import java.util.ArrayList ; 38 import java.util.Iterator ; 39 import java.util.List ; 40 import java.util.Map ; 41 42 43 44 50 public class SingleConnectionWrapper implements Connection { 51 private static Log logCat = LogFactory.getLog(SingleConnectionWrapper.class 52 .getName()); 53 private Connection _conn; 54 private List list = new ArrayList (); 55 private boolean open = true; 56 57 62 public SingleConnectionWrapper(Connection con) { 63 _conn = con; 64 } 65 66 73 public void setAutoCommit(boolean autoCommit) throws SQLException { 74 synchronized (_conn) { 75 _conn.setAutoCommit(autoCommit); 76 } 77 } 78 79 80 87 public boolean getAutoCommit() throws SQLException { 88 synchronized (_conn) { 89 return _conn.getAutoCommit(); 90 } 91 } 92 93 94 101 public void setCatalog(String catalog) throws SQLException { 102 synchronized (_conn) { 103 _conn.setCatalog(catalog); 104 } 105 } 106 107 108 115 public String getCatalog() throws SQLException { 116 synchronized (_conn) { 117 return _conn.getCatalog(); 118 } 119 } 120 121 122 129 public boolean isClosed() throws SQLException { 130 synchronized (_conn) { 131 return !open || _conn.isClosed(); 132 } 133 } 134 135 136 143 public void setHoldability(int holdability) throws SQLException { 144 synchronized (_conn) { 145 _conn.setHoldability(holdability); 146 } 147 } 148 149 150 157 public int getHoldability() throws SQLException { 158 synchronized (_conn) { 159 return _conn.getHoldability(); 160 } 161 } 162 163 164 171 public DatabaseMetaData getMetaData() throws SQLException { 172 synchronized (_conn) { 173 return _conn.getMetaData(); 174 } 175 } 176 177 178 185 public void setReadOnly(boolean readOnly) throws SQLException { 186 synchronized (_conn) { 187 _conn.setReadOnly(readOnly); 188 } 189 } 190 191 192 199 public boolean isReadOnly() throws SQLException { 200 synchronized (_conn) { 201 return _conn.isReadOnly(); 202 } 203 } 204 205 206 213 public java.sql.Savepoint setSavepoint() throws SQLException { 214 synchronized (_conn) { 215 return _conn.setSavepoint(); 216 } 217 } 218 219 220 229 public java.sql.Savepoint setSavepoint(String name) 230 throws SQLException { 231 synchronized (_conn) { 232 return _conn.setSavepoint(name); 233 } 234 } 235 236 237 244 public void setTransactionIsolation(int level) throws SQLException { 245 synchronized (_conn) { 246 _conn.setTransactionIsolation(level); 247 } 248 } 249 250 251 258 public int getTransactionIsolation() throws SQLException { 259 synchronized (_conn) { 260 return _conn.getTransactionIsolation(); 261 } 262 } 263 264 265 272 public void setTypeMap(Map map) throws SQLException { 273 synchronized (_conn) { 274 _conn.setTypeMap(map); 275 } 276 } 277 278 279 286 public Map getTypeMap() throws SQLException { 287 synchronized (_conn) { 288 return _conn.getTypeMap(); 289 } 290 } 291 292 293 300 public SQLWarning getWarnings() throws SQLException { 301 synchronized (_conn) { 302 return _conn.getWarnings(); 303 } 304 } 305 306 307 312 public void clearWarnings() throws SQLException { 313 synchronized (_conn) { 314 _conn.clearWarnings(); 315 } 316 } 317 318 319 322 public void close() throws SQLException { 323 synchronized (_conn) { 324 Iterator iter = list.iterator(); 325 326 while (iter.hasNext()) { 327 Statement stmt = (Statement ) iter.next(); 328 329 try { 330 stmt.close(); 331 } catch (SQLException e) { 332 ; 334 } catch (Exception e) { 335 logCat.error(e); 336 } 337 } 338 339 list.clear(); 340 open = false; 341 } 342 } 343 344 345 350 public void closeReally() throws SQLException { 351 synchronized (_conn) { 352 if (!_conn.isClosed()) { 353 _conn.close(); 354 } 355 } 356 } 357 358 359 364 public void commit() throws SQLException { 365 synchronized (_conn) { 366 _conn.commit(); 367 } 368 } 369 370 371 378 public Statement createStatement() throws SQLException { 379 synchronized (_conn) { 380 Statement res = _conn.createStatement(); 381 list.add(res); 382 383 return res; 384 } 385 } 386 387 388 398 public Statement createStatement(int resultSetType, 399 int resultSetConcurrency) 400 throws SQLException { 401 synchronized (_conn) { 402 Statement res = _conn.createStatement(resultSetType, 403 resultSetConcurrency); 404 list.add(res); 405 406 return res; 407 } 408 } 409 410 411 422 public Statement createStatement(int resultSetType, 423 int resultSetConcurrency, 424 int resultSetHoldability) 425 throws SQLException { 426 synchronized (_conn) { 427 Statement res = _conn.createStatement(resultSetType, 428 resultSetConcurrency, 429 resultSetHoldability); 430 list.add(res); 431 432 return res; 433 } 434 } 435 436 437 446 public String nativeSQL(String sql) throws SQLException { 447 synchronized (_conn) { 448 return _conn.nativeSQL(sql); 449 } 450 } 451 452 453 462 public CallableStatement prepareCall(String sql) throws SQLException { 463 synchronized (_conn) { 464 CallableStatement res = _conn.prepareCall(sql); 465 list.add(res); 466 467 return res; 468 } 469 } 470 471 472 483 public CallableStatement prepareCall(String sql, 484 int resultSetType, 485 int resultSetConcurrency) 486 throws SQLException { 487 synchronized (_conn) { 488 CallableStatement res = _conn.prepareCall(sql, resultSetType, 489 resultSetConcurrency); 490 list.add(res); 491 492 return res; 493 } 494 } 495 496 497 509 public CallableStatement prepareCall(String sql, 510 int resultSetType, 511 int resultSetConcurrency, 512 int resultSetHoldability) 513 throws SQLException { 514 synchronized (_conn) { 515 CallableStatement res = _conn.prepareCall(sql, resultSetType, 516 resultSetConcurrency, 517 resultSetHoldability); 518 list.add(res); 519 520 return res; 521 } 522 } 523 524 525 534 public PreparedStatement prepareStatement(String sql) 535 throws SQLException { 536 synchronized (_conn) { 537 PreparedStatement res = _conn.prepareStatement(sql); 538 list.add(res); 539 540 return res; 541 } 542 } 543 544 545 556 public PreparedStatement prepareStatement(String sql, 557 int resultSetType, 558 int resultSetConcurrency) 559 throws SQLException { 560 synchronized (_conn) { 561 PreparedStatement res = _conn.prepareStatement(sql, resultSetType, 562 resultSetConcurrency); 563 list.add(res); 564 565 return res; 566 } 567 } 568 569 570 582 public PreparedStatement prepareStatement(String sql, 583 int resultSetType, 584 int resultSetConcurrency, 585 int resultSetHoldability) 586 throws SQLException { 587 synchronized (_conn) { 588 PreparedStatement res = _conn.prepareStatement(sql, resultSetType, 589 resultSetConcurrency, 590 resultSetHoldability); 591 list.add(res); 592 593 return res; 594 } 595 } 596 597 598 608 public PreparedStatement prepareStatement(String sql, 609 int autoGeneratedKeys) 610 throws SQLException { 611 synchronized (_conn) { 612 PreparedStatement res = _conn.prepareStatement(sql, autoGeneratedKeys); 613 list.add(res); 614 615 return res; 616 } 617 } 618 619 620 630 public PreparedStatement prepareStatement(String sql, 631 int[] columnIndexes) 632 throws SQLException { 633 synchronized (_conn) { 634 PreparedStatement res = _conn.prepareStatement(sql, columnIndexes); 635 list.add(res); 636 637 return res; 638 } 639 } 640 641 642 652 public PreparedStatement prepareStatement(String sql, 653 String [] columnNames) 654 throws SQLException { 655 synchronized (_conn) { 656 PreparedStatement res = _conn.prepareStatement(sql, columnNames); 657 list.add(res); 658 659 return res; 660 } 661 } 662 663 664 671 public void releaseSavepoint(java.sql.Savepoint savepoint) 672 throws SQLException { 673 synchronized (_conn) { 674 _conn.releaseSavepoint(savepoint); 675 } 676 } 677 678 679 684 public void rollback() throws SQLException { 685 synchronized (_conn) { 686 _conn.rollback(); 687 } 688 } 689 690 691 698 public void rollback(java.sql.Savepoint savepoint) throws SQLException { 699 synchronized (_conn) { 700 _conn.rollback(savepoint); 701 } 702 } 703 } 704 | Popular Tags |