1 19 package com.mysql.jdbc.jdbc2.optional; 20 21 import com.mysql.jdbc.SQLError; 22 23 import java.sql.Connection ; 24 import java.sql.ResultSet ; 25 import java.sql.SQLException ; 26 import java.sql.SQLWarning ; 27 import java.sql.Statement ; 28 29 30 38 class StatementWrapper extends WrapperBase implements Statement { 39 protected Statement wrappedStmt; 40 41 protected StatementWrapper(MysqlPooledConnection conn, Statement toWrap) { 42 this.pooledConnection = conn; 43 this.wrappedStmt = toWrap; 44 } 45 46 49 public Connection getConnection() throws SQLException { 50 try { 51 if (this.wrappedStmt != null) { 52 return this.wrappedStmt.getConnection(); 53 } else { 54 throw new SQLException ("Statement already closed", 55 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 56 } 57 } catch (SQLException sqlEx) { 58 checkAndFireConnectionError(sqlEx); 59 } 60 61 return null; 63 } 65 66 69 public void setCursorName(String name) throws SQLException { 70 try { 71 if (this.wrappedStmt != null) { 72 this.wrappedStmt.setCursorName(name); 73 } else { 74 throw new SQLException ("Statement already closed", 75 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 76 } 77 } catch (SQLException sqlEx) { 78 checkAndFireConnectionError(sqlEx); 79 } 80 } 81 82 85 public void setEscapeProcessing(boolean enable) throws SQLException { 86 try { 87 if (this.wrappedStmt != null) { 88 this.wrappedStmt.setEscapeProcessing(enable); 89 } else { 90 throw new SQLException ("Statement already closed", 91 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 92 } 93 } catch (SQLException sqlEx) { 94 checkAndFireConnectionError(sqlEx); 95 } 96 } 97 98 101 public void setFetchDirection(int direction) throws SQLException { 102 try { 103 if (this.wrappedStmt != null) { 104 this.wrappedStmt.setFetchDirection(direction); 105 } else { 106 throw new SQLException ("Statement already closed", 107 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 108 } 109 } catch (SQLException sqlEx) { 110 checkAndFireConnectionError(sqlEx); 111 } 112 } 113 114 117 public int getFetchDirection() throws SQLException { 118 try { 119 if (this.wrappedStmt != null) { 120 return this.wrappedStmt.getFetchDirection(); 121 } else { 122 throw new SQLException ("Statement already closed", 123 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 124 } 125 } catch (SQLException sqlEx) { 126 checkAndFireConnectionError(sqlEx); 127 } 128 129 return ResultSet.FETCH_FORWARD; 131 } 133 134 137 public void setFetchSize(int rows) throws SQLException { 138 try { 139 if (this.wrappedStmt != null) { 140 this.wrappedStmt.setFetchSize(rows); 141 } else { 142 throw new SQLException ("Statement already closed", 143 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 144 } 145 } catch (SQLException sqlEx) { 146 checkAndFireConnectionError(sqlEx); 147 } 148 } 149 150 153 public int getFetchSize() throws SQLException { 154 try { 155 if (this.wrappedStmt != null) { 156 return this.wrappedStmt.getFetchSize(); 157 } else { 158 throw new SQLException ("Statement already closed", 159 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 160 } 161 } catch (SQLException sqlEx) { 162 checkAndFireConnectionError(sqlEx); 163 } 164 165 return 0; 167 } 169 170 173 public ResultSet getGeneratedKeys() throws SQLException { 174 try { 175 if (this.wrappedStmt != null) { 176 return this.wrappedStmt.getGeneratedKeys(); 177 } else { 178 throw new SQLException ("Statement already closed", 179 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 180 } 181 } catch (SQLException sqlEx) { 182 checkAndFireConnectionError(sqlEx); 183 } 184 185 return null; 187 } 189 190 193 public void setMaxFieldSize(int max) throws SQLException { 194 try { 195 if (this.wrappedStmt != null) { 196 this.wrappedStmt.setMaxFieldSize(max); 197 } else { 198 throw new SQLException ("Statement already closed", 199 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 200 } 201 } catch (SQLException sqlEx) { 202 checkAndFireConnectionError(sqlEx); 203 } 204 } 205 206 209 public int getMaxFieldSize() throws SQLException { 210 try { 211 if (this.wrappedStmt != null) { 212 return this.wrappedStmt.getMaxFieldSize(); 213 } else { 214 throw new SQLException ("Statement already closed", 215 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 216 } 217 } catch (SQLException sqlEx) { 218 checkAndFireConnectionError(sqlEx); 219 } 220 221 return 0; 223 } 225 226 229 public void setMaxRows(int max) throws SQLException { 230 try { 231 if (this.wrappedStmt != null) { 232 this.wrappedStmt.setMaxRows(max); 233 } else { 234 throw new SQLException ("Statement already closed", 235 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 236 } 237 } catch (SQLException sqlEx) { 238 checkAndFireConnectionError(sqlEx); 239 } 240 } 241 242 245 public int getMaxRows() throws SQLException { 246 try { 247 if (this.wrappedStmt != null) { 248 return this.wrappedStmt.getMaxRows(); 249 } else { 250 throw new SQLException ("Statement already closed", 251 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 252 } 253 } catch (SQLException sqlEx) { 254 checkAndFireConnectionError(sqlEx); 255 } 256 257 return 0; 259 } 261 262 265 public boolean getMoreResults() throws SQLException { 266 try { 267 if (this.wrappedStmt != null) { 268 return this.wrappedStmt.getMoreResults(); 269 } else { 270 throw new SQLException ("Statement already closed", 271 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 272 } 273 } catch (SQLException sqlEx) { 274 checkAndFireConnectionError(sqlEx); 275 } 276 277 return false; 278 } 279 280 283 public boolean getMoreResults(int current) throws SQLException { 284 try { 285 if (this.wrappedStmt != null) { 286 return this.wrappedStmt.getMoreResults(current); 287 } else { 288 throw new SQLException ("Statement already closed", 289 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 290 } 291 } catch (SQLException sqlEx) { 292 checkAndFireConnectionError(sqlEx); 293 } 294 295 return false; 296 } 297 298 301 public void setQueryTimeout(int seconds) throws SQLException { 302 try { 303 if (this.wrappedStmt != null) { 304 this.wrappedStmt.setQueryTimeout(seconds); 305 } else { 306 throw new SQLException ("Statement already closed", 307 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 308 } 309 } catch (SQLException sqlEx) { 310 checkAndFireConnectionError(sqlEx); 311 } 312 } 313 314 317 public int getQueryTimeout() throws SQLException { 318 try { 319 if (this.wrappedStmt != null) { 320 return this.wrappedStmt.getQueryTimeout(); 321 } else { 322 throw new SQLException ("Statement already closed", 323 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 324 } 325 } catch (SQLException sqlEx) { 326 checkAndFireConnectionError(sqlEx); 327 } 328 329 return 0; 330 } 331 332 335 public ResultSet getResultSet() throws SQLException { 336 try { 337 if (this.wrappedStmt != null) { 338 return this.wrappedStmt.getResultSet(); 339 } else { 340 throw new SQLException ("Statement already closed", 341 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 342 } 343 } catch (SQLException sqlEx) { 344 checkAndFireConnectionError(sqlEx); 345 } 346 347 return null; 348 } 349 350 353 public int getResultSetConcurrency() throws SQLException { 354 try { 355 if (this.wrappedStmt != null) { 356 return this.wrappedStmt.getResultSetConcurrency(); 357 } else { 358 throw new SQLException ("Statement already closed", 359 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 360 } 361 } catch (SQLException sqlEx) { 362 checkAndFireConnectionError(sqlEx); 363 } 364 365 return 0; 366 } 367 368 371 public int getResultSetHoldability() throws SQLException { 372 try { 373 if (this.wrappedStmt != null) { 374 return this.wrappedStmt.getResultSetHoldability(); 375 } else { 376 throw new SQLException ("Statement already closed", 377 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 378 } 379 } catch (SQLException sqlEx) { 380 checkAndFireConnectionError(sqlEx); 381 } 382 383 return Statement.CLOSE_CURRENT_RESULT; 384 } 385 386 389 public int getResultSetType() throws SQLException { 390 try { 391 if (this.wrappedStmt != null) { 392 return this.wrappedStmt.getResultSetType(); 393 } else { 394 throw new SQLException ("Statement already closed", 395 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 396 } 397 } catch (SQLException sqlEx) { 398 checkAndFireConnectionError(sqlEx); 399 } 400 401 return ResultSet.TYPE_FORWARD_ONLY; 402 } 403 404 407 public int getUpdateCount() throws SQLException { 408 try { 409 if (this.wrappedStmt != null) { 410 return this.wrappedStmt.getUpdateCount(); 411 } else { 412 throw new SQLException ("Statement already closed", 413 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 414 } 415 } catch (SQLException sqlEx) { 416 checkAndFireConnectionError(sqlEx); 417 } 418 419 return -1; 420 } 421 422 425 public SQLWarning getWarnings() throws SQLException { 426 try { 427 if (this.wrappedStmt != null) { 428 return this.wrappedStmt.getWarnings(); 429 } else { 430 throw new SQLException ("Statement already closed", 431 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 432 } 433 } catch (SQLException sqlEx) { 434 checkAndFireConnectionError(sqlEx); 435 } 436 437 return null; 438 } 439 440 443 public void addBatch(String sql) throws SQLException { 444 try { 445 if (this.wrappedStmt != null) { 446 this.wrappedStmt.addBatch(sql); 447 } 448 } catch (SQLException sqlEx) { 449 checkAndFireConnectionError(sqlEx); 450 } 451 } 452 453 456 public void cancel() throws SQLException { 457 try { 458 if (this.wrappedStmt != null) { 459 this.wrappedStmt.cancel(); 460 } 461 } catch (SQLException sqlEx) { 462 checkAndFireConnectionError(sqlEx); 463 } 464 } 465 466 469 public void clearBatch() throws SQLException { 470 try { 471 if (this.wrappedStmt != null) { 472 this.wrappedStmt.clearBatch(); 473 } 474 } catch (SQLException sqlEx) { 475 checkAndFireConnectionError(sqlEx); 476 } 477 } 478 479 482 public void clearWarnings() throws SQLException { 483 try { 484 if (this.wrappedStmt != null) { 485 this.wrappedStmt.clearWarnings(); 486 } 487 } catch (SQLException sqlEx) { 488 checkAndFireConnectionError(sqlEx); 489 } 490 } 491 492 495 public void close() throws SQLException { 496 try { 497 if (this.wrappedStmt != null) { 498 this.wrappedStmt.close(); 499 } 500 } catch (SQLException sqlEx) { 501 checkAndFireConnectionError(sqlEx); 502 } finally { 503 this.wrappedStmt = null; 504 this.pooledConnection = null; 505 } 506 } 507 508 511 public boolean execute(String sql, int autoGeneratedKeys) 512 throws SQLException { 513 try { 514 if (this.wrappedStmt != null) { 515 return this.wrappedStmt.execute(sql, autoGeneratedKeys); 516 } else { 517 throw new SQLException ("Statement already closed", 518 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 519 } 520 } catch (SQLException sqlEx) { 521 checkAndFireConnectionError(sqlEx); 522 } 523 524 return false; 526 } 528 529 532 public boolean execute(String sql, int[] columnIndexes) 533 throws SQLException { 534 try { 535 if (this.wrappedStmt != null) { 536 return this.wrappedStmt.execute(sql, columnIndexes); 537 } else { 538 throw new SQLException ("Statement already closed", 539 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 540 } 541 } catch (SQLException sqlEx) { 542 checkAndFireConnectionError(sqlEx); 543 } 544 545 return false; 547 } 549 550 553 public boolean execute(String sql, String [] columnNames) 554 throws SQLException { 555 try { 556 if (this.wrappedStmt != null) { 557 return this.wrappedStmt.execute(sql, columnNames); 558 } else { 559 throw new SQLException ("Statement already closed", 560 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 561 } 562 } catch (SQLException sqlEx) { 563 checkAndFireConnectionError(sqlEx); 564 } 565 566 return false; 568 } 570 571 574 public boolean execute(String sql) throws SQLException { 575 try { 576 if (this.wrappedStmt != null) { 577 return this.wrappedStmt.execute(sql); 578 } else { 579 throw new SQLException ("Statement already closed", 580 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 581 } 582 } catch (SQLException sqlEx) { 583 checkAndFireConnectionError(sqlEx); 584 } 585 586 return false; 588 } 590 591 594 public int[] executeBatch() throws SQLException { 595 try { 596 if (this.wrappedStmt != null) { 597 return this.wrappedStmt.executeBatch(); 598 } else { 599 throw new SQLException ("Statement already closed", 600 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 601 } 602 } catch (SQLException sqlEx) { 603 checkAndFireConnectionError(sqlEx); 604 } 605 606 return null; 608 } 610 611 614 public ResultSet executeQuery(String sql) throws SQLException { 615 try { 616 if (this.wrappedStmt != null) { 617 return this.wrappedStmt.executeQuery(sql); 618 } else { 619 throw new SQLException ("Statement already closed", 620 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 621 } 622 } catch (SQLException sqlEx) { 623 checkAndFireConnectionError(sqlEx); 624 } 625 626 return null; 628 } 630 631 634 public int executeUpdate(String sql, int autoGeneratedKeys) 635 throws SQLException { 636 try { 637 if (this.wrappedStmt != null) { 638 return this.wrappedStmt.executeUpdate(sql, autoGeneratedKeys); 639 } else { 640 throw new SQLException ("Statement already closed", 641 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 642 } 643 } catch (SQLException sqlEx) { 644 checkAndFireConnectionError(sqlEx); 645 } 646 647 return -1; 649 } 651 652 655 public int executeUpdate(String sql, int[] columnIndexes) 656 throws SQLException { 657 try { 658 if (this.wrappedStmt != null) { 659 return this.wrappedStmt.executeUpdate(sql, columnIndexes); 660 } else { 661 throw new SQLException ("Statement already closed", 662 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 663 } 664 } catch (SQLException sqlEx) { 665 checkAndFireConnectionError(sqlEx); 666 } 667 668 return -1; 670 } 672 673 676 public int executeUpdate(String sql, String [] columnNames) 677 throws SQLException { 678 try { 679 if (this.wrappedStmt != null) { 680 return this.wrappedStmt.executeUpdate(sql, columnNames); 681 } else { 682 throw new SQLException ("Statement already closed", 683 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 684 } 685 } catch (SQLException sqlEx) { 686 checkAndFireConnectionError(sqlEx); 687 } 688 689 return -1; 691 } 693 694 697 public int executeUpdate(String sql) throws SQLException { 698 try { 699 if (this.wrappedStmt != null) { 700 return this.wrappedStmt.executeUpdate(sql); 701 } else { 702 throw new SQLException ("Statement already closed", 703 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 704 } 705 } catch (SQLException sqlEx) { 706 checkAndFireConnectionError(sqlEx); 707 } 708 709 return -1; 711 } 713 } 714 | Popular Tags |