1 16 17 package org.apache.commons.dbcp; 18 19 import java.math.BigDecimal ; 20 import java.sql.Array ; 21 import java.sql.Blob ; 22 import java.sql.Clob ; 23 import java.sql.Ref ; 24 import java.sql.ResultSet ; 25 import java.sql.ResultSetMetaData ; 26 import java.sql.SQLException ; 27 import java.sql.SQLWarning ; 28 import java.sql.Statement ; 29 import java.util.Calendar ; 30 31 38 public class TesterResultSet implements ResultSet { 39 public TesterResultSet(Statement stmt) { 40 _statement = stmt; 41 } 42 43 public TesterResultSet(Statement stmt, Object [][] data) { 44 _statement = stmt; 45 _data = data; 46 } 47 48 public TesterResultSet(Statement stmt, Object [][] data, int type, int concurrency) { 49 _statement = stmt; 50 _data = data; 51 _type = type; 52 _concurrency = concurrency; 53 } 54 55 protected int _type = ResultSet.TYPE_FORWARD_ONLY; 56 protected int _concurrency = ResultSet.CONCUR_READ_ONLY; 57 58 protected Object [][] _data = null; 59 protected int _currentRow = -1; 60 61 protected Statement _statement = null; 62 protected int _rowsLeft = 2; 63 protected boolean _open = true; 64 65 public boolean next() throws SQLException { 66 checkOpen(); 67 if (_data != null) { 68 _currentRow++; 69 return _currentRow < _data.length; 70 } 71 else { 72 if(--_rowsLeft > 0) { 73 return true; 74 } else { 75 return false; 76 } 77 } 78 } 79 80 public void close() throws SQLException { 81 checkOpen(); 82 ((TesterStatement)_statement)._resultSet = null; 83 _open = false; 84 } 85 86 public boolean wasNull() throws SQLException { 87 checkOpen(); 88 return false; 89 } 90 91 public String getString(int columnIndex) throws SQLException { 92 checkOpen(); 93 if (columnIndex == -1) { 94 throw new SQLException ("broken connection"); 95 } 96 if (_data != null) { 97 return (String ) getObject(columnIndex); 98 } 99 return "String" + columnIndex; 100 } 101 102 public boolean getBoolean(int columnIndex) throws SQLException { 103 checkOpen(); 104 return true; 105 } 106 107 public byte getByte(int columnIndex) throws SQLException { 108 checkOpen(); 109 return (byte)columnIndex; 110 } 111 112 public short getShort(int columnIndex) throws SQLException { 113 checkOpen(); 114 return (short)columnIndex; 115 } 116 117 public int getInt(int columnIndex) throws SQLException { 118 checkOpen(); 119 return (short)columnIndex; 120 } 121 122 public long getLong(int columnIndex) throws SQLException { 123 checkOpen(); 124 return (long)columnIndex; 125 } 126 127 public float getFloat(int columnIndex) throws SQLException { 128 checkOpen(); 129 return (float)columnIndex; 130 } 131 132 public double getDouble(int columnIndex) throws SQLException { 133 checkOpen(); 134 return (double)columnIndex; 135 } 136 137 138 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { 139 checkOpen(); 140 return new BigDecimal ((double)columnIndex); 141 } 142 143 public byte[] getBytes(int columnIndex) throws SQLException { 144 checkOpen(); 145 return new byte[] { (byte)columnIndex }; 146 } 147 148 public java.sql.Date getDate(int columnIndex) throws SQLException { 149 checkOpen(); 150 return null; 151 } 152 153 public java.sql.Time getTime(int columnIndex) throws SQLException { 154 checkOpen(); 155 return null; 156 } 157 158 public java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException { 159 checkOpen(); 160 return null; 161 } 162 163 public java.io.InputStream getAsciiStream(int columnIndex) throws SQLException { 164 checkOpen(); 165 return null; 166 } 167 168 169 public java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException { 170 checkOpen(); 171 return null; 172 } 173 174 public java.io.InputStream getBinaryStream(int columnIndex) throws SQLException { 175 checkOpen(); 176 return null; 177 } 178 179 public String getString(String columnName) throws SQLException { 180 checkOpen(); 181 return columnName; 182 } 183 184 public boolean getBoolean(String columnName) throws SQLException { 185 checkOpen(); 186 return true; 187 } 188 189 public byte getByte(String columnName) throws SQLException { 190 checkOpen(); 191 return (byte)(columnName.hashCode()); 192 } 193 194 public short getShort(String columnName) throws SQLException { 195 checkOpen(); 196 return (short)(columnName.hashCode()); 197 } 198 199 public int getInt(String columnName) throws SQLException { 200 checkOpen(); 201 return (columnName.hashCode()); 202 } 203 204 public long getLong(String columnName) throws SQLException { 205 checkOpen(); 206 return (long)(columnName.hashCode()); 207 } 208 209 public float getFloat(String columnName) throws SQLException { 210 checkOpen(); 211 return (float)(columnName.hashCode()); 212 } 213 214 public double getDouble(String columnName) throws SQLException { 215 checkOpen(); 216 return (double)(columnName.hashCode()); 217 } 218 219 220 public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { 221 checkOpen(); 222 return new BigDecimal ((double)columnName.hashCode()); 223 } 224 225 public byte[] getBytes(String columnName) throws SQLException { 226 checkOpen(); 227 return columnName.getBytes(); 228 } 229 230 public java.sql.Date getDate(String columnName) throws SQLException { 231 checkOpen(); 232 return null; 233 } 234 235 public java.sql.Time getTime(String columnName) throws SQLException { 236 checkOpen(); 237 return null; 238 } 239 240 public java.sql.Timestamp getTimestamp(String columnName) throws SQLException { 241 checkOpen(); 242 return null; 243 } 244 245 public java.io.InputStream getAsciiStream(String columnName) throws SQLException { 246 checkOpen(); 247 return null; 248 } 249 250 251 public java.io.InputStream getUnicodeStream(String columnName) throws SQLException { 252 checkOpen(); 253 return null; 254 } 255 256 public java.io.InputStream getBinaryStream(String columnName) throws SQLException { 257 checkOpen(); 258 return null; 259 } 260 261 public SQLWarning getWarnings() throws SQLException { 262 checkOpen(); 263 return null; 264 } 265 266 public void clearWarnings() throws SQLException { 267 checkOpen(); 268 } 269 270 public String getCursorName() throws SQLException { 271 checkOpen(); 272 return null; 273 } 274 275 public ResultSetMetaData getMetaData() throws SQLException { 276 checkOpen(); 277 return null; 278 } 279 280 public Object getObject(int columnIndex) throws SQLException { 281 checkOpen(); 282 if (_data != null) { 283 return _data[_currentRow][columnIndex-1]; 284 } 285 return new Object (); 286 } 287 288 public Object getObject(String columnName) throws SQLException { 289 checkOpen(); 290 return columnName; 291 } 292 293 public int findColumn(String columnName) throws SQLException { 294 checkOpen(); 295 return 1; 296 } 297 298 299 public java.io.Reader getCharacterStream(int columnIndex) throws SQLException { 300 checkOpen(); 301 return null; 302 } 303 304 public java.io.Reader getCharacterStream(String columnName) throws SQLException { 305 checkOpen(); 306 return null; 307 } 308 309 public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 310 checkOpen(); 311 return new BigDecimal ((double)columnIndex); 312 } 313 314 public BigDecimal getBigDecimal(String columnName) throws SQLException { 315 checkOpen(); 316 return new BigDecimal ((double)columnName.hashCode()); 317 } 318 319 public boolean isBeforeFirst() throws SQLException { 320 checkOpen(); 321 return _rowsLeft == 2; 322 } 323 324 public boolean isAfterLast() throws SQLException { 325 checkOpen(); 326 return _rowsLeft < 0; 327 } 328 329 public boolean isFirst() throws SQLException { 330 checkOpen(); 331 return _rowsLeft == 1; 332 } 333 334 public boolean isLast() throws SQLException { 335 checkOpen(); 336 return _rowsLeft == 0; 337 } 338 339 public void beforeFirst() throws SQLException { 340 checkOpen(); 341 } 342 343 public void afterLast() throws SQLException { 344 checkOpen(); 345 } 346 347 public boolean first() throws SQLException { 348 checkOpen(); 349 return false; 350 } 351 352 public boolean last() throws SQLException { 353 checkOpen(); 354 return false; 355 } 356 357 public int getRow() throws SQLException { 358 checkOpen(); 359 return 3 - _rowsLeft; 360 } 361 362 public boolean absolute( int row ) throws SQLException { 363 checkOpen(); 364 return false; 365 } 366 367 public boolean relative( int rows ) throws SQLException { 368 checkOpen(); 369 return false; 370 } 371 372 public boolean previous() throws SQLException { 373 checkOpen(); 374 return false; 375 } 376 377 public void setFetchDirection(int direction) throws SQLException { 378 checkOpen(); 379 } 380 381 public int getFetchDirection() throws SQLException { 382 checkOpen(); 383 return 1; 384 } 385 386 public void setFetchSize(int rows) throws SQLException { 387 checkOpen(); 388 } 389 390 public int getFetchSize() throws SQLException { 391 checkOpen(); 392 return 2; 393 } 394 395 public int getType() throws SQLException { 396 return this._type; 397 } 398 399 public int getConcurrency() throws SQLException { 400 return this._concurrency; 401 } 402 403 public boolean rowUpdated() throws SQLException { 404 checkOpen(); 405 return false; 406 } 407 408 public boolean rowInserted() throws SQLException { 409 checkOpen(); 410 return false; 411 } 412 413 public boolean rowDeleted() throws SQLException { 414 checkOpen(); 415 return false; 416 } 417 418 public void updateNull(int columnIndex) throws SQLException { 419 checkOpen(); 420 } 421 422 public void updateBoolean(int columnIndex, boolean x) throws SQLException { 423 checkOpen(); 424 } 425 426 public void updateByte(int columnIndex, byte x) throws SQLException { 427 checkOpen(); 428 } 429 430 public void updateShort(int columnIndex, short x) throws SQLException { 431 checkOpen(); 432 } 433 434 public void updateInt(int columnIndex, int x) throws SQLException { 435 checkOpen(); 436 } 437 438 public void updateLong(int columnIndex, long x) throws SQLException { 439 checkOpen(); 440 } 441 442 public void updateFloat(int columnIndex, float x) throws SQLException { 443 checkOpen(); 444 } 445 446 public void updateDouble(int columnIndex, double x) throws SQLException { 447 checkOpen(); 448 } 449 450 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { 451 checkOpen(); 452 } 453 454 public void updateString(int columnIndex, String x) throws SQLException { 455 checkOpen(); 456 } 457 458 public void updateBytes(int columnIndex, byte x[]) throws SQLException { 459 checkOpen(); 460 } 461 462 public void updateDate(int columnIndex, java.sql.Date x) throws SQLException { 463 checkOpen(); 464 } 465 466 public void updateTime(int columnIndex, java.sql.Time x) throws SQLException { 467 checkOpen(); 468 } 469 470 public void updateTimestamp(int columnIndex, java.sql.Timestamp x) throws SQLException { 471 checkOpen(); 472 } 473 474 475 public void updateAsciiStream(int columnIndex, 476 java.io.InputStream x, 477 int length) throws SQLException { 478 checkOpen(); 479 } 480 481 public void updateBinaryStream(int columnIndex, 482 java.io.InputStream x, 483 int length) throws SQLException { 484 checkOpen(); 485 } 486 487 public void updateCharacterStream(int columnIndex, 488 java.io.Reader x, 489 int length) throws SQLException { 490 checkOpen(); 491 } 492 493 public void updateObject(int columnIndex, Object x, int scale) 494 throws SQLException { 495 checkOpen(); 496 } 497 498 public void updateObject(int columnIndex, Object x) throws SQLException { 499 checkOpen(); 500 } 501 502 public void updateNull(String columnName) throws SQLException { 503 checkOpen(); 504 } 505 506 public void updateBoolean(String columnName, boolean x) throws SQLException { 507 checkOpen(); 508 } 509 510 public void updateByte(String columnName, byte x) throws SQLException { 511 checkOpen(); 512 } 513 514 public void updateShort(String columnName, short x) throws SQLException { 515 checkOpen(); 516 } 517 518 public void updateInt(String columnName, int x) throws SQLException { 519 checkOpen(); 520 } 521 522 public void updateLong(String columnName, long x) throws SQLException { 523 checkOpen(); 524 } 525 526 public void updateFloat(String columnName, float x) throws SQLException { 527 checkOpen(); 528 } 529 530 public void updateDouble(String columnName, double x) throws SQLException { 531 checkOpen(); 532 } 533 534 public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { 535 checkOpen(); 536 } 537 538 public void updateString(String columnName, String x) throws SQLException { 539 checkOpen(); 540 } 541 542 public void updateBytes(String columnName, byte x[]) throws SQLException { 543 checkOpen(); 544 } 545 546 public void updateDate(String columnName, java.sql.Date x) throws SQLException { 547 checkOpen(); 548 } 549 550 public void updateTime(String columnName, java.sql.Time x) throws SQLException { 551 checkOpen(); 552 } 553 554 public void updateTimestamp(String columnName, java.sql.Timestamp x) 555 throws SQLException { 556 checkOpen(); 557 } 558 559 public void updateAsciiStream(String columnName, 560 java.io.InputStream x, 561 int length) throws SQLException { 562 checkOpen(); 563 } 564 565 public void updateBinaryStream(String columnName, 566 java.io.InputStream x, 567 int length) throws SQLException { 568 checkOpen(); 569 } 570 571 public void updateCharacterStream(String columnName, 572 java.io.Reader reader, 573 int length) throws SQLException { 574 checkOpen(); 575 } 576 577 public void updateObject(String columnName, Object x, int scale) 578 throws SQLException { 579 checkOpen(); 580 } 581 582 public void updateObject(String columnName, Object x) throws SQLException { 583 checkOpen(); 584 } 585 586 public void insertRow() throws SQLException { 587 checkOpen(); 588 } 589 590 public void updateRow() throws SQLException { 591 checkOpen(); 592 } 593 594 public void deleteRow() throws SQLException { 595 checkOpen(); 596 } 597 598 public void refreshRow() throws SQLException { 599 checkOpen(); 600 } 601 602 public void cancelRowUpdates() throws SQLException { 603 checkOpen(); 604 } 605 606 public void moveToInsertRow() throws SQLException { 607 checkOpen(); 608 } 609 610 public void moveToCurrentRow() throws SQLException { 611 checkOpen(); 612 } 613 614 public Statement getStatement() throws SQLException { 615 checkOpen(); 616 return _statement; 617 } 618 619 620 public Object getObject(int i, java.util.Map map) throws SQLException { 621 checkOpen(); 622 return new Object (); 623 } 624 625 public Ref getRef(int i) throws SQLException { 626 checkOpen(); 627 return null; 628 } 629 630 public Blob getBlob(int i) throws SQLException { 631 checkOpen(); 632 return null; 633 } 634 635 public Clob getClob(int i) throws SQLException { 636 checkOpen(); 637 return null; 638 } 639 640 public Array getArray(int i) throws SQLException { 641 checkOpen(); 642 return null; 643 } 644 645 public Object getObject(String colName, java.util.Map map) throws SQLException { 646 checkOpen(); 647 return colName; 648 } 649 650 public Ref getRef(String colName) throws SQLException { 651 checkOpen(); 652 return null; 653 } 654 655 public Blob getBlob(String colName) throws SQLException { 656 checkOpen(); 657 return null; 658 } 659 660 public Clob getClob(String colName) throws SQLException { 661 checkOpen(); 662 return null; 663 } 664 665 public Array getArray(String colName) throws SQLException { 666 checkOpen(); 667 return null; 668 } 669 670 public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException { 671 checkOpen(); 672 return null; 673 } 674 675 public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException { 676 checkOpen(); 677 return null; 678 } 679 680 public java.sql.Time getTime(int columnIndex, Calendar cal) throws SQLException { 681 checkOpen(); 682 return null; 683 } 684 685 public java.sql.Time getTime(String columnName, Calendar cal) throws SQLException { 686 checkOpen(); 687 return null; 688 } 689 690 public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { 691 checkOpen(); 692 return null; 693 } 694 695 public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) 696 throws SQLException { 697 checkOpen(); 698 return null; 699 } 700 701 protected void checkOpen() throws SQLException { 702 if(!_open) { 703 throw new SQLException ("ResultSet is closed."); 704 } 705 } 706 707 710 711 712 public java.net.URL getURL(int columnIndex) throws SQLException { 713 throw new SQLException ("Not implemented."); 714 } 715 716 public java.net.URL getURL(String columnName) throws SQLException { 717 throw new SQLException ("Not implemented."); 718 } 719 720 public void updateRef(int columnIndex, java.sql.Ref x) 721 throws SQLException { 722 throw new SQLException ("Not implemented."); 723 } 724 725 public void updateRef(String columnName, java.sql.Ref x) 726 throws SQLException { 727 throw new SQLException ("Not implemented."); 728 } 729 730 public void updateBlob(int columnIndex, java.sql.Blob x) 731 throws SQLException { 732 throw new SQLException ("Not implemented."); 733 } 734 735 public void updateBlob(String columnName, java.sql.Blob x) 736 throws SQLException { 737 throw new SQLException ("Not implemented."); 738 } 739 740 public void updateClob(int columnIndex, java.sql.Clob x) 741 throws SQLException { 742 throw new SQLException ("Not implemented."); 743 } 744 745 public void updateClob(String columnName, java.sql.Clob x) 746 throws SQLException { 747 throw new SQLException ("Not implemented."); 748 } 749 750 public void updateArray(int columnIndex, java.sql.Array x) 751 throws SQLException { 752 throw new SQLException ("Not implemented."); 753 } 754 755 public void updateArray(String columnName, java.sql.Array x) 756 throws SQLException { 757 throw new SQLException ("Not implemented."); 758 } 759 760 761 762 } 763 | Popular Tags |