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