1 19 package craftsman.spy; 20 21 import java.io.InputStream ; 22 import java.io.Reader ; 23 import java.math.BigDecimal ; 24 import java.net.URL ; 25 import java.sql.Array ; 26 import java.sql.Blob ; 27 import java.sql.Clob ; 28 import java.sql.Connection ; 29 import java.sql.Date ; 30 import java.sql.Ref ; 31 import java.sql.ResultSet ; 32 import java.sql.ResultSetMetaData ; 33 import java.sql.SQLException ; 34 import java.sql.SQLWarning ; 35 import java.sql.Statement ; 36 import java.sql.Time ; 37 import java.sql.Timestamp ; 38 import java.sql.Types ; 39 import java.util.Calendar ; 40 import java.util.Map ; 41 42 48 public class SpyResultSet extends SpyEntity implements ResultSet { 49 52 private ResultSet real = null; 53 54 55 58 private Statement statement = null; 59 60 61 64 private int rowCount = 0; 65 66 67 70 private int maxRowCount = 0; 71 72 73 80 protected SpyResultSet ( Connection c, Statement stmt, ResultSet rs) { 81 super(c); 82 statement = stmt; 83 real = rs; 84 } 85 86 87 93 private String getDisplayableResultSetRow() { 94 StringBuffer displayableResultSetRow = new StringBuffer (); 95 96 try { 97 ResultSetMetaData md = real.getMetaData(); 98 for ( int i = 1; i <= md.getColumnCount(); i++) { 99 displayableResultSetRow.append(md.getColumnName(i)) 100 .append('='); 101 switch ( md.getColumnType(i)) { 102 case Types.ARRAY: 103 case Types.BLOB: 104 case Types.CHAR: 105 case Types.CLOB: 106 case Types.DATALINK: 107 case Types.DATE: 108 case Types.JAVA_OBJECT: 109 case Types.LONGVARBINARY: 110 case Types.LONGVARCHAR: 111 case Types.REF: 112 case Types.TIME: 113 case Types.TIMESTAMP: 114 case Types.VARBINARY: 115 case Types.VARCHAR: if ( real.getString(i)!=null) { 116 displayableResultSetRow.append('\'').append(real.getString(i)).append('\''); 117 } else { 118 displayableResultSetRow.append("NULL"); 119 } 120 break; 121 case Types.NULL: displayableResultSetRow.append("NULL"); 122 break; 123 default: if ( real.getString(i)!=null) { 124 displayableResultSetRow.append(real.getString(i)); 125 } else { 126 displayableResultSetRow.append("NULL"); 127 } 128 break; 129 } 130 131 displayableResultSetRow.append(','); 132 } 133 if ( md.getColumnCount() >= 1) { 134 displayableResultSetRow.deleteCharAt(displayableResultSetRow.length()-1); 135 } 136 } catch ( SQLException e) { 137 if ( log.isErrorEnabled()) log.error(getId()+":unable to display resultset row",e); 138 } 139 140 return displayableResultSetRow.toString(); 141 } 142 143 144 147 public int getConcurrency() throws SQLException { 148 return real.getConcurrency(); 149 } 150 151 152 155 public int getFetchDirection() throws SQLException { 156 return real.getFetchDirection(); 157 } 158 159 160 163 public int getFetchSize() throws SQLException { 164 return real.getFetchSize(); 165 } 166 167 168 171 public int getRow() throws SQLException { 172 return real.getRow(); 173 } 174 175 176 179 public int getType() throws SQLException { 180 return real.getType(); 181 } 182 183 184 187 public void afterLast() throws SQLException { 188 real.afterLast(); 189 } 190 191 192 195 public void beforeFirst() throws SQLException { 196 real.beforeFirst(); 197 } 198 199 200 203 public void cancelRowUpdates() throws SQLException { 204 real.cancelRowUpdates(); 205 } 206 207 208 211 public void clearWarnings() throws SQLException { 212 real.clearWarnings(); 213 } 214 215 216 219 public void close() throws SQLException { 220 real.close(); 221 } 222 223 224 227 public void deleteRow() throws SQLException { 228 real.deleteRow(); 230 } 231 232 233 236 public void insertRow() throws SQLException { 237 real.insertRow(); 239 } 240 241 242 245 public void moveToCurrentRow() throws SQLException { 246 real.moveToCurrentRow(); 247 } 248 249 250 253 public void moveToInsertRow() throws SQLException { 254 real.moveToInsertRow(); 255 } 256 257 258 261 public void refreshRow() throws SQLException { 262 real.refreshRow(); 263 } 264 265 266 269 public void updateRow() throws SQLException { 270 real.updateRow(); 272 } 273 274 275 278 public boolean first() throws SQLException { 279 return real.first(); 280 } 281 282 283 286 public boolean isAfterLast() throws SQLException { 287 return real.isAfterLast(); 288 } 289 290 291 294 public boolean isBeforeFirst() throws SQLException { 295 return real.isBeforeFirst(); 296 } 297 298 299 302 public boolean isFirst() throws SQLException { 303 return real.isFirst(); 304 } 305 306 307 310 public boolean isLast() throws SQLException { 311 return real.isLast(); 312 } 313 314 315 318 public boolean last() throws SQLException { 319 return real.last(); 320 } 321 322 323 326 public boolean next() throws SQLException { 327 boolean result = false; 328 329 330 try { 331 result = real.next(); 332 333 if ( result) { 334 rowCount++; 335 336 if ( rowCount > maxRowCount) { 338 maxRowCount++; 339 if ( log.isInfoEnabled()) log.info(getId()+":"+getDisplayableResultSetRow()+" (row "+rowCount+")"); 340 } 341 } else { 342 if ( log.isInfoEnabled()) log.info(getId()+":total rowcount is "+rowCount); 343 } 344 } catch ( SQLException e) { 345 if ( log.isErrorEnabled()) log.error(getId()+": state="+e.getSQLState()+",code="+e.getErrorCode(),e); 346 throw e; 347 } 348 349 return result; 350 } 351 352 353 356 public boolean previous() throws SQLException { 357 boolean result = real.previous(); 358 359 360 if ( result) { 361 rowCount--; 362 } 363 364 return result; 365 } 366 367 368 371 public boolean rowDeleted() throws SQLException { 372 return real.rowDeleted(); 373 } 374 375 376 379 public boolean rowInserted() throws SQLException { 380 return real.rowInserted(); 381 } 382 383 384 387 public boolean rowUpdated() throws SQLException { 388 return real.rowUpdated(); 389 } 390 391 392 395 public boolean wasNull() throws SQLException { 396 return real.wasNull(); 397 } 398 399 400 403 public byte getByte(int columnIndex) throws SQLException { 404 return real.getByte(columnIndex); 405 } 406 407 408 411 public double getDouble(int columnIndex) throws SQLException { 412 return real.getByte(columnIndex); 413 } 414 415 416 419 public float getFloat(int columnIndex) throws SQLException { 420 return real.getFloat(columnIndex); 421 } 422 423 424 427 public int getInt(int columnIndex) throws SQLException { 428 return real.getInt(columnIndex); 429 } 430 431 432 435 public long getLong(int columnIndex) throws SQLException { 436 return real.getLong(columnIndex); 437 } 438 439 440 443 public short getShort(int columnIndex) throws SQLException { 444 return real.getShort(columnIndex); 445 } 446 447 448 451 public void setFetchDirection(int direction) throws SQLException { 452 real.setFetchDirection(direction); 453 } 454 455 456 459 public void setFetchSize(int rows) throws SQLException { 460 real.setFetchSize(rows); 461 } 462 463 464 467 public void updateNull(int columnIndex) throws SQLException { 468 real.updateNull(columnIndex); 469 } 470 471 472 475 public boolean absolute(int row) throws SQLException { 476 return real.absolute(row); 477 } 478 479 480 483 public boolean getBoolean(int columnIndex) throws SQLException { 484 return real.getBoolean(columnIndex); 485 } 486 487 488 491 public boolean relative(int rows) throws SQLException { 492 return real.relative(rows); 493 } 494 495 496 499 public byte[] getBytes(int columnIndex) throws SQLException { 500 return real.getBytes(columnIndex); 501 } 502 503 504 507 public void updateByte(int columnIndex, byte x) throws SQLException { 508 real.updateByte(columnIndex,x); 509 } 510 511 512 515 public void updateDouble(int columnIndex, double x) throws SQLException { 516 real.updateDouble(columnIndex,x); 517 } 518 519 520 523 public void updateFloat(int columnIndex, float x) throws SQLException { 524 real.updateFloat(columnIndex,x); 525 } 526 527 528 531 public void updateInt(int columnIndex, int x) throws SQLException { 532 real.updateInt(columnIndex,x); 533 } 534 535 536 539 public void updateLong(int columnIndex, long x) throws SQLException { 540 real.updateLong(columnIndex,x); 541 } 542 543 544 547 public void updateShort(int columnIndex, short x) throws SQLException { 548 real.updateShort(columnIndex,x); 549 } 550 551 552 555 public void updateBoolean(int columnIndex, boolean x) throws SQLException { 556 real.updateBoolean(columnIndex,x); 557 } 558 559 560 563 public void updateBytes(int columnIndex, byte[] x) throws SQLException { 564 real.updateBytes(columnIndex,x); 565 } 566 567 568 571 public InputStream getAsciiStream(int columnIndex) throws SQLException { 572 return real.getAsciiStream(columnIndex); 573 } 574 575 576 579 public InputStream getBinaryStream(int columnIndex) throws SQLException { 580 return real.getBinaryStream(columnIndex); 581 } 582 583 584 587 public InputStream getUnicodeStream(int columnIndex) throws SQLException { 588 return real.getUnicodeStream(columnIndex); 589 } 590 591 592 595 public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { 596 real.updateAsciiStream(columnIndex,x,length); 597 } 598 599 600 603 public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { 604 real.updateBinaryStream(columnIndex,x,length); 605 } 606 607 608 611 public Reader getCharacterStream(int columnIndex) throws SQLException { 612 return real.getCharacterStream(columnIndex); 613 } 614 615 616 619 public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { 620 real.updateCharacterStream(columnIndex,x,length); 621 } 622 623 624 627 public Object getObject(int columnIndex) throws SQLException { 628 return real.getObject(columnIndex); 629 } 630 631 632 635 public void updateObject(int columnIndex, Object x) throws SQLException { 636 real.updateObject(columnIndex,x); 637 } 638 639 640 643 public void updateObject(int columnIndex, Object x, int scale) throws SQLException { 644 real.updateObject(columnIndex,x,scale); 645 } 646 647 648 651 public String getCursorName() throws SQLException { 652 return real.getCursorName(); 653 } 654 655 656 659 public String getString(int columnIndex) throws SQLException { 660 return real.getString(columnIndex); 661 } 662 663 664 667 public void updateString(int columnIndex, String x) throws SQLException { 668 real.updateString(columnIndex,x); 669 } 670 671 672 675 public byte getByte(String columnName) throws SQLException { 676 return real.getByte(columnName); 677 } 678 679 680 683 public double getDouble(String columnName) throws SQLException { 684 return real.getDouble(columnName); 685 } 686 687 688 691 public float getFloat(String columnName) throws SQLException { 692 return real.getFloat(columnName); 693 } 694 695 696 699 public int findColumn(String columnName) throws SQLException { 700 return real.findColumn(columnName); 701 } 702 703 704 707 public int getInt(String columnName) throws SQLException { 708 return real.getInt(columnName); 709 } 710 711 712 715 public long getLong(String columnName) throws SQLException { 716 return real.getLong(columnName); 717 } 718 719 720 723 public short getShort(String columnName) throws SQLException { 724 return real.getShort(columnName); 725 } 726 727 728 731 public void updateNull(String columnName) throws SQLException { 732 real.updateNull(columnName); 733 } 734 735 736 739 public boolean getBoolean(String columnName) throws SQLException { 740 return real.getBoolean(columnName); 741 } 742 743 744 747 public byte[] getBytes(String columnName) throws SQLException { 748 return real.getBytes(columnName); 749 } 750 751 752 755 public void updateByte(String columnName, byte x) throws SQLException { 756 real.updateByte(columnName,x); 757 } 758 759 760 763 public void updateDouble(String columnName, double x) throws SQLException { 764 real.updateDouble(columnName,x); 765 } 766 767 768 771 public void updateFloat(String columnName, float x) throws SQLException { 772 real.updateFloat(columnName,x); 773 } 774 775 776 779 public void updateInt(String columnName, int x) throws SQLException { 780 real.updateInt(columnName,x); 781 } 782 783 784 787 public void updateLong(String columnName, long x) throws SQLException { 788 real.updateLong(columnName,x); 789 } 790 791 792 795 public void updateShort(String columnName, short x) throws SQLException { 796 real.updateShort(columnName,x); 797 } 798 799 800 803 public void updateBoolean(String columnName, boolean x) throws SQLException { 804 real.updateBoolean(columnName,x); 805 } 806 807 808 811 public void updateBytes(String columnName, byte[] x) throws SQLException { 812 real.updateBytes(columnName,x); 813 } 814 815 816 819 public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 820 return real.getBigDecimal(columnIndex); 821 } 822 823 824 827 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { 828 return real.getBigDecimal(columnIndex,scale); 829 } 830 831 832 835 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { 836 real.updateBigDecimal(columnIndex,x); 837 } 838 839 840 843 public URL getURL(int columnIndex) throws SQLException { 844 return real.getURL(columnIndex); 845 } 846 847 848 851 public Array getArray(int i) throws SQLException { 852 return real.getArray(i); 853 } 854 855 856 859 public void updateArray(int columnIndex, Array x) throws SQLException { 860 real.updateArray(columnIndex,x); 861 } 862 863 864 867 public Blob getBlob(int i) throws SQLException { 868 return real.getBlob(i); 869 } 870 871 872 875 public void updateBlob(int columnIndex, Blob x) throws SQLException { 876 real.updateBlob(columnIndex,x); 877 } 878 879 880 883 public Clob getClob(int i) throws SQLException { 884 return real.getClob(i); 885 } 886 887 888 891 public void updateClob(int columnIndex, Clob x) throws SQLException { 892 real.updateClob(columnIndex,x); 893 } 894 895 896 899 public Date getDate(int columnIndex) throws SQLException { 900 return real.getDate(columnIndex); 901 } 902 903 904 907 public void updateDate(int columnIndex, Date x) throws SQLException { 908 real.updateDate(columnIndex,x); 909 } 910 911 912 915 public Ref getRef(int i) throws SQLException { 916 return real.getRef(i); 917 } 918 919 920 923 public void updateRef(int columnIndex, Ref x) throws SQLException { 924 real.updateRef(columnIndex,x); 925 } 926 927 928 931 public ResultSetMetaData getMetaData() throws SQLException { 932 return real.getMetaData(); 933 } 934 935 936 939 public SQLWarning getWarnings() throws SQLException { 940 SQLWarning current, sw = real.getWarnings(); 941 942 943 if ( (current = sw)!=null) { 944 do { 945 if ( log.isInfoEnabled()) log.info(getId()+":sql warning state="+current.getSQLState()+",code="+current.getErrorCode()+",message="+current.getMessage()); 946 } while ( (current = current.getNextWarning())!=null); 947 } 948 949 return sw; 950 } 951 952 953 956 public Statement getStatement() throws SQLException { 957 return statement; 958 } 959 960 961 964 public Time getTime(int columnIndex) throws SQLException { 965 return real.getTime(columnIndex); 966 } 967 968 969 972 public void updateTime(int columnIndex, Time x) throws SQLException { 973 real.updateTime(columnIndex,x); 974 } 975 976 977 980 public Timestamp getTimestamp(int columnIndex) throws SQLException { 981 return real.getTimestamp(columnIndex); 982 } 983 984 985 988 public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { 989 real.updateTimestamp(columnIndex,x); 990 } 991 992 993 996 public InputStream getAsciiStream(String columnName) throws SQLException { 997 return real.getAsciiStream(columnName); 998 } 999 1000 1001 1004 public InputStream getBinaryStream(String columnName) throws SQLException { 1005 return real.getBinaryStream(columnName); 1006 } 1007 1008 1009 1012 public InputStream getUnicodeStream(String columnName) throws SQLException { 1013 return real.getUnicodeStream(columnName); 1014 } 1015 1016 1017 1020 public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException { 1021 real.updateAsciiStream(columnName,x,length); 1022 } 1023 1024 1025 1028 public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException { 1029 real.updateBinaryStream(columnName,x,length); 1030 } 1031 1032 1033 1036 public Reader getCharacterStream(String columnName) throws SQLException { 1037 return real.getCharacterStream(columnName); 1038 } 1039 1040 1041 1044 public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException { 1045 real.updateCharacterStream(columnName,reader,length); 1046 } 1047 1048 1049 1052 public Object getObject(String columnName) throws SQLException { 1053 return real.getObject(columnName); 1054 } 1055 1056 1057 1060 public void updateObject(String columnName, Object x) throws SQLException { 1061 real.updateObject(columnName,x); 1062 } 1063 1064 1065 1068 public void updateObject(String columnName, Object x, int scale) throws SQLException { 1069 real.updateObject(columnName,x,scale); 1070 } 1071 1072 1073 1076 public Object getObject(int i, Map map) throws SQLException { 1077 return real.getObject(i,map); 1078 } 1079 1080 1081 1084 public String getString(String columnName) throws SQLException { 1085 return real.getString(columnName); 1086 } 1087 1088 1089 1092 public void updateString(String columnName, String x) throws SQLException { 1093 real.updateString(columnName,x); 1094 } 1095 1096 1097 1100 public BigDecimal getBigDecimal(String columnName) throws SQLException { 1101 return real.getBigDecimal(columnName); 1102 } 1103 1104 1105 1108 public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { 1109 return real.getBigDecimal(columnName,scale); 1110 } 1111 1112 1113 1116 public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { 1117 real.updateBigDecimal(columnName,x); 1118 } 1119 1120 1121 1124 public URL getURL(String columnName) throws SQLException { 1125 return real.getURL(columnName); 1126 } 1127 1128 1129 1132 public Array getArray(String colName) throws SQLException { 1133 return real.getArray(colName); 1134 } 1135 1136 1137 1140 public void updateArray(String columnName, Array x) throws SQLException { 1141 real.updateArray(columnName,x); 1142 } 1143 1144 1145 1148 public Blob getBlob(String colName) throws SQLException { 1149 return real.getBlob(colName); 1150 } 1151 1152 1153 1156 public void updateBlob(String columnName, Blob x) throws SQLException { 1157 real.updateBlob(columnName,x); 1158 } 1159 1160 1161 1164 public Clob getClob(String colName) throws SQLException { 1165 return real.getClob(colName); 1166 } 1167 1168 1169 1172 public void updateClob(String columnName, Clob x) throws SQLException { 1173 real.updateClob(columnName,x); 1174 } 1175 1176 1177 1180 public Date getDate(String columnName) throws SQLException { 1181 return real.getDate(columnName); 1182 } 1183 1184 1185 1188 public void updateDate(String columnName, Date x) throws SQLException { 1189 real.updateDate(columnName,x); 1190 } 1191 1192 1193 1196 public Date getDate(int columnIndex, Calendar cal) throws SQLException { 1197 return real.getDate(columnIndex,cal); 1198 } 1199 1200 1201 1204 public Ref getRef(String colName) throws SQLException { 1205 return real.getRef(colName); 1206 } 1207 1208 1209 1212 public void updateRef(String columnName, Ref x) throws SQLException { 1213 real.updateRef(columnName,x); 1214 } 1215 1216 1217 1220 public Time getTime(String columnName) throws SQLException { 1221 return real.getTime(columnName); 1222 } 1223 1224 1225 1228 public void updateTime(String columnName, Time x) throws SQLException { 1229 real.updateTime(columnName,x); 1230 } 1231 1232 1233 1236 public Time getTime(int columnIndex, Calendar cal) throws SQLException { 1237 return real.getTime(columnIndex,cal); 1238 } 1239 1240 1241 1244 public Timestamp getTimestamp(String columnName) throws SQLException { 1245 return real.getTimestamp(columnName); 1246 } 1247 1248 1249 1252 public void updateTimestamp(String columnName, Timestamp x) throws SQLException { 1253 real.updateTimestamp(columnName,x); 1254 } 1255 1256 1257 1260 public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { 1261 return real.getTimestamp(columnIndex,cal); 1262 } 1263 1264 1265 1268 public Object getObject(String colName, Map map) throws SQLException { 1269 return real.getObject(colName,map); 1270 } 1271 1272 1273 1276 public Date getDate(String columnName, Calendar cal) throws SQLException { 1277 return real.getDate(columnName,cal); 1278 } 1279 1280 1281 1284 public Time getTime(String columnName, Calendar cal) throws SQLException { 1285 return real.getTime(columnName,cal); 1286 } 1287 1288 1289 1292 public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { 1293 return real.getTimestamp(columnName,cal); 1294 } 1295} 1296 | Popular Tags |