1 19 package com.mysql.jdbc.jdbc2.optional; 20 21 import java.sql.Connection ; 22 import java.sql.ResultSet ; 23 import java.sql.SQLException ; 24 import java.sql.Savepoint ; 25 import java.sql.Statement ; 26 27 28 50 class ConnectionWrapper extends WrapperBase implements Connection { 51 private Connection mc = null; 52 private MysqlPooledConnection mpc = null; 53 private String invalidHandleStr = "Logical handle no longer valid"; 54 private boolean closed; 55 56 65 public ConnectionWrapper(MysqlPooledConnection mysqlPooledConnection, 66 Connection mysqlConnection) throws SQLException { 67 this.mpc = mysqlPooledConnection; 68 this.mc = mysqlConnection; 69 this.closed = false; 70 this.pooledConnection = this.mpc; 71 } 72 73 79 public void setAutoCommit(boolean autoCommit) throws SQLException { 80 if (closed) { 81 throw new SQLException (invalidHandleStr); 82 } else { 83 try { 84 mc.setAutoCommit(autoCommit); 85 } catch (SQLException sqlException) { 86 checkAndFireConnectionError(sqlException); 87 } 88 } 89 } 90 91 97 public boolean getAutoCommit() throws SQLException { 98 if (closed) { 99 throw new SQLException (invalidHandleStr); 100 } else { 101 try { 102 return mc.getAutoCommit(); 103 } catch (SQLException sqlException) { 104 checkAndFireConnectionError(sqlException); 105 } 106 } 107 108 return false; } 110 111 117 public void setCatalog(String catalog) throws SQLException { 118 if (closed) { 119 throw new SQLException (invalidHandleStr); 120 } else { 121 try { 122 mc.setCatalog(catalog); 123 } catch (SQLException sqlException) { 124 checkAndFireConnectionError(sqlException); 125 } 126 } 127 } 128 129 137 public String getCatalog() throws SQLException { 138 if (closed) { 139 throw new SQLException (invalidHandleStr); 140 } else { 141 try { 142 return mc.getCatalog(); 143 } catch (SQLException sqlException) { 144 checkAndFireConnectionError(sqlException); 145 } 146 } 147 148 return null; } 150 151 157 public boolean isClosed() throws SQLException { 158 return (closed || mc.isClosed()); 159 } 160 161 164 public void setHoldability(int arg0) throws SQLException { 165 if (closed) { 166 throw new SQLException (invalidHandleStr); 167 } else { 168 try { 169 mc.setHoldability(arg0); 170 } catch (SQLException sqlException) { 171 checkAndFireConnectionError(sqlException); 172 } 173 } 174 } 175 176 179 public int getHoldability() throws SQLException { 180 if (closed) { 181 throw new SQLException (invalidHandleStr); 182 } else { 183 try { 184 return mc.getHoldability(); 185 } catch (SQLException sqlException) { 186 checkAndFireConnectionError(sqlException); 187 } 188 } 189 190 return Statement.CLOSE_CURRENT_RESULT; } 192 193 198 public long getIdleFor() { 199 return ((com.mysql.jdbc.Connection) mc).getIdleFor(); 200 } 201 202 210 public java.sql.DatabaseMetaData getMetaData() throws SQLException { 211 if (closed) { 212 throw new SQLException (invalidHandleStr); 213 } else { 214 try { 215 return mc.getMetaData(); 216 } catch (SQLException sqlException) { 217 checkAndFireConnectionError(sqlException); 218 } 219 } 220 221 return null; } 223 224 230 public void setReadOnly(boolean readOnly) throws SQLException { 231 if (closed) { 232 throw new SQLException (invalidHandleStr); 233 } else { 234 try { 235 mc.setReadOnly(readOnly); 236 } catch (SQLException sqlException) { 237 checkAndFireConnectionError(sqlException); 238 } 239 } 240 } 241 242 248 public boolean isReadOnly() throws SQLException { 249 if (closed) { 250 throw new SQLException (invalidHandleStr); 251 } else { 252 try { 253 return mc.isReadOnly(); 254 } catch (SQLException sqlException) { 255 checkAndFireConnectionError(sqlException); 256 } 257 } 258 259 return false; } 261 262 265 public java.sql.Savepoint setSavepoint() throws SQLException { 266 if (closed) { 267 throw new SQLException (invalidHandleStr); 268 } else { 269 try { 270 return mc.setSavepoint(); 271 } catch (SQLException sqlException) { 272 checkAndFireConnectionError(sqlException); 273 } 274 } 275 276 return null; } 278 279 282 public java.sql.Savepoint setSavepoint(String arg0) 283 throws SQLException { 284 if (closed) { 285 throw new SQLException (invalidHandleStr); 286 } else { 287 try { 288 return mc.setSavepoint(arg0); 289 } catch (SQLException sqlException) { 290 checkAndFireConnectionError(sqlException); 291 } 292 } 293 294 return null; } 296 297 303 public void setTransactionIsolation(int level) throws SQLException { 304 if (closed) { 305 throw new SQLException (invalidHandleStr); 306 } else { 307 try { 308 mc.setTransactionIsolation(level); 309 } catch (SQLException sqlException) { 310 checkAndFireConnectionError(sqlException); 311 } 312 } 313 } 314 315 321 public int getTransactionIsolation() throws SQLException { 322 if (closed) { 323 throw new SQLException (invalidHandleStr); 324 } else { 325 try { 326 return mc.getTransactionIsolation(); 327 } catch (SQLException sqlException) { 328 checkAndFireConnectionError(sqlException); 329 } 330 } 331 332 return TRANSACTION_REPEATABLE_READ; } 334 335 341 public void setTypeMap(java.util.Map map) throws SQLException { 342 if (closed) { 343 throw new SQLException (invalidHandleStr); 344 } else { 345 try { 346 mc.setTypeMap(map); 347 } catch (SQLException sqlException) { 348 checkAndFireConnectionError(sqlException); 349 } 350 } 351 } 352 353 359 public java.util.Map getTypeMap() throws SQLException { 360 if (closed) { 361 throw new SQLException (invalidHandleStr); 362 } else { 363 try { 364 return mc.getTypeMap(); 365 } catch (SQLException sqlException) { 366 checkAndFireConnectionError(sqlException); 367 } 368 } 369 370 return null; } 372 373 379 public java.sql.SQLWarning getWarnings() throws SQLException { 380 if (closed) { 381 throw new SQLException (invalidHandleStr); 382 } else { 383 try { 384 return mc.getWarnings(); 385 } catch (SQLException sqlException) { 386 checkAndFireConnectionError(sqlException); 387 } 388 } 389 390 return null; } 392 393 399 public void clearWarnings() throws SQLException { 400 if (closed) { 401 throw new SQLException (invalidHandleStr); 402 } else { 403 try { 404 mc.clearWarnings(); 405 } catch (SQLException sqlException) { 406 checkAndFireConnectionError(sqlException); 407 } 408 } 409 } 410 411 420 public void close() throws SQLException { 421 close(true); 422 } 423 424 430 public void commit() throws SQLException { 431 if (closed) { 432 throw new SQLException (invalidHandleStr); 433 } else { 434 try { 435 mc.commit(); 436 } catch (SQLException sqlException) { 437 checkAndFireConnectionError(sqlException); 438 } 439 } 440 } 441 442 448 public java.sql.Statement createStatement() throws SQLException { 449 if (this.closed) { 450 throw new SQLException (invalidHandleStr); 451 } else { 452 try { 453 return new StatementWrapper(this.mpc, mc.createStatement()); 454 } catch (SQLException sqlException) { 455 checkAndFireConnectionError(sqlException); 456 } 457 } 458 459 return null; } 461 462 468 public java.sql.Statement createStatement(int resultSetType, 469 int resultSetConcurrency) throws SQLException { 470 if (this.closed) { 471 throw new SQLException (invalidHandleStr); 472 } else { 473 try { 474 return new StatementWrapper(this.mpc, mc.createStatement(resultSetType, resultSetConcurrency)); 475 } catch (SQLException sqlException) { 476 checkAndFireConnectionError(sqlException); 477 } 478 } 479 480 return null; } 482 483 486 public java.sql.Statement createStatement(int arg0, int arg1, int arg2) 487 throws SQLException { 488 if (this.closed) { 489 throw new SQLException (invalidHandleStr); 490 } else { 491 try { 492 return new StatementWrapper(this.mpc, mc.createStatement(arg0, arg1, arg2)); 493 } catch (SQLException sqlException) { 494 checkAndFireConnectionError(sqlException); 495 } 496 } 497 498 return null; } 500 501 507 public String nativeSQL(String sql) throws SQLException { 508 if (closed) { 509 throw new SQLException (invalidHandleStr); 510 } else { 511 try { 512 return mc.nativeSQL(sql); 513 } catch (SQLException sqlException) { 514 checkAndFireConnectionError(sqlException); 515 } 516 } 517 518 return null; } 520 521 527 public java.sql.CallableStatement prepareCall(String sql) 528 throws SQLException { 529 if (closed) { 530 throw new SQLException (invalidHandleStr); 531 } else { 532 try { 533 return mc.prepareCall(sql); 534 } catch (SQLException sqlException) { 535 checkAndFireConnectionError(sqlException); 536 } 537 } 538 539 return null; } 541 542 548 public java.sql.CallableStatement prepareCall(String sql, 549 int resultSetType, int resultSetConcurrency) throws SQLException { 550 if (closed) { 551 throw new SQLException (invalidHandleStr); 552 } else { 553 try { 554 return mc.prepareCall(sql, resultSetType, resultSetConcurrency); 555 } catch (SQLException sqlException) { 556 checkAndFireConnectionError(sqlException); 557 } 558 } 559 560 return null; } 562 563 566 public java.sql.CallableStatement prepareCall(String arg0, int arg1, 567 int arg2, int arg3) throws SQLException { 568 if (closed) { 569 throw new SQLException (invalidHandleStr); 570 } else { 571 try { 572 return mc.prepareCall(arg0, arg1, arg2, arg3); 573 } catch (SQLException sqlException) { 574 checkAndFireConnectionError(sqlException); 575 } 576 } 577 578 return null; } 580 581 587 public java.sql.PreparedStatement prepareStatement(String sql) 588 throws SQLException { 589 if (this.closed) { 590 throw new SQLException (invalidHandleStr); 591 } else { 592 try { 593 return new PreparedStatementWrapper(this.mpc, mc.prepareStatement(sql)); 594 } catch (SQLException sqlException) { 595 checkAndFireConnectionError(sqlException); 596 } 597 } 598 599 return null; } 601 602 608 public java.sql.PreparedStatement prepareStatement(String sql, 609 int resultSetType, int resultSetConcurrency) throws SQLException { 610 if (this.closed) { 611 throw new SQLException (invalidHandleStr); 612 } else { 613 try { 614 return new PreparedStatementWrapper(this.mpc, mc.prepareStatement(sql, resultSetType, 615 resultSetConcurrency)); 616 } catch (SQLException sqlException) { 617 checkAndFireConnectionError(sqlException); 618 } 619 } 620 621 return null; } 623 624 627 public java.sql.PreparedStatement prepareStatement(String arg0, int arg1, 628 int arg2, int arg3) throws SQLException { 629 if (this.closed) { 630 throw new SQLException (invalidHandleStr); 631 } else { 632 try { 633 return new PreparedStatementWrapper(this.mpc, mc.prepareStatement(arg0, arg1, arg2, arg3)); 634 } catch (SQLException sqlException) { 635 checkAndFireConnectionError(sqlException); 636 } 637 } 638 639 return null; } 641 642 645 public java.sql.PreparedStatement prepareStatement(String arg0, int arg1) 646 throws SQLException { 647 if (this.closed) { 648 throw new SQLException (invalidHandleStr); 649 } else { 650 try { 651 return new PreparedStatementWrapper(this.mpc, mc.prepareStatement(arg0, arg1)); 652 } catch (SQLException sqlException) { 653 checkAndFireConnectionError(sqlException); 654 } 655 } 656 657 return null; } 659 660 663 public java.sql.PreparedStatement prepareStatement(String arg0, int[] arg1) 664 throws SQLException { 665 if (this.closed) { 666 throw new SQLException (invalidHandleStr); 667 } else { 668 try { 669 return new PreparedStatementWrapper(this.mpc, mc.prepareStatement(arg0, arg1)); 670 } catch (SQLException sqlException) { 671 checkAndFireConnectionError(sqlException); 672 } 673 } 674 675 return null; } 677 678 681 public java.sql.PreparedStatement prepareStatement(String arg0, 682 String [] arg1) throws SQLException { 683 if (this.closed) { 684 throw new SQLException (invalidHandleStr); 685 } else { 686 try { 687 return new PreparedStatementWrapper(this.mpc, mc.prepareStatement(arg0, arg1)); 688 } catch (SQLException sqlException) { 689 checkAndFireConnectionError(sqlException); 690 } 691 } 692 693 return null; } 695 696 699 public void releaseSavepoint(Savepoint arg0) throws SQLException { 700 if (closed) { 701 throw new SQLException (invalidHandleStr); 702 } else { 703 try { 704 mc.releaseSavepoint(arg0); 705 } catch (SQLException sqlException) { 706 checkAndFireConnectionError(sqlException); 707 } 708 } 709 } 710 711 717 public void rollback() throws SQLException { 718 if (closed) { 719 throw new SQLException (invalidHandleStr); 720 } else { 721 try { 722 mc.rollback(); 723 } catch (SQLException sqlException) { 724 checkAndFireConnectionError(sqlException); 725 } 726 } 727 } 728 729 732 public void rollback(Savepoint arg0) throws SQLException { 733 if (closed) { 734 throw new SQLException (invalidHandleStr); 735 } else { 736 try { 737 mc.rollback(arg0); 738 } catch (SQLException sqlException) { 739 checkAndFireConnectionError(sqlException); 740 } 741 } 742 } 743 744 protected void close(boolean fireClosedEvent) 745 throws SQLException { 746 747 synchronized (this.mpc) { 748 if (closed) { 749 return; 750 } 751 752 if (fireClosedEvent) { 753 mpc.callListener(MysqlPooledConnection.CONNECTION_CLOSED_EVENT, null); 754 } 755 756 this.closed = true; 760 } 761 } 762 } 763 | Popular Tags |