001 package net.sf.persism; 002 003 import java.io.InputStream; 004 import java.io.Reader; 005 import java.math.BigDecimal; 006 import java.net.URL; 007 import java.sql.*; 008 import java.sql.Date; 009 import java.util.*; 010 011 /** 012 * Mapped based implementation of a ResultSet which does not throw any SQLExceptions. 013 * This is a disconnected ResultSet. 014 * 015 * @author Dan Howard 016 * @since 6/19/12 6:14 PM 017 */ 018 public final class ResultSet implements java.sql.ResultSet { 019 020 private List<String> columns = null; 021 private List<Map<Integer, Object>> data; 022 private int columnCount; 023 private ResultSetMetaData rsmd = null; 024 private int row; 025 026 // Only instantiated by Persism 027 ResultSet() { 028 data = new ArrayList<Map<Integer, Object>>(32); 029 row = 0; 030 } 031 032 void add(java.sql.ResultSet rs) throws SQLException { 033 if (rsmd == null) { 034 rsmd = rs.getMetaData(); 035 columnCount = rsmd.getColumnCount(); 036 columns = new ArrayList<String>(32); 037 for (int j = 1; j <= columnCount; j++) { 038 columns.add(rsmd.getColumnLabel(j)); 039 } 040 } 041 042 while (rs.next()) { 043 Map<Integer, Object> row = new HashMap<Integer, Object>(32); 044 for (int j = 1; j <= columnCount; j++) { 045 row.put(j, rs.getObject(j)); 046 } 047 048 data.add(row); 049 } 050 } 051 052 int columnIndex(String col) { 053 int n = -1; 054 for (String column : columns) { 055 n++; 056 if (column.equalsIgnoreCase(col)) { 057 return n; 058 } 059 } 060 return -1; 061 } 062 063 064 // Methods which implement java.sql.ResultSet 065 066 public boolean next() throws SQLException { 067 if (row < data.size()) { 068 row++; 069 return true; 070 } 071 row = 0; 072 return false; 073 } 074 075 public void close() throws SQLException { 076 } 077 078 public boolean wasNull() throws SQLException { 079 return false; 080 } 081 082 public String getString(int columnIndex) throws SQLException { 083 return null; 084 } 085 086 public boolean getBoolean(int columnIndex) throws SQLException { 087 return false; 088 } 089 090 public byte getByte(int columnIndex) throws SQLException { 091 return 0; 092 } 093 094 public short getShort(int columnIndex) throws SQLException { 095 return 0; 096 } 097 098 public int getInt(int columnIndex) throws SQLException { 099 return 0; 100 } 101 102 public long getLong(int columnIndex) throws SQLException { 103 return 0; 104 } 105 106 public float getFloat(int columnIndex) throws SQLException { 107 return 0; 108 } 109 110 public double getDouble(int columnIndex) throws SQLException { 111 return 0; 112 } 113 114 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { 115 return null; 116 } 117 118 public byte[] getBytes(int columnIndex) throws SQLException { 119 return new byte[0]; 120 } 121 122 public Date getDate(int columnIndex) throws SQLException { 123 return null; 124 } 125 126 public Time getTime(int columnIndex) throws SQLException { 127 return null; 128 } 129 130 public Timestamp getTimestamp(int columnIndex) throws SQLException { 131 return null; 132 } 133 134 public InputStream getAsciiStream(int columnIndex) throws SQLException { 135 return null; 136 } 137 138 public InputStream getUnicodeStream(int columnIndex) throws SQLException { 139 return null; 140 } 141 142 public InputStream getBinaryStream(int columnIndex) throws SQLException { 143 return null; 144 } 145 146 public String getString(String columnLabel) throws SQLException { 147 int index = columnIndex(columnLabel); 148 if (index > -1) { 149 return String.valueOf(data.get(row).get(index+1)); 150 } 151 return null; 152 } 153 154 public boolean getBoolean(String columnLabel) throws SQLException { 155 return false; 156 } 157 158 public byte getByte(String columnLabel) throws SQLException { 159 return 0; 160 } 161 162 public short getShort(String columnLabel) throws SQLException { 163 return 0; 164 } 165 166 public int getInt(String columnLabel) throws SQLException { 167 return 0; 168 } 169 170 public long getLong(String columnLabel) throws SQLException { 171 return 0; 172 } 173 174 public float getFloat(String columnLabel) throws SQLException { 175 return 0; 176 } 177 178 public double getDouble(String columnLabel) throws SQLException { 179 return 0; 180 } 181 182 public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { 183 return null; 184 } 185 186 public byte[] getBytes(String columnLabel) throws SQLException { 187 return new byte[0]; 188 } 189 190 public Date getDate(String columnLabel) throws SQLException { 191 return null; 192 } 193 194 public Time getTime(String columnLabel) throws SQLException { 195 return null; 196 } 197 198 public Timestamp getTimestamp(String columnLabel) throws SQLException { 199 return null; 200 } 201 202 public InputStream getAsciiStream(String columnLabel) throws SQLException { 203 return null; 204 } 205 206 public InputStream getUnicodeStream(String columnLabel) throws SQLException { 207 return null; 208 } 209 210 public InputStream getBinaryStream(String columnLabel) throws SQLException { 211 return null; 212 } 213 214 public SQLWarning getWarnings() throws SQLException { 215 return null; 216 } 217 218 public void clearWarnings() throws SQLException { 219 } 220 221 public String getCursorName() throws SQLException { 222 return null; 223 } 224 225 public ResultSetMetaData getMetaData() throws SQLException { 226 return null; 227 } 228 229 public Object getObject(int columnIndex) throws SQLException { 230 return null; 231 } 232 233 public Object getObject(String columnLabel) throws SQLException { 234 return null; 235 } 236 237 public int findColumn(String columnLabel) throws SQLException { 238 return 0; 239 } 240 241 public Reader getCharacterStream(int columnIndex) throws SQLException { 242 return null; 243 } 244 245 public Reader getCharacterStream(String columnLabel) throws SQLException { 246 return null; 247 } 248 249 public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 250 return null; 251 } 252 253 public BigDecimal getBigDecimal(String columnLabel) throws SQLException { 254 return null; 255 } 256 257 public boolean isBeforeFirst() throws SQLException { 258 return false; 259 } 260 261 public boolean isAfterLast() throws SQLException { 262 return false; 263 } 264 265 public boolean isFirst() throws SQLException { 266 return false; 267 } 268 269 public boolean isLast() throws SQLException { 270 return false; 271 } 272 273 public void beforeFirst() throws SQLException { 274 } 275 276 public void afterLast() throws SQLException { 277 } 278 279 public boolean first() throws SQLException { 280 return false; 281 } 282 283 public boolean last() throws SQLException { 284 return false; 285 } 286 287 public int getRow() throws SQLException { 288 return 0; 289 } 290 291 public boolean absolute(int row) throws SQLException { 292 return false; 293 } 294 295 public boolean relative(int rows) throws SQLException { 296 return false; 297 } 298 299 public boolean previous() throws SQLException { 300 return false; 301 } 302 303 public void setFetchDirection(int direction) throws SQLException { 304 } 305 306 public int getFetchDirection() throws SQLException { 307 return 0; 308 } 309 310 public void setFetchSize(int rows) throws SQLException { 311 } 312 313 public int getFetchSize() throws SQLException { 314 return 0; 315 } 316 317 public int getType() throws SQLException { 318 return 0; 319 } 320 321 public int getConcurrency() throws SQLException { 322 return 0; 323 } 324 325 public boolean rowUpdated() throws SQLException { 326 return false; 327 } 328 329 public boolean rowInserted() throws SQLException { 330 return false; 331 } 332 333 public boolean rowDeleted() throws SQLException { 334 return false; 335 } 336 337 public void updateNull(int columnIndex) throws SQLException { 338 } 339 340 public void updateBoolean(int columnIndex, boolean x) throws SQLException { 341 } 342 343 public void updateByte(int columnIndex, byte x) throws SQLException { 344 } 345 346 public void updateShort(int columnIndex, short x) throws SQLException { 347 } 348 349 public void updateInt(int columnIndex, int x) throws SQLException { 350 } 351 352 public void updateLong(int columnIndex, long x) throws SQLException { 353 } 354 355 public void updateFloat(int columnIndex, float x) throws SQLException { 356 } 357 358 public void updateDouble(int columnIndex, double x) throws SQLException { 359 } 360 361 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { 362 } 363 364 public void updateString(int columnIndex, String x) throws SQLException { 365 } 366 367 public void updateBytes(int columnIndex, byte[] x) throws SQLException { 368 } 369 370 public void updateDate(int columnIndex, Date x) throws SQLException { 371 } 372 373 public void updateTime(int columnIndex, Time x) throws SQLException { 374 } 375 376 public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { 377 } 378 379 public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { 380 } 381 382 public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { 383 } 384 385 public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { 386 } 387 388 public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { 389 } 390 391 public void updateObject(int columnIndex, Object x) throws SQLException { 392 } 393 394 public void updateNull(String columnLabel) throws SQLException { 395 } 396 397 public void updateBoolean(String columnLabel, boolean x) throws SQLException { 398 } 399 400 public void updateByte(String columnLabel, byte x) throws SQLException { 401 } 402 403 public void updateShort(String columnLabel, short x) throws SQLException { 404 } 405 406 public void updateInt(String columnLabel, int x) throws SQLException { 407 } 408 409 public void updateLong(String columnLabel, long x) throws SQLException { 410 } 411 412 public void updateFloat(String columnLabel, float x) throws SQLException { 413 } 414 415 public void updateDouble(String columnLabel, double x) throws SQLException { 416 } 417 418 public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { 419 } 420 421 public void updateString(String columnLabel, String x) throws SQLException { 422 } 423 424 public void updateBytes(String columnLabel, byte[] x) throws SQLException { 425 } 426 427 public void updateDate(String columnLabel, Date x) throws SQLException { 428 } 429 430 public void updateTime(String columnLabel, Time x) throws SQLException { 431 } 432 433 public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { 434 } 435 436 public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { 437 } 438 439 public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { 440 } 441 442 public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { 443 } 444 445 public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { 446 } 447 448 public void updateObject(String columnLabel, Object x) throws SQLException { 449 } 450 451 public void insertRow() throws SQLException { 452 } 453 454 public void updateRow() throws SQLException { 455 } 456 457 public void deleteRow() throws SQLException { 458 } 459 460 public void refreshRow() throws SQLException { 461 } 462 463 public void cancelRowUpdates() throws SQLException { 464 } 465 466 public void moveToInsertRow() throws SQLException { 467 } 468 469 public void moveToCurrentRow() throws SQLException { 470 } 471 472 public Statement getStatement() throws SQLException { 473 return null; 474 } 475 476 public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException { 477 return null; 478 } 479 480 public Ref getRef(int columnIndex) throws SQLException { 481 return null; 482 } 483 484 public Blob getBlob(int columnIndex) throws SQLException { 485 return null; 486 } 487 488 public Clob getClob(int columnIndex) throws SQLException { 489 return null; 490 } 491 492 public Array getArray(int columnIndex) throws SQLException { 493 return null; 494 } 495 496 public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException { 497 return null; 498 } 499 500 public Ref getRef(String columnLabel) throws SQLException { 501 return null; 502 } 503 504 public Blob getBlob(String columnLabel) throws SQLException { 505 return null; 506 } 507 508 public Clob getClob(String columnLabel) throws SQLException { 509 return null; 510 } 511 512 public Array getArray(String columnLabel) throws SQLException { 513 return null; 514 } 515 516 public Date getDate(int columnIndex, Calendar cal) throws SQLException { 517 return null; 518 } 519 520 public Date getDate(String columnLabel, Calendar cal) throws SQLException { 521 return null; 522 } 523 524 public Time getTime(int columnIndex, Calendar cal) throws SQLException { 525 return null; 526 } 527 528 public Time getTime(String columnLabel, Calendar cal) throws SQLException { 529 return null; 530 } 531 532 public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { 533 return null; 534 } 535 536 public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { 537 return null; 538 } 539 540 public URL getURL(int columnIndex) throws SQLException { 541 return null; 542 } 543 544 public URL getURL(String columnLabel) throws SQLException { 545 return null; 546 } 547 548 public void updateRef(int columnIndex, Ref x) throws SQLException { 549 } 550 551 public void updateRef(String columnLabel, Ref x) throws SQLException { 552 } 553 554 public void updateBlob(int columnIndex, Blob x) throws SQLException { 555 } 556 557 public void updateBlob(String columnLabel, Blob x) throws SQLException { 558 } 559 560 public void updateClob(int columnIndex, Clob x) throws SQLException { 561 } 562 563 public void updateClob(String columnLabel, Clob x) throws SQLException { 564 } 565 566 public void updateArray(int columnIndex, Array x) throws SQLException { 567 } 568 569 public void updateArray(String columnLabel, Array x) throws SQLException { 570 } 571 572 public int getHoldability() throws SQLException { 573 return 0; 574 } 575 576 public boolean isClosed() throws SQLException { 577 return false; 578 } 579 580 public void updateNString(int columnIndex, String nString) throws SQLException { 581 } 582 583 public void updateNString(String columnLabel, String nString) throws SQLException { 584 } 585 586 public String getNString(int columnIndex) throws SQLException { 587 return null; 588 } 589 590 public String getNString(String columnLabel) throws SQLException { 591 return null; 592 } 593 594 public Reader getNCharacterStream(int columnIndex) throws SQLException { 595 return null; 596 } 597 598 public Reader getNCharacterStream(String columnLabel) throws SQLException { 599 return null; 600 } 601 602 public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { 603 } 604 605 public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { 606 } 607 608 public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { 609 } 610 611 public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { 612 } 613 614 public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { 615 } 616 617 public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { 618 } 619 620 public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { 621 } 622 623 public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { 624 } 625 626 public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { 627 } 628 629 public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { 630 } 631 632 public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { 633 } 634 635 public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { 636 } 637 638 public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { 639 } 640 641 public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { 642 } 643 644 public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { 645 } 646 647 public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { 648 } 649 650 public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { 651 } 652 653 public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { 654 } 655 656 public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { 657 } 658 659 public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { 660 } 661 662 public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { 663 } 664 665 public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { 666 } 667 668 public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { 669 } 670 671 public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { 672 } 673 674 public void updateClob(int columnIndex, Reader reader) throws SQLException { 675 } 676 677 public void updateClob(String columnLabel, Reader reader) throws SQLException { 678 } 679 680 public void updateNClob(int columnIndex, Reader reader) throws SQLException { 681 } 682 683 public void updateNClob(String columnLabel, Reader reader) throws SQLException { 684 } 685 686 public <T> T unwrap(Class<T> iface) throws SQLException { 687 return null; 688 } 689 690 public boolean isWrapperFor(Class<?> iface) throws SQLException { 691 return false; 692 } 693 694 // JDBC 6? BELOW? 695 // public RowId getRowId(int columnIndex) throws SQLException { 696 // return null; 697 // } 698 // 699 // public RowId getRowId(String columnLabel) throws SQLException { 700 // return null; 701 // } 702 // 703 // public void updateRowId(int columnIndex, RowId x) throws SQLException { 704 // } 705 // 706 // public void updateRowId(String columnLabel, RowId x) throws SQLException { 707 // } 708 // 709 // public void updateNClob(int columnIndex, NClob nClob) throws SQLException { 710 // } 711 // 712 // public void updateNClob(String columnLabel, NClob nClob) throws SQLException { 713 // } 714 // 715 // public NClob getNClob(int columnIndex) throws SQLException { 716 // return null; 717 // } 718 // 719 // public NClob getNClob(String columnLabel) throws SQLException { 720 // return null; 721 // } 722 // 723 // public SQLXML getSQLXML(int columnIndex) throws SQLException { 724 // return null; 725 // } 726 // 727 // public SQLXML getSQLXML(String columnLabel) throws SQLException { 728 // return null; 729 // } 730 // 731 // public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { 732 // } 733 // 734 // public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { 735 // } 736 }