| 1 | /* |
| 2 | Copyright (C) 2002-2004 MySQL AB |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of version 2 of the GNU General Public License as |
| 6 | published by the Free Software Foundation. |
| 7 | |
| 8 | There are special exceptions to the terms and conditions of the GPL |
| 9 | as it is applied to this software. View the full text of the |
| 10 | exception in file EXCEPTIONS-CONNECTOR-J in the directory of this |
| 11 | software distribution. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | |
| 22 | |
| 23 | |
| 24 | */ |
| 25 | package com.mysql.jdbc.jdbc2.optional; |
| 26 | |
| 27 | import java.sql.Connection; |
| 28 | import java.sql.SQLException; |
| 29 | import java.sql.Savepoint; |
| 30 | import java.sql.Statement; |
| 31 | |
| 32 | /** |
| 33 | * This class serves as a wrapper for the org.gjt.mm.mysql.jdbc2.Connection |
| 34 | * class. It is returned to the application server which may wrap it again and |
| 35 | * then return it to the application client in response to |
| 36 | * dataSource.getConnection(). |
| 37 | * |
| 38 | * <p> |
| 39 | * All method invocations are forwarded to org.gjt.mm.mysql.jdbc2.Connection |
| 40 | * unless the close method was previously called, in which case a sqlException |
| 41 | * is thrown. The close method performs a 'logical close' on the connection. |
| 42 | * </p> |
| 43 | * |
| 44 | * <p> |
| 45 | * All sqlExceptions thrown by the physical connection are intercepted and sent |
| 46 | * to connectionEvent listeners before being thrown to client. |
| 47 | * </p> |
| 48 | * |
| 49 | * @author Todd Wolff todd.wolff_at_prodigy.net |
| 50 | * |
| 51 | * @see org.gjt.mm.mysql.jdbc2.Connection |
| 52 | * @see org.gjt.mm.mysql.jdbc2.optional.MysqlPooledConnection |
| 53 | */ |
| 54 | public class ConnectionWrapper extends WrapperBase implements Connection { |
| 55 | private com.mysql.jdbc.Connection mc = null; |
| 56 | |
| 57 | private MysqlPooledConnection mpc = null; |
| 58 | |
| 59 | private String invalidHandleStr = "Logical handle no longer valid"; |
| 60 | |
| 61 | private boolean closed; |
| 62 | |
| 63 | /** |
| 64 | * Construct a new LogicalHandle and set instance variables |
| 65 | * |
| 66 | * @param mysqlPooledConnection |
| 67 | * reference to object that instantiated this object |
| 68 | * @param mysqlConnection |
| 69 | * physical connection to db |
| 70 | * |
| 71 | * @throws SQLException |
| 72 | * if an error occurs. |
| 73 | */ |
| 74 | public ConnectionWrapper(MysqlPooledConnection mysqlPooledConnection, |
| 75 | com.mysql.jdbc.Connection mysqlConnection) throws SQLException { |
| 76 | this.mpc = mysqlPooledConnection; |
| 77 | this.mc = mysqlConnection; |
| 78 | this.closed = false; |
| 79 | this.pooledConnection = this.mpc; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Passes call to method on physical connection instance. Notifies listeners |
| 84 | * of any caught exceptions before re-throwing to client. |
| 85 | * |
| 86 | * @see java.sql.Connection#setAutoCommit |
| 87 | */ |
| 88 | public void setAutoCommit(boolean autoCommit) throws SQLException { |
| 89 | checkClosed(); |
| 90 | |
| 91 | try { |
| 92 | this.mc.setAutoCommit(autoCommit); |
| 93 | } catch (SQLException sqlException) { |
| 94 | checkAndFireConnectionError(sqlException); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Passes call to method on physical connection instance. Notifies listeners |
| 100 | * of any caught exceptions before re-throwing to client. |
| 101 | * |
| 102 | * @see java.sql.Connection#getAutoCommit() |
| 103 | */ |
| 104 | public boolean getAutoCommit() throws SQLException { |
| 105 | checkClosed(); |
| 106 | |
| 107 | try { |
| 108 | return this.mc.getAutoCommit(); |
| 109 | } catch (SQLException sqlException) { |
| 110 | checkAndFireConnectionError(sqlException); |
| 111 | } |
| 112 | |
| 113 | return false; // we don't reach this code, compiler can't tell |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Passes call to method on physical connection instance. Notifies listeners |
| 118 | * of any caught exceptions before re-throwing to client. |
| 119 | * |
| 120 | * @see java.sql.Connection#setCatalog() |
| 121 | */ |
| 122 | public void setCatalog(String catalog) throws SQLException { |
| 123 | checkClosed(); |
| 124 | |
| 125 | try { |
| 126 | this.mc.setCatalog(catalog); |
| 127 | } catch (SQLException sqlException) { |
| 128 | checkAndFireConnectionError(sqlException); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Passes call to method on physical connection instance. Notifies listeners |
| 134 | * of any caught exceptions before re-throwing to client. |
| 135 | * |
| 136 | * @return the current catalog |
| 137 | * |
| 138 | * @throws SQLException |
| 139 | * if an error occurs |
| 140 | */ |
| 141 | public String getCatalog() throws SQLException { |
| 142 | checkClosed(); |
| 143 | |
| 144 | try { |
| 145 | return this.mc.getCatalog(); |
| 146 | } catch (SQLException sqlException) { |
| 147 | checkAndFireConnectionError(sqlException); |
| 148 | } |
| 149 | |
| 150 | return null; // we don't reach this code, compiler can't tell |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Passes call to method on physical connection instance. Notifies listeners |
| 155 | * of any caught exceptions before re-throwing to client. |
| 156 | * |
| 157 | * @see java.sql.Connection#isClosed() |
| 158 | */ |
| 159 | public boolean isClosed() throws SQLException { |
| 160 | return (this.closed || this.mc.isClosed()); |
| 161 | } |
| 162 | |
| 163 | public boolean isMasterConnection() throws SQLException { |
| 164 | return this.mc.isMasterConnection(); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @see Connection#setHoldability(int) |
| 169 | */ |
| 170 | public void setHoldability(int arg0) throws SQLException { |
| 171 | checkClosed(); |
| 172 | |
| 173 | try { |
| 174 | this.mc.setHoldability(arg0); |
| 175 | } catch (SQLException sqlException) { |
| 176 | checkAndFireConnectionError(sqlException); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * @see Connection#getHoldability() |
| 182 | */ |
| 183 | public int getHoldability() throws SQLException { |
| 184 | checkClosed(); |
| 185 | |
| 186 | try { |
| 187 | return this.mc.getHoldability(); |
| 188 | } catch (SQLException sqlException) { |
| 189 | checkAndFireConnectionError(sqlException); |
| 190 | } |
| 191 | |
| 192 | return Statement.CLOSE_CURRENT_RESULT; // we don't reach this code, |
| 193 | // compiler can't tell |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Allows clients to determine how long this connection has been idle. |
| 198 | * |
| 199 | * @return how long the connection has been idle. |
| 200 | */ |
| 201 | public long getIdleFor() { |
| 202 | return this.mc.getIdleFor(); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Passes call to method on physical connection instance. Notifies listeners |
| 207 | * of any caught exceptions before re-throwing to client. |
| 208 | * |
| 209 | * @return a metadata instance |
| 210 | * |
| 211 | * @throws SQLException |
| 212 | * if an error occurs |
| 213 | */ |
| 214 | public java.sql.DatabaseMetaData getMetaData() throws SQLException { |
| 215 | checkClosed(); |
| 216 | |
| 217 | try { |
| 218 | return this.mc.getMetaData(); |
| 219 | } catch (SQLException sqlException) { |
| 220 | checkAndFireConnectionError(sqlException); |
| 221 | } |
| 222 | |
| 223 | return null; // we don't reach this code, compiler can't tell |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Passes call to method on physical connection instance. Notifies listeners |
| 228 | * of any caught exceptions before re-throwing to client. |
| 229 | * |
| 230 | * @see java.sql.Connection#setReadOnly() |
| 231 | */ |
| 232 | public void setReadOnly(boolean readOnly) throws SQLException { |
| 233 | checkClosed(); |
| 234 | |
| 235 | try { |
| 236 | this.mc.setReadOnly(readOnly); |
| 237 | } catch (SQLException sqlException) { |
| 238 | checkAndFireConnectionError(sqlException); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Passes call to method on physical connection instance. Notifies listeners |
| 244 | * of any caught exceptions before re-throwing to client. |
| 245 | * |
| 246 | * @see java.sql.Connection#isReadOnly() |
| 247 | */ |
| 248 | public boolean isReadOnly() throws SQLException { |
| 249 | checkClosed(); |
| 250 | |
| 251 | try { |
| 252 | return this.mc.isReadOnly(); |
| 253 | } catch (SQLException sqlException) { |
| 254 | checkAndFireConnectionError(sqlException); |
| 255 | } |
| 256 | |
| 257 | return false; // we don't reach this code, compiler can't tell |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * @see Connection#setSavepoint() |
| 262 | */ |
| 263 | public java.sql.Savepoint setSavepoint() throws SQLException { |
| 264 | checkClosed(); |
| 265 | |
| 266 | try { |
| 267 | return this.mc.setSavepoint(); |
| 268 | } catch (SQLException sqlException) { |
| 269 | checkAndFireConnectionError(sqlException); |
| 270 | } |
| 271 | |
| 272 | return null; // we don't reach this code, compiler can't tell |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * @see Connection#setSavepoint(String) |
| 277 | */ |
| 278 | public java.sql.Savepoint setSavepoint(String arg0) throws SQLException { |
| 279 | checkClosed(); |
| 280 | |
| 281 | try { |
| 282 | return this.mc.setSavepoint(arg0); |
| 283 | } catch (SQLException sqlException) { |
| 284 | checkAndFireConnectionError(sqlException); |
| 285 | } |
| 286 | |
| 287 | return null; // we don't reach this code, compiler can't tell |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Passes call to method on physical connection instance. Notifies listeners |
| 292 | * of any caught exceptions before re-throwing to client. |
| 293 | * |
| 294 | * @see java.sql.Connection#setTransactionIsolation() |
| 295 | */ |
| 296 | public void setTransactionIsolation(int level) throws SQLException { |
| 297 | checkClosed(); |
| 298 | |
| 299 | try { |
| 300 | this.mc.setTransactionIsolation(level); |
| 301 | } catch (SQLException sqlException) { |
| 302 | checkAndFireConnectionError(sqlException); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Passes call to method on physical connection instance. Notifies listeners |
| 308 | * of any caught exceptions before re-throwing to client. |
| 309 | * |
| 310 | * @see java.sql.Connection#getTransactionIsolation() |
| 311 | */ |
| 312 | public int getTransactionIsolation() throws SQLException { |
| 313 | checkClosed(); |
| 314 | |
| 315 | try { |
| 316 | return this.mc.getTransactionIsolation(); |
| 317 | } catch (SQLException sqlException) { |
| 318 | checkAndFireConnectionError(sqlException); |
| 319 | } |
| 320 | |
| 321 | return TRANSACTION_REPEATABLE_READ; // we don't reach this code, |
| 322 | // compiler can't tell |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Passes call to method on physical connection instance. Notifies listeners |
| 327 | * of any caught exceptions before re-throwing to client. |
| 328 | * |
| 329 | * @see java.sql.Connection#setTypeMap() |
| 330 | */ |
| 331 | public void setTypeMap(java.util.Map map) throws SQLException { |
| 332 | checkClosed(); |
| 333 | |
| 334 | try { |
| 335 | this.mc.setTypeMap(map); |
| 336 | } catch (SQLException sqlException) { |
| 337 | checkAndFireConnectionError(sqlException); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Passes call to method on physical connection instance. Notifies listeners |
| 343 | * of any caught exceptions before re-throwing to client. |
| 344 | * |
| 345 | * @see java.sql.Connection#getTypeMap() |
| 346 | */ |
| 347 | public java.util.Map getTypeMap() throws SQLException { |
| 348 | checkClosed(); |
| 349 | |
| 350 | try { |
| 351 | return this.mc.getTypeMap(); |
| 352 | } catch (SQLException sqlException) { |
| 353 | checkAndFireConnectionError(sqlException); |
| 354 | } |
| 355 | |
| 356 | return null; // we don't reach this code, compiler can't tell |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Passes call to method on physical connection instance. Notifies listeners |
| 361 | * of any caught exceptions before re-throwing to client. |
| 362 | * |
| 363 | * @see java.sql.Connection#getWarnings |
| 364 | */ |
| 365 | public java.sql.SQLWarning getWarnings() throws SQLException { |
| 366 | checkClosed(); |
| 367 | |
| 368 | try { |
| 369 | return this.mc.getWarnings(); |
| 370 | } catch (SQLException sqlException) { |
| 371 | checkAndFireConnectionError(sqlException); |
| 372 | } |
| 373 | |
| 374 | return null; // we don't reach this code, compiler can't tell |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Passes call to method on physical connection instance. Notifies listeners |
| 379 | * of any caught exceptions before re-throwing to client. |
| 380 | * |
| 381 | * @throws SQLException |
| 382 | * if an error occurs |
| 383 | */ |
| 384 | public void clearWarnings() throws SQLException { |
| 385 | checkClosed(); |
| 386 | |
| 387 | try { |
| 388 | this.mc.clearWarnings(); |
| 389 | } catch (SQLException sqlException) { |
| 390 | checkAndFireConnectionError(sqlException); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * The physical connection is not actually closed. the physical connection |
| 396 | * is closed when the application server calls |
| 397 | * mysqlPooledConnection.close(). this object is de-referenced by the pooled |
| 398 | * connection each time mysqlPooledConnection.getConnection() is called by |
| 399 | * app server. |
| 400 | * |
| 401 | * @throws SQLException |
| 402 | * if an error occurs |
| 403 | */ |
| 404 | public void close() throws SQLException { |
| 405 | close(true); |
| 406 | } |
| 407 | |
| 408 | /** |
| 409 | * Passes call to method on physical connection instance. Notifies listeners |
| 410 | * of any caught exceptions before re-throwing to client. |
| 411 | * |
| 412 | * @throws SQLException |
| 413 | * if an error occurs |
| 414 | */ |
| 415 | public void commit() throws SQLException { |
| 416 | checkClosed(); |
| 417 | |
| 418 | try { |
| 419 | this.mc.commit(); |
| 420 | } catch (SQLException sqlException) { |
| 421 | checkAndFireConnectionError(sqlException); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Passes call to method on physical connection instance. Notifies listeners |
| 427 | * of any caught exceptions before re-throwing to client. |
| 428 | * |
| 429 | * @see java.sql.Connection#createStatement() |
| 430 | */ |
| 431 | public java.sql.Statement createStatement() throws SQLException { |
| 432 | checkClosed(); |
| 433 | |
| 434 | try { |
| 435 | return new StatementWrapper(this, this.mpc, this.mc |
| 436 | .createStatement()); |
| 437 | } catch (SQLException sqlException) { |
| 438 | checkAndFireConnectionError(sqlException); |
| 439 | } |
| 440 | |
| 441 | return null; // we don't reach this code, compiler can't tell |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Passes call to method on physical connection instance. Notifies listeners |
| 446 | * of any caught exceptions before re-throwing to client. |
| 447 | * |
| 448 | * @see java.sql.Connection#createStatement() |
| 449 | */ |
| 450 | public java.sql.Statement createStatement(int resultSetType, |
| 451 | int resultSetConcurrency) throws SQLException { |
| 452 | checkClosed(); |
| 453 | |
| 454 | try { |
| 455 | return new StatementWrapper(this, this.mpc, this.mc |
| 456 | .createStatement(resultSetType, resultSetConcurrency)); |
| 457 | } catch (SQLException sqlException) { |
| 458 | checkAndFireConnectionError(sqlException); |
| 459 | } |
| 460 | |
| 461 | return null; // we don't reach this code, compiler can't tell |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * @see Connection#createStatement(int, int, int) |
| 466 | */ |
| 467 | public java.sql.Statement createStatement(int arg0, int arg1, int arg2) |
| 468 | throws SQLException { |
| 469 | checkClosed(); |
| 470 | |
| 471 | try { |
| 472 | return new StatementWrapper(this, this.mpc, this.mc |
| 473 | .createStatement(arg0, arg1, arg2)); |
| 474 | } catch (SQLException sqlException) { |
| 475 | checkAndFireConnectionError(sqlException); |
| 476 | } |
| 477 | |
| 478 | return null; // we don't reach this code, compiler can't tell |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Passes call to method on physical connection instance. Notifies listeners |
| 483 | * of any caught exceptions before re-throwing to client. |
| 484 | * |
| 485 | * @see java.sql.Connection#nativeSQL() |
| 486 | */ |
| 487 | public String nativeSQL(String sql) throws SQLException { |
| 488 | checkClosed(); |
| 489 | |
| 490 | try { |
| 491 | return this.mc.nativeSQL(sql); |
| 492 | } catch (SQLException sqlException) { |
| 493 | checkAndFireConnectionError(sqlException); |
| 494 | } |
| 495 | |
| 496 | return null; // we don't reach this code, compiler can't tell |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * Passes call to method on physical connection instance. Notifies listeners |
| 501 | * of any caught exceptions before re-throwing to client. |
| 502 | * |
| 503 | * @see java.sql.Connection#prepareCall() |
| 504 | */ |
| 505 | public java.sql.CallableStatement prepareCall(String sql) |
| 506 | throws SQLException { |
| 507 | checkClosed(); |
| 508 | |
| 509 | try { |
| 510 | return new CallableStatementWrapper(this, this.mpc, this.mc |
| 511 | .prepareCall(sql)); |
| 512 | } catch (SQLException sqlException) { |
| 513 | checkAndFireConnectionError(sqlException); |
| 514 | } |
| 515 | |
| 516 | return null; // we don't reach this code, compiler can't tell |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Passes call to method on physical connection instance. Notifies listeners |
| 521 | * of any caught exceptions before re-throwing to client. |
| 522 | * |
| 523 | * @see java.sql.Connection#prepareCall() |
| 524 | */ |
| 525 | public java.sql.CallableStatement prepareCall(String sql, |
| 526 | int resultSetType, int resultSetConcurrency) throws SQLException { |
| 527 | checkClosed(); |
| 528 | |
| 529 | try { |
| 530 | return new CallableStatementWrapper(this, this.mpc, this.mc |
| 531 | .prepareCall(sql, resultSetType, resultSetConcurrency)); |
| 532 | } catch (SQLException sqlException) { |
| 533 | checkAndFireConnectionError(sqlException); |
| 534 | } |
| 535 | |
| 536 | return null; // we don't reach this code, compiler can't tell |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * @see Connection#prepareCall(String, int, int, int) |
| 541 | */ |
| 542 | public java.sql.CallableStatement prepareCall(String arg0, int arg1, |
| 543 | int arg2, int arg3) throws SQLException { |
| 544 | checkClosed(); |
| 545 | |
| 546 | try { |
| 547 | return new CallableStatementWrapper(this, this.mpc, this.mc |
| 548 | .prepareCall(arg0, arg1, arg2, arg3)); |
| 549 | } catch (SQLException sqlException) { |
| 550 | checkAndFireConnectionError(sqlException); |
| 551 | } |
| 552 | |
| 553 | return null; // we don't reach this code, compiler can't tell |
| 554 | } |
| 555 | |
| 556 | public java.sql.PreparedStatement clientPrepare(String sql) throws SQLException |
| 557 | { |
| 558 | checkClosed(); |
| 559 | |
| 560 | try { |
| 561 | return new PreparedStatementWrapper(this, this.mpc, |
| 562 | this.mc.clientPrepareStatement(sql)); |
| 563 | } catch (SQLException sqlException) { |
| 564 | checkAndFireConnectionError(sqlException); |
| 565 | } |
| 566 | |
| 567 | return null; |
| 568 | } |
| 569 | |
| 570 | public java.sql.PreparedStatement clientPrepare(String sql, |
| 571 | int resultSetType, int resultSetConcurrency) throws SQLException |
| 572 | { |
| 573 | checkClosed(); |
| 574 | |
| 575 | try { |
| 576 | return new PreparedStatementWrapper(this, this.mpc, |
| 577 | this.mc.clientPrepareStatement(sql, |
| 578 | resultSetType, resultSetConcurrency)); |
| 579 | } catch (SQLException sqlException) { |
| 580 | checkAndFireConnectionError(sqlException); |
| 581 | } |
| 582 | |
| 583 | return null; |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * Passes call to method on physical connection instance. Notifies listeners |
| 588 | * of any caught exceptions before re-throwing to client. |
| 589 | * |
| 590 | * @see java.sql.Connection#prepareStatement() |
| 591 | */ |
| 592 | public java.sql.PreparedStatement prepareStatement(String sql) |
| 593 | throws SQLException { |
| 594 | checkClosed(); |
| 595 | |
| 596 | try { |
| 597 | return new PreparedStatementWrapper(this, this.mpc, this.mc |
| 598 | .prepareStatement(sql)); |
| 599 | } catch (SQLException sqlException) { |
| 600 | checkAndFireConnectionError(sqlException); |
| 601 | } |
| 602 | |
| 603 | return null; // we don't reach this code, compiler can't tell |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * Passes call to method on physical connection instance. Notifies listeners |
| 608 | * of any caught exceptions before re-throwing to client. |
| 609 | * |
| 610 | * @see java.sql.Connection#prepareStatement() |
| 611 | */ |
| 612 | public java.sql.PreparedStatement prepareStatement(String sql, |
| 613 | int resultSetType, int resultSetConcurrency) throws SQLException { |
| 614 | checkClosed(); |
| 615 | |
| 616 | try { |
| 617 | return new PreparedStatementWrapper(this, this.mpc, this.mc |
| 618 | .prepareStatement(sql, resultSetType, resultSetConcurrency)); |
| 619 | } catch (SQLException sqlException) { |
| 620 | checkAndFireConnectionError(sqlException); |
| 621 | } |
| 622 | |
| 623 | return null; // we don't reach this code, compiler can't tell |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * @see Connection#prepareStatement(String, int, int, int) |
| 628 | */ |
| 629 | public java.sql.PreparedStatement prepareStatement(String arg0, int arg1, |
| 630 | int arg2, int arg3) throws SQLException { |
| 631 | checkClosed(); |
| 632 | |
| 633 | try { |
| 634 | return new PreparedStatementWrapper(this, this.mpc, this.mc |
| 635 | .prepareStatement(arg0, arg1, arg2, arg3)); |
| 636 | } catch (SQLException sqlException) { |
| 637 | checkAndFireConnectionError(sqlException); |
| 638 | } |
| 639 | |
| 640 | return null; // we don't reach this code, compiler can't tell |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * @see Connection#prepareStatement(String, int) |
| 645 | */ |
| 646 | public java.sql.PreparedStatement prepareStatement(String arg0, int arg1) |
| 647 | throws SQLException { |
| 648 | checkClosed(); |
| 649 | |
| 650 | try { |
| 651 | return new PreparedStatementWrapper(this, this.mpc, this.mc |
| 652 | .prepareStatement(arg0, arg1)); |
| 653 | } catch (SQLException sqlException) { |
| 654 | checkAndFireConnectionError(sqlException); |
| 655 | } |
| 656 | |
| 657 | return null; // we don't reach this code, compiler can't tell |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * @see Connection#prepareStatement(String, int[]) |
| 662 | */ |
| 663 | public java.sql.PreparedStatement prepareStatement(String arg0, int[] arg1) |
| 664 | throws SQLException { |
| 665 | checkClosed(); |
| 666 | |
| 667 | try { |
| 668 | return new PreparedStatementWrapper(this, this.mpc, this.mc |
| 669 | .prepareStatement(arg0, arg1)); |
| 670 | } catch (SQLException sqlException) { |
| 671 | checkAndFireConnectionError(sqlException); |
| 672 | } |
| 673 | |
| 674 | return null; // we don't reach this code, compiler can't tell |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * @see Connection#prepareStatement(String, String[]) |
| 679 | */ |
| 680 | public java.sql.PreparedStatement prepareStatement(String arg0, |
| 681 | String[] arg1) throws SQLException { |
| 682 | checkClosed(); |
| 683 | |
| 684 | try { |
| 685 | return new PreparedStatementWrapper(this, this.mpc, this.mc |
| 686 | .prepareStatement(arg0, arg1)); |
| 687 | } catch (SQLException sqlException) { |
| 688 | checkAndFireConnectionError(sqlException); |
| 689 | } |
| 690 | |
| 691 | return null; // we don't reach this code, compiler can't tell |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * @see Connection#releaseSavepoint(Savepoint) |
| 696 | */ |
| 697 | public void releaseSavepoint(Savepoint arg0) throws SQLException { |
| 698 | checkClosed(); |
| 699 | |
| 700 | try { |
| 701 | this.mc.releaseSavepoint(arg0); |
| 702 | } catch (SQLException sqlException) { |
| 703 | checkAndFireConnectionError(sqlException); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Passes call to method on physical connection instance. Notifies listeners |
| 709 | * of any caught exceptions before re-throwing to client. |
| 710 | * |
| 711 | * @see java.sql.Connection#rollback() |
| 712 | */ |
| 713 | public void rollback() throws SQLException { |
| 714 | checkClosed(); |
| 715 | |
| 716 | try { |
| 717 | this.mc.rollback(); |
| 718 | } catch (SQLException sqlException) { |
| 719 | checkAndFireConnectionError(sqlException); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * @see Connection#rollback(Savepoint) |
| 725 | */ |
| 726 | public void rollback(Savepoint arg0) throws SQLException { |
| 727 | checkClosed(); |
| 728 | |
| 729 | try { |
| 730 | this.mc.rollback(arg0); |
| 731 | } catch (SQLException sqlException) { |
| 732 | checkAndFireConnectionError(sqlException); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | protected void close(boolean fireClosedEvent) throws SQLException { |
| 737 | synchronized (this.mpc) { |
| 738 | if (this.closed) { |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | if (this.mc.getRollbackOnPooledClose() |
| 743 | && !this.getAutoCommit()) { |
| 744 | rollback(); |
| 745 | } |
| 746 | |
| 747 | if (fireClosedEvent) { |
| 748 | this.mpc.callListener( |
| 749 | MysqlPooledConnection.CONNECTION_CLOSED_EVENT, null); |
| 750 | } |
| 751 | |
| 752 | // set closed status to true so that if application client tries to |
| 753 | // make additional |
| 754 | // calls a sqlException will be thrown. The physical connection is |
| 755 | // re-used by the pooled connection each time getConnection is |
| 756 | // called. |
| 757 | this.closed = true; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | private void checkClosed() throws SQLException { |
| 762 | if (this.closed) { |
| 763 | throw new SQLException(this.invalidHandleStr); |
| 764 | } |
| 765 | } |
| 766 | } |