1 28 29 30 package com.caucho.tools.profiler; 31 32 import java.io.InputStream ; 33 import java.io.Reader ; 34 import java.math.BigDecimal ; 35 import java.net.URL ; 36 import java.sql.*; 37 import java.util.Calendar ; 38 39 public class PreparedStatementWrapper 40 implements PreparedStatement 41 { 42 private final PreparedStatement _preparedStatement; 43 private ProfilerPoint _profilerPoint; 44 45 public PreparedStatementWrapper(ProfilerPoint profilerPoint, 46 PreparedStatement preparedStatement) 47 { 48 _profilerPoint = profilerPoint; 49 _preparedStatement = preparedStatement; 50 } 51 52 public ResultSet executeQuery() 53 throws SQLException 54 { 55 Profiler profiler = _profilerPoint.start(); 56 57 try { 58 return _preparedStatement.executeQuery(); 59 } 60 finally { 61 profiler.finish(); 62 } 63 } 64 65 public int executeUpdate() 66 throws SQLException 67 { 68 Profiler profiler = _profilerPoint.start(); 69 70 try { 71 return _preparedStatement.executeUpdate(); 72 } 73 finally { 74 profiler.finish(); 75 } 76 } 77 78 public void setNull(int parameterIndex, int sqlType) 79 throws SQLException 80 { 81 Profiler profiler = _profilerPoint.start(); 82 83 try { 84 _preparedStatement.setNull(parameterIndex, sqlType); 85 } 86 finally { 87 profiler.finish(); 88 } 89 } 90 91 public void setBoolean(int parameterIndex, boolean x) 92 throws SQLException 93 { 94 Profiler profiler = _profilerPoint.start(); 95 96 try { 97 _preparedStatement.setBoolean(parameterIndex, x); 98 } 99 finally { 100 profiler.finish(); 101 } 102 } 103 104 public void setByte(int parameterIndex, byte x) 105 throws SQLException 106 { 107 Profiler profiler = _profilerPoint.start(); 108 109 try { 110 _preparedStatement.setByte(parameterIndex, x); 111 } 112 finally { 113 profiler.finish(); 114 } 115 } 116 117 public void setShort(int parameterIndex, short x) 118 throws SQLException 119 { 120 Profiler profiler = _profilerPoint.start(); 121 122 try { 123 _preparedStatement.setShort(parameterIndex, x); 124 } 125 finally { 126 profiler.finish(); 127 } 128 } 129 130 public void setInt(int parameterIndex, int x) 131 throws SQLException 132 { 133 Profiler profiler = _profilerPoint.start(); 134 135 try { 136 _preparedStatement.setInt(parameterIndex, x); 137 } 138 finally { 139 profiler.finish(); 140 } 141 } 142 143 public void setLong(int parameterIndex, long x) 144 throws SQLException 145 { 146 Profiler profiler = _profilerPoint.start(); 147 148 try { 149 _preparedStatement.setLong(parameterIndex, x); 150 } 151 finally { 152 profiler.finish(); 153 } 154 } 155 156 public void setFloat(int parameterIndex, float x) 157 throws SQLException 158 { 159 Profiler profiler = _profilerPoint.start(); 160 161 try { 162 _preparedStatement.setFloat(parameterIndex, x); 163 } 164 finally { 165 profiler.finish(); 166 } 167 } 168 169 public void setDouble(int parameterIndex, double x) 170 throws SQLException 171 { 172 Profiler profiler = _profilerPoint.start(); 173 174 try { 175 _preparedStatement.setDouble(parameterIndex, x); 176 } 177 finally { 178 profiler.finish(); 179 } 180 } 181 182 public void setBigDecimal(int parameterIndex, BigDecimal x) 183 throws SQLException 184 { 185 Profiler profiler = _profilerPoint.start(); 186 187 try { 188 _preparedStatement.setBigDecimal(parameterIndex, x); 189 } 190 finally { 191 profiler.finish(); 192 } 193 } 194 195 public void setString(int parameterIndex, String x) 196 throws SQLException 197 { 198 Profiler profiler = _profilerPoint.start(); 199 200 try { 201 _preparedStatement.setString(parameterIndex, x); 202 } 203 finally { 204 profiler.finish(); 205 } 206 } 207 208 public void setBytes(int parameterIndex, byte[] x) 209 throws SQLException 210 { 211 Profiler profiler = _profilerPoint.start(); 212 213 try { 214 _preparedStatement.setBytes(parameterIndex, x); 215 } 216 finally { 217 profiler.finish(); 218 } 219 } 220 221 public void setDate(int parameterIndex, Date x) 222 throws SQLException 223 { 224 Profiler profiler = _profilerPoint.start(); 225 226 try { 227 _preparedStatement.setDate(parameterIndex, x); 228 } 229 finally { 230 profiler.finish(); 231 } 232 } 233 234 public void setTime(int parameterIndex, Time x) 235 throws SQLException 236 { 237 Profiler profiler = _profilerPoint.start(); 238 239 try { 240 _preparedStatement.setTime(parameterIndex, x); 241 } 242 finally { 243 profiler.finish(); 244 } 245 } 246 247 public void setTimestamp(int parameterIndex, Timestamp x) 248 throws SQLException 249 { 250 Profiler profiler = _profilerPoint.start(); 251 252 try { 253 _preparedStatement.setTimestamp(parameterIndex, x); 254 } 255 finally { 256 profiler.finish(); 257 } 258 } 259 260 public void setAsciiStream(int parameterIndex, InputStream x, int length) 261 throws SQLException 262 { 263 Profiler profiler = _profilerPoint.start(); 264 265 try { 266 _preparedStatement.setAsciiStream(parameterIndex, x, length); 267 } 268 finally { 269 profiler.finish(); 270 } 271 } 272 273 public void setUnicodeStream(int parameterIndex, InputStream x, int length) 274 throws SQLException 275 { 276 Profiler profiler = _profilerPoint.start(); 277 278 try { 279 _preparedStatement.setUnicodeStream(parameterIndex, x, length); 280 } 281 finally { 282 profiler.finish(); 283 } 284 } 285 286 public void setBinaryStream(int parameterIndex, InputStream x, int length) 287 throws SQLException 288 { 289 Profiler profiler = _profilerPoint.start(); 290 291 try { 292 _preparedStatement.setBinaryStream(parameterIndex, x, length); 293 } 294 finally { 295 profiler.finish(); 296 } 297 } 298 299 public void clearParameters() 300 throws SQLException 301 { 302 Profiler profiler = _profilerPoint.start(); 303 304 try { 305 _preparedStatement.clearParameters(); 306 } 307 finally { 308 profiler.finish(); 309 } 310 } 311 312 public void setObject(int parameterIndex, 313 Object x, 314 int targetSqlType, 315 int scale) 316 throws SQLException 317 { 318 Profiler profiler = _profilerPoint.start(); 319 320 try { 321 _preparedStatement.setObject(parameterIndex, x, targetSqlType, scale); 322 } 323 finally { 324 profiler.finish(); 325 } 326 } 327 328 public void setObject(int parameterIndex, Object x, int targetSqlType) 329 throws SQLException 330 { 331 Profiler profiler = _profilerPoint.start(); 332 333 try { 334 _preparedStatement.setObject(parameterIndex, x, targetSqlType); 335 } 336 finally { 337 profiler.finish(); 338 } 339 } 340 341 public void setObject(int parameterIndex, Object x) 342 throws SQLException 343 { 344 Profiler profiler = _profilerPoint.start(); 345 346 try { 347 _preparedStatement.setObject(parameterIndex, x); 348 } 349 finally { 350 profiler.finish(); 351 } 352 } 353 354 public boolean execute() 355 throws SQLException 356 { 357 Profiler profiler = _profilerPoint.start(); 358 359 try { 360 return _preparedStatement.execute(); 361 } 362 finally { 363 profiler.finish(); 364 } 365 } 366 367 public void addBatch() 368 throws SQLException 369 { 370 Profiler profiler = _profilerPoint.start(); 371 372 try { 373 _preparedStatement.addBatch(); 374 } 375 finally { 376 profiler.finish(); 377 } 378 } 379 380 public void setCharacterStream(int parameterIndex, Reader reader, int length) 381 throws SQLException 382 { 383 Profiler profiler = _profilerPoint.start(); 384 385 try { 386 _preparedStatement.setCharacterStream(parameterIndex, reader, length); 387 } 388 finally { 389 profiler.finish(); 390 } 391 } 392 393 public void setRef(int i, Ref x) 394 throws SQLException 395 { 396 Profiler profiler = _profilerPoint.start(); 397 398 try { 399 _preparedStatement.setRef(i, x); 400 } 401 finally { 402 profiler.finish(); 403 } 404 } 405 406 public void setBlob(int i, Blob x) 407 throws SQLException 408 { 409 Profiler profiler = _profilerPoint.start(); 410 411 try { 412 _preparedStatement.setBlob(i, x); 413 } 414 finally { 415 profiler.finish(); 416 } 417 } 418 419 public void setClob(int i, Clob x) 420 throws SQLException 421 { 422 Profiler profiler = _profilerPoint.start(); 423 424 try { 425 _preparedStatement.setClob(i, x); 426 } 427 finally { 428 profiler.finish(); 429 } 430 } 431 432 public void setArray(int i, Array x) 433 throws SQLException 434 { 435 Profiler profiler = _profilerPoint.start(); 436 437 try { 438 _preparedStatement.setArray(i, x); 439 } 440 finally { 441 profiler.finish(); 442 } 443 } 444 445 public ResultSetMetaData getMetaData() 446 throws SQLException 447 { 448 Profiler profiler = _profilerPoint.start(); 449 450 try { 451 return _preparedStatement.getMetaData(); 452 } 453 finally { 454 profiler.finish(); 455 } 456 } 457 458 public void setDate(int parameterIndex, Date x, Calendar cal) 459 throws SQLException 460 { 461 Profiler profiler = _profilerPoint.start(); 462 463 try { 464 _preparedStatement.setDate(parameterIndex, x, cal); 465 } 466 finally { 467 profiler.finish(); 468 } 469 } 470 471 public void setTime(int parameterIndex, Time x, Calendar cal) 472 throws SQLException 473 { 474 Profiler profiler = _profilerPoint.start(); 475 476 try { 477 _preparedStatement.setTime(parameterIndex, x, cal); 478 } 479 finally { 480 profiler.finish(); 481 } 482 } 483 484 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) 485 throws SQLException 486 { 487 Profiler profiler = _profilerPoint.start(); 488 489 try { 490 _preparedStatement.setTimestamp(parameterIndex, x, cal); 491 } 492 finally { 493 profiler.finish(); 494 } 495 } 496 497 public void setNull(int paramIndex, int sqlType, String typeName) 498 throws SQLException 499 { 500 Profiler profiler = _profilerPoint.start(); 501 502 try { 503 _preparedStatement.setNull(paramIndex, sqlType, typeName); 504 } 505 finally { 506 profiler.finish(); 507 } 508 } 509 510 public void setURL(int parameterIndex, URL x) 511 throws SQLException 512 { 513 Profiler profiler = _profilerPoint.start(); 514 515 try { 516 _preparedStatement.setURL(parameterIndex, x); 517 } 518 finally { 519 profiler.finish(); 520 } 521 } 522 523 public ParameterMetaData getParameterMetaData() 524 throws SQLException 525 { 526 Profiler profiler = _profilerPoint.start(); 527 528 try { 529 return _preparedStatement.getParameterMetaData(); 530 } 531 finally { 532 profiler.finish(); 533 } 534 } 535 536 public ResultSet executeQuery(String sql) 537 throws SQLException 538 { 539 Profiler profiler = _profilerPoint.start(); 540 541 try { 542 return _preparedStatement.executeQuery(sql); 543 } 544 finally { 545 profiler.finish(); 546 } 547 } 548 549 public int executeUpdate(String sql) 550 throws SQLException 551 { 552 Profiler profiler = _profilerPoint.start(); 553 554 try { 555 return _preparedStatement.executeUpdate(sql); 556 } 557 finally { 558 profiler.finish(); 559 } 560 } 561 562 public void close() 563 throws SQLException 564 { 565 Profiler profiler = _profilerPoint.start(); 566 567 try { 568 _preparedStatement.close(); 569 } 570 finally { 571 profiler.finish(); 572 } 573 } 574 575 public int getMaxFieldSize() 576 throws SQLException 577 { 578 Profiler profiler = _profilerPoint.start(); 579 580 try { 581 return _preparedStatement.getMaxFieldSize(); 582 } 583 finally { 584 profiler.finish(); 585 } 586 } 587 588 public void setMaxFieldSize(int max) 589 throws SQLException 590 { 591 Profiler profiler = _profilerPoint.start(); 592 593 try { 594 _preparedStatement.setMaxFieldSize(max); 595 } 596 finally { 597 profiler.finish(); 598 } 599 } 600 601 public int getMaxRows() 602 throws SQLException 603 { 604 Profiler profiler = _profilerPoint.start(); 605 606 try { 607 return _preparedStatement.getMaxRows(); 608 } 609 finally { 610 profiler.finish(); 611 } 612 } 613 614 public void setMaxRows(int max) 615 throws SQLException 616 { 617 Profiler profiler = _profilerPoint.start(); 618 619 try { 620 _preparedStatement.setMaxRows(max); 621 } 622 finally { 623 profiler.finish(); 624 } 625 } 626 627 public void setEscapeProcessing(boolean enable) 628 throws SQLException 629 { 630 Profiler profiler = _profilerPoint.start(); 631 632 try { 633 _preparedStatement.setEscapeProcessing(enable); 634 } 635 finally { 636 profiler.finish(); 637 } 638 } 639 640 public int getQueryTimeout() 641 throws SQLException 642 { 643 Profiler profiler = _profilerPoint.start(); 644 645 try { 646 return _preparedStatement.getQueryTimeout(); 647 } 648 finally { 649 profiler.finish(); 650 } 651 } 652 653 public void setQueryTimeout(int seconds) 654 throws SQLException 655 { 656 Profiler profiler = _profilerPoint.start(); 657 658 try { 659 _preparedStatement.setQueryTimeout(seconds); 660 } 661 finally { 662 profiler.finish(); 663 } 664 } 665 666 public void cancel() 667 throws SQLException 668 { 669 Profiler profiler = _profilerPoint.start(); 670 671 try { 672 _preparedStatement.cancel(); 673 } 674 finally { 675 profiler.finish(); 676 } 677 } 678 679 public SQLWarning getWarnings() 680 throws SQLException 681 { 682 Profiler profiler = _profilerPoint.start(); 683 684 try { 685 return _preparedStatement.getWarnings(); 686 } 687 finally { 688 profiler.finish(); 689 } 690 } 691 692 public void clearWarnings() 693 throws SQLException 694 { 695 Profiler profiler = _profilerPoint.start(); 696 697 try { 698 _preparedStatement.clearWarnings(); 699 } 700 finally { 701 profiler.finish(); 702 } 703 } 704 705 public void setCursorName(String name) 706 throws SQLException 707 { 708 Profiler profiler = _profilerPoint.start(); 709 710 try { 711 _preparedStatement.setCursorName(name); 712 } 713 finally { 714 profiler.finish(); 715 } 716 } 717 718 public boolean execute(String sql) 719 throws SQLException 720 { 721 Profiler profiler = _profilerPoint.start(); 722 723 try { 724 return _preparedStatement.execute(sql); 725 } 726 finally { 727 profiler.finish(); 728 } 729 } 730 731 public ResultSet getResultSet() 732 throws SQLException 733 { 734 Profiler profiler = _profilerPoint.start(); 735 736 try { 737 return _preparedStatement.getResultSet(); 738 } 739 finally { 740 profiler.finish(); 741 } 742 } 743 744 public int getUpdateCount() 745 throws SQLException 746 { 747 Profiler profiler = _profilerPoint.start(); 748 749 try { 750 return _preparedStatement.getUpdateCount(); 751 } 752 finally { 753 profiler.finish(); 754 } 755 } 756 757 public boolean getMoreResults() 758 throws SQLException 759 { 760 Profiler profiler = _profilerPoint.start(); 761 762 try { 763 return _preparedStatement.getMoreResults(); 764 } 765 finally { 766 profiler.finish(); 767 } 768 } 769 770 public void setFetchDirection(int direction) 771 throws SQLException 772 { 773 Profiler profiler = _profilerPoint.start(); 774 775 try { 776 _preparedStatement.setFetchDirection(direction); 777 } 778 finally { 779 profiler.finish(); 780 } 781 } 782 783 public int getFetchDirection() 784 throws SQLException 785 { 786 Profiler profiler = _profilerPoint.start(); 787 788 try { 789 return _preparedStatement.getFetchDirection(); 790 } 791 finally { 792 profiler.finish(); 793 } 794 } 795 796 public void setFetchSize(int rows) 797 throws SQLException 798 { 799 Profiler profiler = _profilerPoint.start(); 800 801 try { 802 _preparedStatement.setFetchSize(rows); 803 } 804 finally { 805 profiler.finish(); 806 } 807 } 808 809 public int getFetchSize() 810 throws SQLException 811 { 812 Profiler profiler = _profilerPoint.start(); 813 814 try { 815 return _preparedStatement.getFetchSize(); 816 } 817 finally { 818 profiler.finish(); 819 } 820 } 821 822 public int getResultSetConcurrency() 823 throws SQLException 824 { 825 Profiler profiler = _profilerPoint.start(); 826 827 try { 828 return _preparedStatement.getResultSetConcurrency(); 829 } 830 finally { 831 profiler.finish(); 832 } 833 } 834 835 public int getResultSetType() 836 throws SQLException 837 { 838 Profiler profiler = _profilerPoint.start(); 839 840 try { 841 return _preparedStatement.getResultSetType(); 842 } 843 finally { 844 profiler.finish(); 845 } 846 } 847 848 public void addBatch(String sql) 849 throws SQLException 850 { 851 Profiler profiler = _profilerPoint.start(); 852 853 try { 854 _preparedStatement.addBatch(sql); 855 } 856 finally { 857 profiler.finish(); 858 } 859 } 860 861 public void clearBatch() 862 throws SQLException 863 { 864 Profiler profiler = _profilerPoint.start(); 865 866 try { 867 _preparedStatement.clearBatch(); 868 } 869 finally 870 871 { 872 profiler.finish(); 873 } 874 } 875 876 public int[] executeBatch() 877 throws SQLException 878 { 879 Profiler profiler = _profilerPoint.start(); 880 881 try { 882 return _preparedStatement.executeBatch(); 883 } 884 finally { 885 profiler.finish(); 886 } 887 } 888 889 public Connection getConnection() 890 throws SQLException 891 { 892 Profiler profiler = _profilerPoint.start(); 893 894 try { 895 return _preparedStatement.getConnection(); 896 } 897 finally { 898 profiler.finish(); 899 } 900 } 901 902 public boolean getMoreResults(int current) 903 throws SQLException 904 { 905 Profiler profiler = _profilerPoint.start(); 906 907 try { 908 return _preparedStatement.getMoreResults(current); 909 } 910 finally { 911 profiler.finish(); 912 } 913 } 914 915 public ResultSet getGeneratedKeys() 916 throws SQLException 917 { 918 Profiler profiler = _profilerPoint.start(); 919 920 try { 921 return _preparedStatement.getGeneratedKeys(); 922 } 923 finally { 924 profiler.finish(); 925 } 926 } 927 928 public int executeUpdate(String sql, int autoGeneratedKeys) 929 throws SQLException 930 { 931 Profiler profiler = _profilerPoint.start(); 932 933 try { 934 return _preparedStatement.executeUpdate(sql, autoGeneratedKeys); 935 } 936 finally { 937 profiler.finish(); 938 } 939 } 940 941 public int executeUpdate(String sql, int[] columnIndexes) 942 throws SQLException 943 { 944 Profiler profiler = _profilerPoint.start(); 945 946 try { 947 return _preparedStatement.executeUpdate(sql, columnIndexes); 948 } 949 finally { 950 profiler.finish(); 951 } 952 } 953 954 public int executeUpdate(String sql, String [] columnNames) 955 throws SQLException 956 { 957 Profiler profiler = _profilerPoint.start(); 958 959 try { 960 return _preparedStatement.executeUpdate(sql, columnNames); 961 } 962 finally { 963 profiler.finish(); 964 } 965 } 966 967 public boolean execute(String sql, int autoGeneratedKeys) 968 throws SQLException 969 { 970 Profiler profiler = _profilerPoint.start(); 971 972 try { 973 return _preparedStatement.execute(sql, autoGeneratedKeys); 974 } 975 finally { 976 profiler.finish(); 977 } 978 } 979 980 public boolean execute(String sql, int[] columnIndexes) 981 throws SQLException 982 { 983 Profiler profiler = _profilerPoint.start(); 984 985 try { 986 return _preparedStatement.execute(sql, columnIndexes); 987 } 988 finally { 989 profiler.finish(); 990 } 991 } 992 993 public boolean execute(String sql, String [] columnNames) 994 throws SQLException 995 { 996 Profiler profiler = _profilerPoint.start(); 997 998 try { 999 return _preparedStatement.execute(sql, columnNames); 1000 } 1001 finally { 1002 profiler.finish(); 1003 } 1004 } 1005 1006 public int getResultSetHoldability() 1007 throws SQLException 1008 { 1009 Profiler profiler = _profilerPoint.start(); 1010 1011 try { 1012 return _preparedStatement.getResultSetHoldability(); 1013 } 1014 finally { 1015 profiler.finish(); 1016 } 1017 } 1018 1019 public String toString() 1020 { 1021 return "PreparedStatementWrapper[" + _profilerPoint.getName() + "]"; 1022 } 1023} 1024 | Popular Tags |