1 2 12 package com.versant.core.jdbc.conn; 13 14 import com.versant.core.logging.LogEventStore; 15 import com.versant.core.jdbc.logging.JdbcStatementEvent; 16 import com.versant.core.jdbc.logging.JdbcResultSetEvent; 17 import com.versant.core.jdbc.logging.JdbcLogEvent; 18 import com.versant.core.logging.LogEventStore; 19 20 import java.math.BigDecimal ; 21 import java.io.InputStream ; 22 import java.io.Reader ; 23 import java.util.Map ; 24 import java.util.Calendar ; 25 import java.sql.*; 26 import java.net.URL ; 27 28 import com.versant.core.common.BindingSupportImpl; 29 30 33 public final class LoggingResultSet implements ResultSet { 34 35 private LoggingStatement proxyStatement; 36 private String sql; 37 private ResultSet resultSet; 38 private LogEventStore pes; 39 private Object [] row = new Object [8]; 40 private int rowSize; 41 42 public LoggingResultSet(LoggingStatement proxyStatement, String sql, 43 ResultSet resultSet, LogEventStore pes) { 44 this.proxyStatement = proxyStatement; 45 this.sql = sql; 46 this.resultSet = resultSet; 47 this.pes = pes; 48 } 49 50 53 private void addRowToEvent(JdbcResultSetEvent ev) { 54 if (rowSize > 0) { 55 ev.setRow(getRowData()); 56 rowSize = 0; 57 } 58 } 59 60 64 public Object [] getRowData() { 65 Object [] a = new Object [rowSize]; 66 System.arraycopy(row, 0, a, 0, rowSize); 67 return a; 68 } 69 70 73 public String getRowDataString() { 74 Object [] a = getRowData(); 75 StringBuffer s = new StringBuffer (); 76 s.append('['); 77 for (int i = 0; i < a.length; i++) { 78 if (i > 0) s.append(", "); 79 try { 80 s.append(a[i]); 81 } catch (Exception e) { 82 s.append("<toString failed: "); 83 s.append(e.toString()); 84 s.append('>'); 85 } 86 } 87 s.append(']'); 88 return s.toString(); 89 } 90 91 94 public String getSql() { 95 return sql; 96 } 97 98 private void setRow(int columnIndex, Object x) { 99 if (columnIndex > rowSize) rowSize = columnIndex; 100 int i = columnIndex - 1; 101 int n = row.length; 102 if (i >= n) { 103 Object [] a = new Object [i * 2]; 104 System.arraycopy(row, 0, a, 0, n); 105 row = a; 106 } 107 row[i] = x; 108 } 109 110 150 public boolean next() throws SQLException { 151 JdbcResultSetEvent ev = new JdbcResultSetEvent( 152 0, this, null, JdbcStatementEvent.RS_NEXT); 153 addRowToEvent(ev); 154 pes.log(ev); 155 try { 156 boolean ans = resultSet.next(); 157 ev.setNext(ans); 158 return ans; 159 } catch (SQLException e) { 160 ev.setErrorMsg(e); 161 throw e; 162 } catch (RuntimeException e) { 163 ev.setErrorMsg(e); 164 throw e; 165 } finally { 166 ev.updateTotalMs(); 167 } 168 } 169 170 public void close() throws SQLException { 171 JdbcResultSetEvent ev = new JdbcResultSetEvent( 172 0, this, null, JdbcStatementEvent.RS_CLOSE); 173 addRowToEvent(ev); 174 pes.log(ev); 175 try { 176 resultSet.close(); 177 } catch (SQLException e) { 178 ev.setErrorMsg(e); 179 throw e; 180 } catch (RuntimeException e) { 181 ev.setErrorMsg(e); 182 throw e; 183 } finally { 184 ev.updateTotalMs(); 185 } 186 } 187 188 public boolean wasNull() throws SQLException { 189 return resultSet.wasNull(); 190 } 191 192 public String getString(int columnIndex) throws SQLException { 193 String s = resultSet.getString(columnIndex); 194 setRow(columnIndex, s); 195 return s; 196 } 197 198 public boolean getBoolean(int columnIndex) throws SQLException { 199 boolean b = resultSet.getBoolean(columnIndex); 200 setRow(columnIndex, b ? Boolean.TRUE : Boolean.FALSE); 201 return b; 202 } 203 204 public byte getByte(int columnIndex) throws SQLException { 205 byte b = resultSet.getByte(columnIndex); 206 setRow(columnIndex, new Byte (b)); 207 return b; 208 } 209 210 public short getShort(int columnIndex) throws SQLException { 211 short s = resultSet.getShort(columnIndex); 212 setRow(columnIndex, new Short (s)); 213 return s; 214 } 215 216 public int getInt(int columnIndex) throws SQLException { 217 int x = resultSet.getInt(columnIndex); 218 setRow(columnIndex, new Integer (x)); 219 return x; 220 } 221 222 public long getLong(int columnIndex) throws SQLException { 223 long x = resultSet.getLong(columnIndex); 224 setRow(columnIndex, new Long (x)); 225 return x; 226 } 227 228 public float getFloat(int columnIndex) throws SQLException { 229 float x = resultSet.getFloat(columnIndex); 230 setRow(columnIndex, new Float (x)); 231 return x; 232 } 233 234 public double getDouble(int columnIndex) throws SQLException { 235 double x = resultSet.getDouble(columnIndex); 236 setRow(columnIndex, new Double (x)); 237 return x; 238 } 239 240 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { 241 BigDecimal x = resultSet.getBigDecimal(columnIndex,scale); 242 setRow(columnIndex, x); 243 return x; 244 } 245 246 public byte[] getBytes(int columnIndex) throws SQLException { 247 byte[] x = resultSet.getBytes(columnIndex); 248 setRow(columnIndex, x); 249 return x; 250 } 251 252 public Date getDate(int columnIndex) throws SQLException { 253 Date x = resultSet.getDate(columnIndex); 254 setRow(columnIndex, x); 255 return x; 256 } 257 258 public Time getTime(int columnIndex) throws SQLException { 259 Time x = resultSet.getTime(columnIndex); 260 setRow(columnIndex, x); 261 return x; 262 } 263 264 public Timestamp getTimestamp(int columnIndex) throws SQLException { 265 Timestamp x = resultSet.getTimestamp(columnIndex); 266 setRow(columnIndex, x); 267 return x; 268 } 269 270 271 272 public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 273 BigDecimal x = resultSet.getBigDecimal(columnIndex); 274 setRow(columnIndex, x); 275 return x; 276 } 277 278 public Object getObject(int columnIndex) throws SQLException { 279 Object x = resultSet.getObject(columnIndex); 280 setRow(columnIndex, x); 281 return x; 282 } 283 284 public InputStream getAsciiStream(int columnIndex) throws SQLException { 285 return resultSet.getAsciiStream(columnIndex); 286 } 287 288 public InputStream getUnicodeStream(int columnIndex) throws SQLException { 289 return resultSet.getUnicodeStream(columnIndex); 290 } 291 292 public InputStream getBinaryStream(int columnIndex) 293 throws SQLException { 294 return resultSet.getBinaryStream(columnIndex); 295 } 296 297 public String getString(String columnName) throws SQLException { 298 return resultSet.getString(columnName); 299 } 300 301 public boolean getBoolean(String columnName) throws SQLException { 302 return resultSet.getBoolean(columnName); 303 } 304 305 public byte getByte(String columnName) throws SQLException { 306 return resultSet.getByte(columnName); 307 } 308 309 public short getShort(String columnName) throws SQLException { 310 return resultSet.getShort(columnName); 311 } 312 313 public int getInt(String columnName) throws SQLException { 314 return resultSet.getInt(columnName); 315 } 316 317 public long getLong(String columnName) throws SQLException { 318 return resultSet.getLong(columnName); 319 } 320 321 public float getFloat(String columnName) throws SQLException { 322 return resultSet.getFloat(columnName); 323 } 324 325 public double getDouble(String columnName) throws SQLException { 326 return resultSet.getDouble(columnName); 327 } 328 329 public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { 330 return resultSet.getBigDecimal(columnName,scale); 331 } 332 333 public byte[] getBytes(String columnName) throws SQLException { 334 return resultSet.getBytes(columnName); 335 } 336 337 public Date getDate(String columnName) throws SQLException { 338 return resultSet.getDate(columnName); 339 } 340 341 public Time getTime(String columnName) throws SQLException { 342 return resultSet.getTime(columnName); 343 } 344 345 public Timestamp getTimestamp(String columnName) throws SQLException { 346 return resultSet.getTimestamp(columnName); 347 } 348 349 public InputStream getAsciiStream(String columnName) throws SQLException { 350 return resultSet.getAsciiStream(columnName); 351 } 352 353 public InputStream getUnicodeStream(String columnName) throws SQLException { 354 return resultSet.getUnicodeStream(columnName); 355 } 356 357 public InputStream getBinaryStream(String columnName) 358 throws SQLException { 359 return resultSet.getBinaryStream(columnName); 360 } 361 362 public SQLWarning getWarnings() throws SQLException { 363 return resultSet.getWarnings(); 364 } 365 366 public void clearWarnings() throws SQLException { 367 resultSet.clearWarnings(); 368 } 369 370 public String getCursorName() throws SQLException { 371 return resultSet.getCursorName(); 372 } 373 374 public ResultSetMetaData getMetaData() throws SQLException { 375 return resultSet.getMetaData(); 376 } 377 378 public Object getObject(String columnName) throws SQLException { 379 return resultSet.getObject(columnName); 380 } 381 382 public int findColumn(String columnName) throws SQLException { 383 return resultSet.findColumn(columnName); 384 } 385 386 public Reader getCharacterStream(int columnIndex) throws SQLException { 387 return resultSet.getCharacterStream(columnIndex); 388 } 389 390 public Reader getCharacterStream(String columnName) throws SQLException { 391 return resultSet.getCharacterStream(columnName); 392 } 393 394 public BigDecimal getBigDecimal(String columnName) throws SQLException { 395 return resultSet.getBigDecimal(columnName); 396 } 397 398 public boolean isBeforeFirst() throws SQLException { 399 return resultSet.isBeforeFirst(); 400 } 401 402 public boolean isAfterLast() throws SQLException { 403 return resultSet.isAfterLast(); 404 } 405 406 public boolean isFirst() throws SQLException { 407 return resultSet.isFirst(); 408 } 409 410 public boolean isLast() throws SQLException { 411 return resultSet.isLast(); 412 } 413 414 public void beforeFirst() throws SQLException { 415 resultSet.beforeFirst(); 416 } 417 418 public void afterLast() throws SQLException { 419 resultSet.afterLast(); 420 } 421 422 public boolean first() throws SQLException { 423 return resultSet.first(); 424 } 425 426 public boolean last() throws SQLException { 427 JdbcResultSetEvent ev = new JdbcResultSetEvent( 428 0, this, null, JdbcStatementEvent.RS_LAST); 429 addRowToEvent(ev); 430 pes.log(ev); 431 try { 432 boolean ans = resultSet.last(); 433 ev.setNext(ans); 434 return ans; 435 } catch (SQLException e) { 436 ev.setErrorMsg(e); 437 throw e; 438 } catch (RuntimeException e) { 439 ev.setErrorMsg(e); 440 throw e; 441 } finally { 442 ev.updateTotalMs(); 443 } 444 } 445 446 public int getRow() throws SQLException { 447 JdbcResultSetEvent ev = new JdbcResultSetEvent( 448 0, this, null, JdbcStatementEvent.RS_GET_ROW); 449 addRowToEvent(ev); 450 pes.log(ev); 451 try { 452 int ans = resultSet.getRow(); 453 ev.setRows(ans); 454 return ans; 455 } catch (SQLException e) { 456 ev.setErrorMsg(e); 457 throw e; 458 } catch (RuntimeException e) { 459 ev.setErrorMsg(e); 460 throw e; 461 } finally { 462 ev.updateTotalMs(); 463 } 464 } 465 466 public boolean absolute(int row) throws SQLException { 467 JdbcResultSetEvent ev = new JdbcResultSetEvent( 468 0, this, null, JdbcStatementEvent.RS_ABSOLUTE); 469 ev.setRows(row); 470 addRowToEvent(ev); 471 pes.log(ev); 472 try { 473 boolean ans = resultSet.absolute(row); 474 ev.setNext(ans); 475 return ans; 476 } catch (SQLException e) { 477 ev.setErrorMsg(e); 478 throw e; 479 } catch (RuntimeException e) { 480 ev.setErrorMsg(e); 481 throw e; 482 } finally { 483 ev.updateTotalMs(); 484 } 485 } 486 487 public boolean relative(int rows) throws SQLException { 488 JdbcResultSetEvent ev = new JdbcResultSetEvent( 489 0, this, null, JdbcStatementEvent.RS_RELATIVE); 490 ev.setRows(rows); 491 addRowToEvent(ev); 492 pes.log(ev); 493 try { 494 boolean ans = resultSet.relative(rows); 495 ev.setNext(ans); 496 return ans; 497 } catch (SQLException e) { 498 ev.setErrorMsg(e); 499 throw e; 500 } catch (RuntimeException e) { 501 ev.setErrorMsg(e); 502 throw e; 503 } finally { 504 ev.updateTotalMs(); 505 } 506 } 507 508 public boolean previous() throws SQLException { 509 return resultSet.previous(); 510 } 511 512 public void setFetchDirection(int direction) throws SQLException { 513 resultSet.setFetchDirection(direction); 514 } 515 516 public int getFetchDirection() throws SQLException { 517 return resultSet.getFetchDirection(); 518 } 519 520 public void setFetchSize(int rows) throws SQLException { 521 JdbcLogEvent ev = null; 522 if (pes.isFiner()) { 523 ev = new JdbcLogEvent(0, 524 JdbcLogEvent.RS_FETCH_SIZE, Integer.toString(rows)); 525 pes.log(ev); 526 } 527 try { 528 resultSet.setFetchSize(rows); 529 } catch (SQLException e) { 530 if (ev != null) ev.setErrorMsg(e); 531 throw e; 532 } catch (RuntimeException e) { 533 if (ev != null) ev.setErrorMsg(e); 534 throw e; 535 } finally { 536 if (ev != null) ev.updateTotalMs(); 537 } 538 } 539 540 public int getFetchSize() throws SQLException { 541 return resultSet.getFetchSize(); 542 } 543 544 public int getType() throws SQLException { 545 return resultSet.getType(); 546 } 547 548 public int getConcurrency() throws SQLException { 549 return resultSet.getConcurrency(); 550 } 551 552 public boolean rowUpdated() throws SQLException { 553 return resultSet.rowUpdated(); 554 } 555 556 public boolean rowInserted() throws SQLException { 557 return resultSet.rowInserted(); 558 } 559 560 public boolean rowDeleted() throws SQLException { 561 return resultSet.rowDeleted(); 562 } 563 564 public void updateNull(int columnIndex) throws SQLException { 565 resultSet.updateNull(columnIndex); 566 } 567 568 public void updateBoolean(int columnIndex, boolean x) throws SQLException { 569 resultSet.updateBoolean(columnIndex,x); 570 } 571 572 public void updateByte(int columnIndex, byte x) throws SQLException { 573 resultSet.updateByte(columnIndex,x); 574 } 575 576 public void updateShort(int columnIndex, short x) throws SQLException { 577 resultSet.updateShort(columnIndex,x); 578 } 579 580 public void updateInt(int columnIndex, int x) throws SQLException { 581 resultSet.updateInt(columnIndex,x); 582 } 583 584 public void updateLong(int columnIndex, long x) throws SQLException { 585 resultSet.updateLong(columnIndex,x); 586 } 587 588 public void updateFloat(int columnIndex, float x) throws SQLException { 589 resultSet.updateFloat(columnIndex,x); 590 } 591 592 public void updateDouble(int columnIndex, double x) throws SQLException { 593 resultSet.updateDouble(columnIndex,x); 594 } 595 596 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { 597 resultSet.updateBigDecimal(columnIndex,x); 598 } 599 600 public void updateString(int columnIndex, String x) throws SQLException { 601 resultSet.updateString(columnIndex,x); 602 } 603 604 public void updateBytes(int columnIndex, byte x[]) throws SQLException { 605 resultSet.updateBytes(columnIndex,x); 606 } 607 608 public void updateDate(int columnIndex, Date x) throws SQLException { 609 resultSet.updateDate(columnIndex,x); 610 } 611 612 public void updateTime(int columnIndex, Time x) throws SQLException { 613 resultSet.updateTime(columnIndex,x); 614 } 615 616 public void updateTimestamp(int columnIndex, Timestamp x) 617 throws SQLException { 618 resultSet.updateTimestamp(columnIndex,x); 619 } 620 621 public void updateAsciiStream(int columnIndex, 622 InputStream x, 623 int length) throws SQLException { 624 resultSet.updateAsciiStream(columnIndex,x,length); 625 } 626 627 public void updateBinaryStream(int columnIndex, 628 InputStream x, 629 int length) throws SQLException { 630 resultSet.updateBinaryStream(columnIndex,x,length); 631 } 632 633 public void updateCharacterStream(int columnIndex, 634 Reader x, 635 int length) throws SQLException { 636 resultSet.updateCharacterStream(columnIndex,x,length); 637 } 638 639 public void updateObject(int columnIndex, Object x, int scale) 640 throws SQLException { 641 resultSet.updateObject(columnIndex,x,scale); 642 } 643 644 public void updateObject(int columnIndex, Object x) throws SQLException { 645 resultSet.updateObject(columnIndex,x); 646 } 647 648 public void updateNull(String columnName) throws SQLException { 649 resultSet.updateNull(columnName); 650 } 651 652 public void updateBoolean(String columnName, boolean x) throws SQLException { 653 resultSet.updateBoolean(columnName,x); 654 } 655 656 public void updateByte(String columnName, byte x) throws SQLException { 657 resultSet.updateByte(columnName,x); 658 } 659 660 public void updateShort(String columnName, short x) throws SQLException { 661 resultSet.updateShort(columnName,x); 662 } 663 664 public void updateInt(String columnName, int x) throws SQLException { 665 resultSet.updateInt(columnName,x); 666 } 667 668 public void updateLong(String columnName, long x) throws SQLException { 669 resultSet.updateLong(columnName,x); 670 } 671 672 public void updateFloat(String columnName, float x) throws SQLException { 673 resultSet.updateFloat(columnName,x); 674 } 675 676 public void updateDouble(String columnName, double x) throws SQLException { 677 resultSet.updateDouble(columnName,x); 678 } 679 680 public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { 681 resultSet.updateBigDecimal(columnName,x); 682 } 683 684 public void updateString(String columnName, String x) throws SQLException { 685 resultSet.updateString(columnName,x); 686 } 687 688 public void updateBytes(String columnName, byte x[]) throws SQLException { 689 resultSet.updateBytes(columnName,x); 690 } 691 692 public void updateDate(String columnName, Date x) throws SQLException { 693 resultSet.updateDate(columnName,x); 694 } 695 696 public void updateTime(String columnName, Time x) throws SQLException { 697 resultSet.updateTime(columnName,x); 698 } 699 700 public void updateTimestamp(String columnName, Timestamp x) 701 throws SQLException { 702 resultSet.updateTimestamp(columnName,x); 703 } 704 705 public void updateAsciiStream(String columnName, 706 InputStream x, 707 int length) throws SQLException { 708 resultSet.updateAsciiStream(columnName,x,length); 709 } 710 711 public void updateBinaryStream(String columnName, 712 InputStream x, 713 int length) throws SQLException { 714 resultSet.updateBinaryStream(columnName,x,length); 715 } 716 717 public void updateCharacterStream(String columnName, 718 Reader reader, 719 int length) throws SQLException { 720 resultSet.updateCharacterStream(columnName,reader,length); 721 } 722 723 public void updateObject(String columnName, Object x, int scale) 724 throws SQLException { 725 resultSet.updateObject(columnName,x,scale); 726 } 727 728 public void updateObject(String columnName, Object x) throws SQLException { 729 resultSet.updateObject(columnName,x); 730 } 731 732 public void insertRow() throws SQLException { 733 resultSet.insertRow(); 734 } 735 736 public void updateRow() throws SQLException { 737 resultSet.updateRow(); 738 } 739 740 public void deleteRow() throws SQLException { 741 resultSet.deleteRow(); 742 } 743 744 public void refreshRow() throws SQLException { 745 resultSet.refreshRow(); 746 } 747 748 public void cancelRowUpdates() throws SQLException { 749 resultSet.cancelRowUpdates(); 750 } 751 752 public void moveToInsertRow() throws SQLException { 753 resultSet.moveToInsertRow(); 754 } 755 756 public void moveToCurrentRow() throws SQLException { 757 resultSet.moveToCurrentRow(); 758 } 759 760 public Statement getStatement() throws SQLException { 761 return proxyStatement; 762 } 763 764 public Object getObject(int i, Map map) throws SQLException { 765 return resultSet.getObject(i,map); 766 } 767 768 public Ref getRef(int i) throws SQLException { 769 return resultSet.getRef(i); 770 } 771 772 public Blob getBlob(int i) throws SQLException { 773 return resultSet.getBlob(i); 774 } 775 776 public Clob getClob(int i) throws SQLException { 777 return resultSet.getClob(i); 778 } 779 780 public Array getArray(int i) throws SQLException { 781 return resultSet.getArray(i); 782 } 783 784 public Object getObject(String colName, Map map) throws SQLException { 785 return resultSet.getObject(colName,map); 786 } 787 788 public Ref getRef(String colName) throws SQLException { 789 return resultSet.getRef(colName); 790 } 791 792 public Blob getBlob(String colName) throws SQLException { 793 return resultSet.getBlob(colName); 794 } 795 796 public Clob getClob(String colName) throws SQLException { 797 return resultSet.getClob(colName); 798 } 799 800 public Array getArray(String colName) throws SQLException { 801 return resultSet.getArray(colName); 802 } 803 804 public Date getDate(int columnIndex, Calendar cal) throws SQLException { 805 return resultSet.getDate(columnIndex,cal); 806 } 807 808 public Date getDate(String columnName, Calendar cal) throws SQLException { 809 return resultSet.getDate(columnName,cal); 810 } 811 812 public Time getTime(int columnIndex, Calendar cal) throws SQLException { 813 return resultSet.getTime(columnIndex,cal); 814 } 815 816 public Time getTime(String columnName, Calendar cal) throws SQLException { 817 return resultSet.getTime(columnName,cal); 818 } 819 820 public Timestamp getTimestamp(int columnIndex, Calendar cal) 821 throws SQLException { 822 return resultSet.getTimestamp(columnIndex,cal); 823 } 824 825 public Timestamp getTimestamp(String columnName, Calendar cal) 826 throws SQLException { 827 return resultSet.getTimestamp(columnName,cal); 828 } 829 830 public URL getURL(int columnIndex) throws SQLException { 834 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 835 } 836 public URL getURL(String columnName) throws SQLException { 837 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 838 } 839 public void updateRef(int columnIndex, Ref x) throws SQLException { 840 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 841 } 842 public void updateRef(String columnName, Ref x) throws SQLException { 843 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 844 } 845 public void updateBlob(int columnIndex, Blob x) throws SQLException { 846 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 847 } 848 public void updateBlob(String columnName, Blob x) throws SQLException { 849 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 850 } 851 public void updateClob(int columnIndex, Clob x) throws SQLException { 852 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 853 } 854 public void updateClob(String columnName, Clob x) throws SQLException { 855 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 856 } 857 public void updateArray(int columnIndex, Array x) throws SQLException { 858 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 859 } 860 public void updateArray(String columnName, Array x) throws SQLException { 861 throw BindingSupportImpl.getInstance().unsupported("not implemented."); 862 } 863 } 864 865 | Popular Tags |