1 24 25 package com.mckoi.database.jdbc; 26 27 import java.io.*; 28 import java.sql.*; 29 import java.math.BigDecimal ; 30 import java.util.Calendar ; 31 import java.util.Hashtable ; 32 import java.util.Vector ; 33 import com.mckoi.database.global.ColumnDescription; 34 import com.mckoi.database.global.ByteLongObject; 35 import com.mckoi.database.global.ObjectTransfer; 36 import com.mckoi.database.global.StreamableObject; 37 import com.mckoi.database.global.ObjectTranslator; 38 import com.mckoi.database.global.SQLTypes; 39 import com.mckoi.database.global.StringObject; 40 import com.mckoi.util.BigNumber; 41 42 50 51 public final class MResultSet implements ResultSet { 52 53 56 private static final int DEFAULT_FETCH_SIZE = 32; 57 58 61 private static final int MAXIMUM_FETCH_SIZE = 512; 62 63 66 private static int unique_id_key = 1; 67 68 71 private static BigNumber BD_ZERO = BigNumber.fromInt(0); 72 73 74 77 private int unique_id; 78 79 82 private MConnection connection; 83 84 87 private MStatement statement; 88 89 92 private SQLWarning head_warning; 93 94 97 private int result_id; 98 99 103 private ColumnDescription[] col_list; 104 105 108 private int query_time_ms; 109 110 113 private int result_row_count; 114 115 119 private int max_row_count = Integer.MAX_VALUE; 120 121 124 private int block_top_row; 125 126 129 private int block_row_count; 130 131 135 private int fetch_size; 136 137 141 private Vector result_block; 142 143 146 private int real_index = Integer.MAX_VALUE; 147 148 152 private int real_index_offset = -1; 153 154 158 private boolean last_was_null = false; 159 160 163 private Hashtable column_hash; 164 165 168 private boolean closed_on_server; 169 170 171 172 173 174 177 MResultSet(MConnection connection, MStatement statement) { 178 this.connection = connection; 179 this.statement = statement; 180 unique_id = unique_id_key++; 181 result_id = -1; 182 result_block = new Vector (); 183 } 184 185 186 187 190 void addSQLWarning(SQLWarning warning) { 191 if (head_warning == null) { 192 head_warning = warning; 193 } 194 else { 195 head_warning.setNextWarning(warning); 196 } 197 } 198 199 203 boolean verboseColumnNames() { 204 return connection.verboseColumnNames(); 205 } 206 207 211 217 void connSetup(int result_id, ColumnDescription[] col_list, 218 int total_row_count) { 219 this.result_id = result_id; 220 this.col_list = col_list; 221 this.result_row_count = total_row_count; 222 block_top_row = -1; 223 result_block.removeAllElements(); 224 225 real_index = -1; 226 fetch_size = DEFAULT_FETCH_SIZE; 227 closed_on_server = false; 228 } 229 230 238 void setQueryTime(int time_ms) { 239 query_time_ms = time_ms; 240 } 241 242 247 void setMaxRowCount(int row_count) { 248 if (row_count == 0) { 249 max_row_count = Integer.MAX_VALUE; 250 } 251 else { 252 max_row_count = row_count; 253 } 254 } 255 256 260 boolean containsLargeObjects() { 261 for (int i = 0; i < col_list.length; ++i) { 262 ColumnDescription col = col_list[i]; 263 int sql_type = col.getSQLType(); 264 if (sql_type == com.mckoi.database.global.SQLTypes.BINARY || 265 sql_type == com.mckoi.database.global.SQLTypes.VARBINARY || 266 sql_type == com.mckoi.database.global.SQLTypes.LONGVARBINARY || 267 sql_type == com.mckoi.database.global.SQLTypes.BLOB || 268 sql_type == com.mckoi.database.global.SQLTypes.CHAR || 269 sql_type == com.mckoi.database.global.SQLTypes.VARCHAR || 270 sql_type == com.mckoi.database.global.SQLTypes.LONGVARCHAR || 271 sql_type == com.mckoi.database.global.SQLTypes.CLOB) { 272 return true; 273 } 274 } 275 return false; 276 } 277 278 283 void storeResultLocally() throws SQLException { 284 updateResultPart(0, rowCount()); 286 connection.disposeResult(result_id); 288 closed_on_server = true; 289 } 290 291 301 void updateResultPart(int row_index, int row_count) throws SQLException { 302 303 if (row_count == 0) { 305 return; 306 } 307 308 if (row_index + row_count < 0) { 309 throw new SQLException( 310 "ResultSet row index is before the start of the set."); 311 } 312 else if (row_index < 0) { 313 row_index = 0; 314 row_count = row_count + row_index; 315 } 316 317 if (row_index >= rowCount()) { 318 throw new SQLException( 319 "ResultSet row index is after the end of the set."); 320 } 321 else if (row_index + row_count > rowCount()) { 322 row_count = rowCount() - row_index; 323 } 324 325 if (result_id == -1) { 326 throw new SQLException("result_id == -1. No result to get from."); 327 } 328 329 try { 330 331 result_block = connection.getRowCache().getResultPart(result_block, 334 connection, result_id, row_index, row_count, 335 columnCount(), rowCount()); 336 337 block_top_row = row_index; 339 block_row_count = row_count; 341 342 353 } 354 catch (IOException e) { 355 e.printStackTrace(); 356 throw new SQLException("IO Error: " + e.getMessage()); 357 } 358 359 } 360 361 371 void closeCurrentResult() throws SQLException { 372 if (getResultID() != -1) { 373 if (!closed_on_server) { 374 connection.disposeResult(result_id); 376 closed_on_server = true; 377 } 378 result_id = -1; 379 real_index = Integer.MAX_VALUE; 380 if (column_hash != null) { 382 column_hash.clear(); 383 } 384 } 385 } 386 387 392 int getResultID() { 393 return result_id; 394 } 395 396 399 int rowCount() { 400 return Math.min(result_row_count, max_row_count); 404 } 405 406 409 int columnCount() { 410 return col_list.length; 411 } 412 413 417 ColumnDescription getColumn(int column) { 418 return col_list[column]; 419 } 420 421 431 boolean isUpdate() { 432 return (columnCount() == 1 && rowCount() == 1 && 435 getColumn(0).getName().equals("@aresult")); 436 } 437 438 442 int intValue() throws SQLException { 443 if (isUpdate()) { 444 Object ob = result_block.elementAt(0); 445 if (ob instanceof BigNumber) { 446 return ((BigNumber) ob).intValue(); 447 } 448 else { 449 return 0; 450 } 451 } 452 throw new SQLException("Unable to format query result as an update value."); 453 } 454 455 460 void dispose() { 461 try { 462 close(); 463 } 464 catch (SQLException e) { 465 } 469 470 connection = null; 471 statement = null; 472 col_list = null; 473 result_block = null; 474 } 475 476 481 void ensureIndexLoaded() throws SQLException { 482 if (real_index == -1) { 483 throw new SQLException("Row index out of bounds."); 484 } 485 486 int row_offset = real_index - block_top_row; 488 if (row_offset >= block_row_count) { 489 updateResultPart(real_index, fetch_size); 491 row_offset = real_index - block_top_row; 493 real_index_offset = row_offset * columnCount(); 494 } 495 else if (row_offset < 0) { 496 int fs_dif = Math.min(fetch_size, 8); 497 updateResultPart(real_index - fetch_size + fs_dif, fetch_size); 499 row_offset = real_index - block_top_row; 501 real_index_offset = row_offset * columnCount(); 502 } 503 } 504 505 509 int findColumnIndex(String name) throws SQLException { 510 if (column_hash == null) { 513 column_hash = new Hashtable (); 514 } 515 516 boolean case_insensitive = connection.isCaseInsensitiveIdentifiers(); 517 if (case_insensitive) { 518 name = name.toUpperCase(); 519 } 520 521 Integer index = (Integer ) column_hash.get(name); 522 if (index == null) { 523 int col_count = columnCount(); 524 String [] cols = new String [col_count]; 526 for (int i = 0; i < col_count; ++i) { 527 String col_name = col_list[i].getName(); 528 if (col_name.startsWith("\"")) { 529 col_name = col_name.substring(1, col_name.length() - 1); 530 } 531 if (col_name.startsWith("@")) { 533 col_name = col_name.substring(2); 534 } 535 if (case_insensitive) { 536 col_name = col_name.toUpperCase(); 537 } 538 cols[i] = col_name; 539 } 540 541 for (int i = 0; i < col_count; ++i) { 542 String col_name = cols[i]; 543 if (col_name.equals(name)) { 544 column_hash.put(name, new Integer (i + 1)); 545 return i + 1; 546 } 547 } 548 549 String point_name = "." + name; 551 for (int i = 0; i < col_count; ++i) { 552 String col_name = cols[i]; 553 if (col_name.endsWith(point_name)) { 554 column_hash.put(name, new Integer (i + 1)); 555 return i + 1; 556 } 557 } 558 559 throw new SQLException("Couldn't find column with name: " + name); 564 } 565 else { 566 return index.intValue(); 567 } 568 } 569 570 574 Object getRawColumn(int column) throws SQLException { 575 if (column < 1 || column > columnCount()) { 578 throw new SQLException( 579 "Column index out of bounds: 1 > " + column + " > " + columnCount()); 580 } 581 ensureIndexLoaded(); 583 Object ob = result_block.elementAt(real_index_offset + (column - 1)); 585 if (ob != null) { 587 last_was_null = false; 588 if (getColumn(column - 1).getSQLType() == 591 com.mckoi.database.global.SQLTypes.JAVA_OBJECT) { 592 ob = ObjectTranslator.deserialize((ByteLongObject) ob); 593 } 594 return ob; 595 } 596 last_was_null = true; 597 return null; 598 } 599 600 603 Object getRawColumn(String name) throws SQLException { 604 return getRawColumn(findColumnIndex(name)); 605 } 606 607 611 private void realIndexUpdate() throws SQLException { 612 int row_offset = real_index - block_top_row; 614 real_index_offset = row_offset * columnCount(); 615 clearWarnings(); 617 } 618 619 624 private boolean canMakeString(Object ob) { 625 return (ob instanceof StringObject || ob instanceof StreamableObject); 626 } 627 628 636 private String makeString(Object ob) throws SQLException { 637 if (ob instanceof StreamableObject) { 638 Clob clob = asClob(ob); 639 long clob_len = clob.length(); 640 if (clob_len < 16384L * 65536L) { 641 return clob.getSubString(1, (int) clob_len); 642 } 643 throw new SQLException("Clob too large to return as a string."); 644 } 645 else if (ob instanceof ByteLongObject) { 646 throw new ClassCastException (); 647 } 648 else { 649 return ob.toString(); 650 } 651 } 652 653 656 private Blob asBlob(Object ob) { 657 if (ob instanceof StreamableObject) { 658 StreamableObject s_ob = (StreamableObject) ob; 659 byte type = (byte) (s_ob.getType() & 0x0F); 660 if (type == 2) { 661 return new MStreamableBlob(connection, result_id, type, 662 s_ob.getIdentifier(), s_ob.getSize()); 663 } 664 } 665 else if (ob instanceof ByteLongObject) { 666 return new MBlob((ByteLongObject) ob); 667 } 668 throw new ClassCastException (); 669 } 670 671 674 private Clob asClob(Object ob) { 675 if (ob instanceof StreamableObject) { 676 StreamableObject s_ob = (StreamableObject) ob; 677 byte type = (byte) (s_ob.getType() & 0x0F); 678 if (type == 3 || 679 type == 4) { 680 return new MStreamableClob(connection, result_id, type, 681 s_ob.getIdentifier(), s_ob.getSize()); 682 } 683 } 684 else if (ob instanceof StringObject) { 685 return new MClob(ob.toString()); 686 } 687 throw new ClassCastException (); 688 } 689 690 694 private Object jdbcObjectCast(Object ob, int sql_type) throws SQLException { 695 switch (sql_type) { 696 case(SQLTypes.BIT): 697 return ob; 698 case(SQLTypes.TINYINT): 699 return new Byte (((BigNumber) ob).byteValue()); 700 case(SQLTypes.SMALLINT): 701 return new Short (((BigNumber) ob).shortValue()); 702 case(SQLTypes.INTEGER): 703 return new Integer (((BigNumber) ob).intValue()); 704 case(SQLTypes.BIGINT): 705 return new Long (((BigNumber) ob).longValue()); 706 case(SQLTypes.FLOAT): 707 return new Double (((BigNumber) ob).doubleValue()); 708 case(SQLTypes.REAL): 709 return new Float (((BigNumber) ob).floatValue()); 710 case(SQLTypes.DOUBLE): 711 return new Double (((BigNumber) ob).doubleValue()); 712 case(SQLTypes.NUMERIC): 713 return ((BigNumber) ob).asBigDecimal(); 714 case(SQLTypes.DECIMAL): 715 return ((BigNumber) ob).asBigDecimal(); 716 case(SQLTypes.CHAR): 717 return makeString(ob); 718 case(SQLTypes.VARCHAR): 719 return makeString(ob); 720 case(SQLTypes.LONGVARCHAR): 721 return makeString(ob); 722 case(SQLTypes.DATE): 723 return new java.sql.Date (((java.util.Date ) ob).getTime()); 724 case(SQLTypes.TIME): 725 return new java.sql.Time (((java.util.Date ) ob).getTime()); 726 case(SQLTypes.TIMESTAMP): 727 return new java.sql.Timestamp (((java.util.Date ) ob).getTime()); 728 case(SQLTypes.BINARY): 729 case(SQLTypes.VARBINARY): 731 case(SQLTypes.LONGVARBINARY): 733 Blob b = asBlob(ob); 734 return b.getBytes(1, (int) b.length()); 735 case(SQLTypes.NULL): 736 return ob; 737 case(SQLTypes.OTHER): 738 return ob; 739 case(SQLTypes.JAVA_OBJECT): 740 return ob; 741 case(SQLTypes.DISTINCT): 742 return ob; 744 case(SQLTypes.STRUCT): 745 return ob; 747 case(SQLTypes.ARRAY): 748 return ob; 750 case(SQLTypes.BLOB): 752 return asBlob(ob); 753 case(SQLTypes.CLOB): 754 return asClob(ob); 755 case(SQLTypes.REF): 756 return ob; 758 default: 760 return ob; 761 } 762 } 763 764 768 773 public int extQueryTimeMillis() { 774 return query_time_ms; 775 } 776 777 781 public java.util.Date extGetDate(int columnIndex) throws SQLException { 782 return (java.util.Date ) getRawColumn(columnIndex); 783 } 784 785 789 public java.util.Date extGetDate(String columnName) throws SQLException { 790 return extGetDate(findColumnIndex(columnName)); 791 } 792 793 795 public boolean next() throws SQLException { 796 int row_count = rowCount(); 797 if (real_index < row_count) { 798 ++real_index; 799 if (real_index < row_count) { 800 realIndexUpdate(); 801 } 802 } 803 return (real_index < row_count); 804 } 805 806 public void close() throws SQLException { 807 closeCurrentResult(); 808 } 809 810 public boolean wasNull() throws SQLException { 811 return last_was_null; 813 } 814 815 819 public String getString(int columnIndex) throws SQLException { 820 Object str = getRawColumn(columnIndex); 821 if (str == null) { 822 return null; 823 } 824 else { 825 if (canMakeString(str)) { 826 return makeString(str); 827 } 828 else { 829 if (str instanceof java.util.Date ) { 832 int sql_type = getColumn(columnIndex - 1).getSQLType(); 833 return jdbcObjectCast(str, sql_type).toString(); 834 } 835 return str.toString(); 836 } 837 } 838 } 839 840 public boolean getBoolean(int columnIndex) throws SQLException { 841 Object ob = getRawColumn(columnIndex); 842 if (ob == null) { 843 return false; 844 } 845 else if (ob instanceof Boolean ) { 846 return ((Boolean ) ob).booleanValue(); 847 } 848 else if (ob instanceof BigNumber) { 849 return ((BigNumber) ob).compareTo(BD_ZERO) != 0; 850 } 851 else if (canMakeString(ob)) { 852 return makeString(ob).equalsIgnoreCase("true"); 853 } 854 else { 855 throw new SQLException("Unable to cast value in ResultSet to boolean"); 856 } 857 } 858 859 public byte getByte(int columnIndex) throws SQLException { 860 BigNumber num = getBigNumber(columnIndex); 862 return num == null ? 0 : num.byteValue(); 863 } 864 865 public short getShort(int columnIndex) throws SQLException { 866 BigNumber num = getBigNumber(columnIndex); 868 return num == null ? 0 : num.shortValue(); 869 } 870 871 public int getInt(int columnIndex) throws SQLException { 872 BigNumber num = getBigNumber(columnIndex); 874 return num == null ? 0 : num.intValue(); 875 } 876 877 public long getLong(int columnIndex) throws SQLException { 878 BigNumber num = getBigNumber(columnIndex); 880 return num == null ? 0 : num.longValue(); 881 } 882 883 public float getFloat(int columnIndex) throws SQLException { 884 BigNumber num = getBigNumber(columnIndex); 886 return num == null ? 0 : num.floatValue(); 887 } 888 889 public double getDouble(int columnIndex) throws SQLException { 890 BigNumber num = getBigNumber(columnIndex); 892 return num == null ? 0 : num.doubleValue(); 893 } 894 895 898 public BigDecimal getBigDecimal(int columnIndex, int scale) 899 throws SQLException { 900 return getBigDecimal(columnIndex); 901 } 902 903 public byte[] getBytes(int columnIndex) throws SQLException { 904 Blob b = getBlob(columnIndex); 905 if (b == null) { 906 return null; 907 } 908 else { 909 if (b.length() <= Integer.MAX_VALUE) { 910 return b.getBytes(1, (int) b.length()); 911 } 912 else { 913 throw new SQLException("Blob too large to return as byte[]"); 914 } 915 } 916 } 931 932 public Date getDate(int columnIndex) throws SQLException { 933 java.util.Date d = extGetDate(columnIndex); 935 if (d != null) { 936 return new Date(d.getTime()); 937 } 938 return null; 939 } 940 941 public java.sql.Time getTime(int columnIndex) throws SQLException { 942 java.util.Date d = extGetDate(columnIndex); 944 if (d != null) { 945 return new Time(d.getTime()); 946 } 947 return null; 948 } 949 950 public java.sql.Timestamp getTimestamp(int columnIndex) 951 throws SQLException { 952 java.util.Date d = extGetDate(columnIndex); 955 if (d != null) { 956 return new Timestamp(d.getTime()); 957 } 958 return null; 959 } 960 961 962 public java.io.InputStream getAsciiStream(int columnIndex) 963 throws SQLException { 964 Clob c = getClob(columnIndex); 965 if (c == null) { 966 return null; 967 } 968 else { 969 return c.getAsciiStream(); 970 } 971 } 972 973 976 public java.io.InputStream getUnicodeStream(int columnIndex) 977 throws SQLException { 978 throw new SQLException("Deprecated method not supported"); 979 } 980 981 public java.io.InputStream getBinaryStream(int columnIndex) 982 throws SQLException { 983 Blob blob = getBlob(columnIndex); 984 if (blob == null) { 985 return null; 986 } 987 else { 988 return blob.getBinaryStream(); 989 } 990 } 1003 1004 1008 public String getString(String columnName) throws SQLException { 1009 return getString(findColumnIndex(columnName)); 1010 } 1011 1012 public boolean getBoolean(String columnName) throws SQLException { 1013 return getBoolean(findColumnIndex(columnName)); 1014 } 1015 1016 public byte getByte(String columnName) throws SQLException { 1017 return getByte(findColumnIndex(columnName)); 1018 } 1019 1020 public short getShort(String columnName) throws SQLException { 1021 return getShort(findColumnIndex(columnName)); 1022 } 1023 1024 public int getInt(String columnName) throws SQLException { 1025 return getInt(findColumnIndex(columnName)); 1026 } 1027 1028 public long getLong(String columnName) throws SQLException { 1029 return getLong(findColumnIndex(columnName)); 1030 } 1031 1032 public float getFloat(String columnName) throws SQLException { 1033 return getFloat(findColumnIndex(columnName)); 1034 } 1035 1036 public double getDouble(String columnName) throws SQLException { 1037 return getDouble(findColumnIndex(columnName)); 1038 } 1039 1040 1043 public BigDecimal getBigDecimal(String columnName, int scale) 1044 throws SQLException { 1045 return getBigDecimal(findColumnIndex(columnName)); 1046 } 1047 1048 public byte[] getBytes(String columnName) throws SQLException { 1049 return getBytes(findColumnIndex(columnName)); 1050 } 1051 1052 public java.sql.Date getDate(String columnName) throws SQLException { 1053 return getDate(findColumnIndex(columnName)); 1054 } 1055 1056 public java.sql.Time getTime(String columnName) throws SQLException { 1057 return getTime(findColumnIndex(columnName)); 1058 } 1059 1060 public java.sql.Timestamp getTimestamp(String columnName) 1061 throws SQLException { 1062 return getTimestamp(findColumnIndex(columnName)); 1063 } 1064 1065 public java.io.InputStream getAsciiStream(String columnName) 1066 throws SQLException { 1067 return getAsciiStream(findColumnIndex(columnName)); 1068 } 1069 1070 1073 public java.io.InputStream getUnicodeStream(String columnName) 1074 throws SQLException { 1075 return getUnicodeStream(findColumnIndex(columnName)); 1076 } 1077 1078 public java.io.InputStream getBinaryStream(String columnName) 1079 throws SQLException { 1080 return getBinaryStream(findColumnIndex(columnName)); 1081 } 1082 1083 1087 public SQLWarning getWarnings() throws SQLException { 1088 return head_warning; 1089 } 1090 1091 public void clearWarnings() throws SQLException { 1092 head_warning = null; 1093 } 1094 1095 public String getCursorName() throws SQLException { 1096 throw MSQLException.unsupported(); 1098 } 1099 1100 public ResultSetMetaData getMetaData() throws SQLException { 1101 return new MResultSetMetaData(this); 1102 } 1103 1104 public Object getObject(int columnIndex) throws SQLException { 1105 Object ob = getRawColumn(columnIndex); 1106 if (ob == null) { 1107 return ob; 1108 } 1109 if (connection.isStrictGetObject()) { 1110 ColumnDescription col_desc = getColumn(columnIndex - 1); 1112 int sql_type = col_desc.getSQLType(); 1113 1114 return jdbcObjectCast(ob, sql_type); 1115 1116 } 1117 else { 1119 if (ob instanceof ByteLongObject || 1121 ob instanceof StreamableObject) { 1122 return asBlob(ob); 1123 } 1124 } 1125 return ob; 1127 } 1128 1129 public Object getObject(String columnName) throws SQLException { 1130 return getObject(findColumnIndex(columnName)); 1131 } 1132 1133 1135 public int findColumn(String columnName) throws SQLException { 1136 return findColumnIndex(columnName); 1137 } 1138 1139 1141 1144 public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 1145 BigNumber bnum = getBigNumber(columnIndex); 1146 if (bnum != null) { 1147 return bnum.asBigDecimal(); 1148 } 1149 else { 1150 return null; 1151 } 1152 } 1153 1154 private BigNumber getBigNumber(int columnIndex) throws SQLException { 1155 Object ob = getRawColumn(columnIndex); 1156 if (ob == null) { 1157 return null; 1158 } 1159 if (ob instanceof BigNumber) { 1160 return (BigNumber) ob; 1161 } 1162 else { 1163 return BigNumber.fromString(makeString(ob)); 1164 } 1165 } 1166 1167 public BigDecimal getBigDecimal(String columnName) throws SQLException { 1168 return getBigDecimal(findColumnIndex(columnName)); 1169 } 1170 1171 1174 public void setFetchSize(int rows) throws SQLException { 1175 if (rows > 0) { 1176 fetch_size = Math.min(rows, MAXIMUM_FETCH_SIZE); 1177 } 1178 else { 1179 fetch_size = DEFAULT_FETCH_SIZE; 1180 } 1181 } 1182 1183 public int getFetchSize() throws SQLException { 1184 return fetch_size; 1185 } 1186 1187 1189 1193 public java.io.Reader getCharacterStream(int columnIndex) 1194 throws SQLException { 1195 Clob c = getClob(columnIndex); 1196 if (c == null) { 1197 return null; 1198 } 1199 else { 1200 return c.getCharacterStream(); 1201 } 1202 } 1203 1204 public java.io.Reader getCharacterStream(String columnName) 1205 throws SQLException { 1206 return getCharacterStream(findColumnIndex(columnName)); 1207 } 1208 1209 1210 1214 public boolean isBeforeFirst() throws SQLException { 1215 return real_index < 0; 1216 } 1217 1218 public boolean isAfterLast() throws SQLException { 1219 return real_index >= rowCount(); 1220 } 1221 1222 public boolean isFirst() throws SQLException { 1223 return real_index == 0; 1224 } 1225 1226 public boolean isLast() throws SQLException { 1227 return real_index == rowCount() - 1; 1228 } 1229 1230 public void beforeFirst() throws SQLException { 1231 real_index = -1; 1232 } 1233 1234 public void afterLast() throws SQLException { 1235 real_index = rowCount(); 1236 } 1237 1238 public boolean first() throws SQLException { 1239 real_index = 0; 1240 realIndexUpdate(); 1241 return real_index < rowCount(); 1242 } 1243 1244 public boolean last() throws SQLException { 1245 real_index = rowCount() - 1; 1246 realIndexUpdate(); 1247 return real_index >= 0; 1248 } 1249 1250 public int getRow() throws SQLException { 1251 return real_index + 1; 1252 } 1253 1254 public boolean absolute( int row ) throws SQLException { 1255 if (row > 0) { 1256 real_index = row - 1; 1257 } 1258 else if (row < 0) { 1259 real_index = rowCount() + row; 1260 } 1261 realIndexUpdate(); 1262 1263 return (real_index >= 0 && real_index < rowCount()); 1264 } 1265 1266 public boolean relative( int rows ) throws SQLException { 1267 real_index += rows; 1268 1269 int row_count = rowCount(); 1270 if (real_index < -1) { 1271 real_index = -1; 1272 } 1273 if (real_index > row_count) { 1274 real_index = row_count; 1275 } 1276 realIndexUpdate(); 1277 1278 return (real_index >= 0 && real_index < rowCount()); 1279 } 1280 1281 public boolean previous() throws SQLException { 1282 if (real_index >= 0) { 1283 --real_index; 1284 realIndexUpdate(); 1285 } 1286 1287 return real_index >= 0; 1288 } 1289 1290 public void setFetchDirection(int direction) throws SQLException { 1291 } 1294 1295 public int getFetchDirection() throws SQLException { 1296 return FETCH_UNKNOWN; 1299 } 1300 1301 public int getType() throws SQLException { 1302 return TYPE_SCROLL_INSENSITIVE; 1304 } 1305 1306 public int getConcurrency() throws SQLException { 1307 return CONCUR_READ_ONLY; 1309 } 1310 1311 1315 public boolean rowUpdated() throws SQLException { 1316 throw MSQLException.unsupported(); 1317 } 1318 1319 public boolean rowInserted() throws SQLException { 1320 throw MSQLException.unsupported(); 1321 } 1322 1323 public boolean rowDeleted() throws SQLException { 1324 throw MSQLException.unsupported(); 1325 } 1326 1327 public void updateNull(int columnIndex) throws SQLException { 1328 throw MSQLException.unsupported(); 1329 } 1330 1331 public void updateBoolean(int columnIndex, boolean x) throws SQLException { 1332 throw MSQLException.unsupported(); 1333 } 1334 1335 public void updateByte(int columnIndex, byte x) throws SQLException { 1336 throw MSQLException.unsupported(); 1337 } 1338 1339 public void updateShort(int columnIndex, short x) throws SQLException { 1340 throw MSQLException.unsupported(); 1341 } 1342 1343 public void updateInt(int columnIndex, int x) throws SQLException { 1344 throw MSQLException.unsupported(); 1345 } 1346 1347 public void updateLong(int columnIndex, long x) throws SQLException { 1348 throw MSQLException.unsupported(); 1349 } 1350 1351 public void updateFloat(int columnIndex, float x) throws SQLException { 1352 throw MSQLException.unsupported(); 1353 } 1354 1355 public void updateDouble(int columnIndex, double x) throws SQLException { 1356 throw MSQLException.unsupported(); 1357 } 1358 1359 public void updateBigDecimal(int columnIndex, BigDecimal x) 1360 throws SQLException { 1361 throw MSQLException.unsupported(); 1362 } 1363 1364 public void updateString(int columnIndex, String x) throws SQLException { 1365 throw MSQLException.unsupported(); 1366 } 1367 1368 public void updateBytes(int columnIndex, byte x[]) throws SQLException { 1369 throw MSQLException.unsupported(); 1370 } 1371 1372 public void updateDate(int columnIndex, java.sql.Date x) 1373 throws SQLException { 1374 throw MSQLException.unsupported(); 1375 } 1376 1377 public void updateTime(int columnIndex, java.sql.Time x) 1378 throws SQLException { 1379 throw MSQLException.unsupported(); 1380 } 1381 1382 public void updateTimestamp(int columnIndex, java.sql.Timestamp x) 1383 throws SQLException { 1384 throw MSQLException.unsupported(); 1385 } 1386 1387 public void updateAsciiStream(int columnIndex, 1388 java.io.InputStream x, 1389 int length) throws SQLException { 1390 throw MSQLException.unsupported(); 1391 } 1392 1393 public void updateBinaryStream(int columnIndex, 1394 java.io.InputStream x, 1395 int length) throws SQLException { 1396 throw MSQLException.unsupported(); 1397 } 1398 1399 public void updateCharacterStream(int columnIndex, 1400 java.io.Reader x, 1401 int length) throws SQLException { 1402 throw MSQLException.unsupported(); 1403 } 1404 1405 public void updateObject(int columnIndex, Object x, int scale) 1406 throws SQLException { 1407 throw MSQLException.unsupported(); 1408 } 1409 1410 public void updateObject(int columnIndex, Object x) throws SQLException { 1411 throw MSQLException.unsupported(); 1412 } 1413 1414 public void updateNull(String columnName) throws SQLException { 1415 throw MSQLException.unsupported(); 1416 } 1417 1418 public void updateBoolean(String columnName, boolean x) 1419 throws SQLException { 1420 throw MSQLException.unsupported(); 1421 } 1422 1423 public void updateByte(String columnName, byte x) throws SQLException { 1424 throw MSQLException.unsupported(); 1425 } 1426 1427 public void updateShort(String columnName, short x) throws SQLException { 1428 throw MSQLException.unsupported(); 1429 } 1430 1431 public void updateInt(String columnName, int x) throws SQLException { 1432 throw MSQLException.unsupported(); 1433 } 1434 1435 public void updateLong(String columnName, long x) throws SQLException { 1436 throw MSQLException.unsupported(); 1437 } 1438 1439 public void updateFloat(String columnName, float x) throws SQLException { 1440 throw MSQLException.unsupported(); 1441 } 1442 1443 public void updateDouble(String columnName, double x) throws SQLException { 1444 throw MSQLException.unsupported(); 1445 } 1446 1447 public void updateBigDecimal(String columnName, BigDecimal x) 1448 throws SQLException { 1449 throw MSQLException.unsupported(); 1450 } 1451 1452 public void updateString(String columnName, String x) 1453 throws SQLException { 1454 throw MSQLException.unsupported(); 1455 } 1456 1457 public void updateBytes(String columnName, byte x[]) throws SQLException { 1458 throw MSQLException.unsupported(); 1459 } 1460 1461 public void updateDate(String columnName, java.sql.Date x) 1462 throws SQLException { 1463 throw MSQLException.unsupported(); 1464 } 1465 1466 public void updateTime(String columnName, java.sql.Time x) 1467 throws SQLException { 1468 throw MSQLException.unsupported(); 1469 } 1470 1471 public void updateTimestamp(String columnName, java.sql.Timestamp x) 1472 throws SQLException { 1473 throw MSQLException.unsupported(); 1474 } 1475 1476 public void updateAsciiStream(String columnName, 1477 java.io.InputStream x, 1478 int length) throws SQLException { 1479 throw MSQLException.unsupported(); 1480 } 1481 1482 public void updateBinaryStream(String columnName, 1483 java.io.InputStream x, 1484 int length) throws SQLException { 1485 throw MSQLException.unsupported(); 1486 } 1487 1488 public void updateCharacterStream(String columnName, 1489 java.io.Reader reader, 1490 int length) throws SQLException { 1491 throw MSQLException.unsupported(); 1492 } 1493 1494 public void updateObject(String columnName, Object x, int scale) 1495 throws SQLException { 1496 throw MSQLException.unsupported(); 1497 } 1498 1499 public void updateObject(String columnName, Object x) throws SQLException { 1500 throw MSQLException.unsupported(); 1501 } 1502 1503 public void insertRow() throws SQLException { 1504 throw MSQLException.unsupported(); 1505 } 1506 1507 public void updateRow() throws SQLException { 1508 throw MSQLException.unsupported(); 1509 } 1510 1511 public void deleteRow() throws SQLException { 1512 throw MSQLException.unsupported(); 1513 } 1514 1515 public void refreshRow() throws SQLException { 1516 throw MSQLException.unsupported(); 1517 } 1518 1519 public void cancelRowUpdates() throws SQLException { 1520 throw MSQLException.unsupported(); 1521 } 1522 1523 public void moveToInsertRow() throws SQLException { 1524 throw MSQLException.unsupported(); 1525 } 1526 1527 public void moveToCurrentRow() throws SQLException { 1528 throw MSQLException.unsupported(); 1529 } 1530 1531 public Statement getStatement() throws SQLException { 1532 return statement; 1533 } 1534 1535 public Object getObject(int i, java.util.Map map) throws SQLException { 1536 return getObject(i); 1539 } 1540 1541 public Ref getRef(int i) throws SQLException { 1542 throw MSQLException.unsupported(); 1547 } 1548 1549 public Blob getBlob(int i) throws SQLException { 1550 Object ob = getRawColumn(i); 1552 if (ob != null) { 1553 try { 1554 return asBlob(ob); 1555 } 1556 catch (ClassCastException e) { 1557 throw new SQLException("Column " + i + " is not a binary column."); 1558 } 1559 } 1560 return null; 1561 } 1562 1563 public Clob getClob(int i) throws SQLException { 1564 Object ob = getRawColumn(i); 1566 if (ob != null) { 1567 try { 1568 return asClob(ob); 1569 } 1570 catch (ClassCastException e) { 1571 throw new SQLException("Column " + i + " is not a character column."); 1572 } 1573 } 1574 return null; 1575 } 1576 1577 public Array getArray(int i) throws SQLException { 1578 throw MSQLException.unsupported(); 1580 } 1581 1582 public Object getObject(String colName, java.util.Map map) 1583 throws SQLException { 1584 return getObject(colName); 1587 } 1588 1589 public Ref getRef(String colName) throws SQLException { 1590 throw MSQLException.unsupported(); 1591 } 1592 1593 public Blob getBlob(String colName) throws SQLException { 1594 return getBlob(findColumnIndex(colName)); 1595 } 1596 1597 public Clob getClob(String colName) throws SQLException { 1598 return getClob(findColumnIndex(colName)); 1599 } 1600 1601 public Array getArray(String colName) throws SQLException { 1602 throw MSQLException.unsupported(); 1603 } 1604 1605 public java.sql.Date getDate(int columnIndex, Calendar cal) 1606 throws SQLException { 1607 return getDate(columnIndex); 1608 } 1609 1610 public java.sql.Date getDate(String columnName, Calendar cal) 1611 throws SQLException { 1612 return getDate(columnName); 1613 } 1614 1615 public java.sql.Time getTime(int columnIndex, Calendar cal) 1616 throws SQLException { 1617 return getTime(columnIndex); 1618 } 1619 1620 public java.sql.Time getTime(String columnName, Calendar cal) 1621 throws SQLException { 1622 return getTime(columnName); 1623 } 1624 1625 public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) 1626 throws SQLException { 1627 return getTimestamp(columnIndex); 1628 } 1629 1630 public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) 1631 throws SQLException { 1632 return getTimestamp(columnName); 1633 } 1634 1635 1637 1639 1641 public java.net.URL getURL(int columnIndex) throws SQLException { 1642 throw MSQLException.unsupported(); 1643 } 1644 1645 public java.net.URL getURL(String columnName) throws SQLException { 1646 throw MSQLException.unsupported(); 1647 } 1648 1649 public void updateRef(int columnIndex, java.sql.Ref x) throws SQLException { 1650 throw MSQLException.unsupported(); 1651 } 1652 1653 public void updateRef(String columnName, java.sql.Ref x) 1654 throws SQLException { 1655 throw MSQLException.unsupported(); 1656 } 1657 1658 public void updateBlob(int columnIndex, java.sql.Blob x) 1659 throws SQLException { 1660 throw MSQLException.unsupported(); 1661 } 1662 1663 public void updateBlob(String columnName, java.sql.Blob x) 1664 throws SQLException { 1665 throw MSQLException.unsupported(); 1666 } 1667 1668 public void updateClob(int columnIndex, java.sql.Clob x) 1669 throws SQLException { 1670 throw MSQLException.unsupported(); 1671 } 1672 1673 public void updateClob(String columnName, java.sql.Clob x) 1674 throws SQLException { 1675 throw MSQLException.unsupported(); 1676 } 1677 1678 public void updateArray(int columnIndex, java.sql.Array x) 1679 throws SQLException { 1680 throw MSQLException.unsupported(); 1681 } 1682 1683 public void updateArray(String columnName, java.sql.Array x) 1684 throws SQLException { 1685 throw MSQLException.unsupported(); 1686 } 1687 1688 1690 1692 public void finalize() { 1693 dispose(); 1694 } 1695 1696} 1697 | Popular Tags |