1 29 package com.caucho.db.jdbc; 30 31 import com.caucho.sql.SQLExceptionWrapper; 32 import com.caucho.util.L10N; 33 34 import java.io.IOException ; 35 import java.io.InputStream ; 36 import java.io.Reader ; 37 import java.math.BigDecimal ; 38 import java.sql.*; 39 import java.util.Calendar ; 40 import java.util.Map ; 41 42 45 abstract public class AbstractResultSet implements java.sql.ResultSet { 46 protected final static L10N L = new L10N(AbstractResultSet.class); 47 private int _rowNumber; 48 49 public boolean absolute(int row) 50 { 51 return false; 52 } 53 54 public void afterLast() 55 { 56 } 57 58 public void beforeFirst() 59 { 60 } 61 62 public void cancelRowUpdates() 63 { 64 } 65 66 public void clearWarnings() 67 { 68 } 69 70 public void deleteRow() 71 { 72 } 73 74 public int getRow() 75 throws SQLException 76 { 77 if (_rowNumber < 0) 78 throw new SQLException("can't call getRow() after close()"); 79 80 return _rowNumber; 81 } 82 83 public boolean isBeforeFirst() 84 throws SQLException 85 { 86 return _rowNumber == 0; 87 } 88 89 public boolean isAfterLast() 90 { 91 return false; 92 } 93 94 public boolean isFirst() 95 throws SQLException 96 { 97 return _rowNumber == 1; 98 } 99 100 public boolean first() 101 throws SQLException 102 { 103 return isFirst(); 104 } 105 106 public boolean isLast() 107 throws SQLException 108 { 109 return false; 110 } 111 112 public boolean last() 113 throws SQLException 114 { 115 return isLast(); 116 } 117 118 public int getConcurrency() 119 { 120 return 0; 121 } 122 123 public String getCursorName() 124 { 125 return null; 126 } 127 128 abstract public java.sql.Statement getStatement() 129 throws SQLException; 130 131 abstract public java.sql.ResultSetMetaData getMetaData() 132 throws SQLException; 133 134 abstract public boolean next() 135 throws SQLException; 136 137 abstract public boolean wasNull() 138 throws SQLException; 139 140 abstract public int findColumn(String columnName) 141 throws SQLException; 142 143 public int getType() 144 { 145 return 0; 146 } 147 148 public BigDecimal getBigDecimal(int columnIndex) 149 throws SQLException 150 { 151 return null; 152 } 153 154 public BigDecimal getBigDecimal(int columnIndex, int scale) 155 throws SQLException 156 { 157 return getBigDecimal(columnIndex).setScale(scale); 158 } 159 160 public BigDecimal getBigDecimal(String columnName) 161 throws SQLException 162 { 163 return getBigDecimal(findColumn(columnName)); 164 } 165 166 public BigDecimal getBigDecimal(String columnName, int scale) 167 throws SQLException 168 { 169 return getBigDecimal(findColumn(columnName), scale); 170 } 171 172 175 public boolean getBoolean(int columnIndex) 176 throws SQLException 177 { 178 String v = getString(columnIndex); 179 180 return (v != null && ! v.equals("") && ! v.equals("0") && ! v.equals("n")); 181 } 182 183 186 public boolean getBoolean(String columnName) 187 throws SQLException 188 { 189 return getBoolean(findColumn(columnName)); 190 } 191 192 public byte getByte(int columnIndex) 193 throws SQLException 194 { 195 return (byte) getInt(columnIndex); 196 } 197 198 public byte getByte(String columnName) 199 throws SQLException 200 { 201 return getByte(findColumn(columnName)); 202 } 203 204 207 public byte []getBytes(int columnIndex) 208 throws SQLException 209 { 210 try { 211 Blob blob = getBlob(columnIndex); 212 213 if (blob == null) 214 return null; 215 216 int length = (int) blob.length(); 217 218 byte []bytes = new byte[length]; 219 220 InputStream is = blob.getBinaryStream(); 221 222 try { 223 int offset = 0; 224 int sublen; 225 226 while (length > 0 && (sublen = is.read(bytes, offset, length)) > 0) { 227 offset += sublen; 228 length -= sublen; 229 } 230 } finally { 231 is.close(); 232 } 233 234 return bytes; 235 } catch (IOException e) { 236 throw new SQLExceptionWrapper(e); 237 } 238 } 239 240 public byte []getBytes(String columnName) 241 throws SQLException 242 { 243 return getBytes(findColumn(columnName)); 244 } 245 246 public Reader getCharacterStream(int columnIndex) 247 throws SQLException 248 { 249 throw new UnsupportedOperationException (); 250 } 251 252 public Reader getCharacterStream(String columnName) 253 throws SQLException 254 { 255 return getCharacterStream(findColumn(columnName)); 256 } 257 258 public java.sql.Date getDate(int columnIndex) 259 throws SQLException 260 { 261 throw new UnsupportedOperationException (); 262 } 263 264 public java.sql.Date getDate(String columnName) 265 throws SQLException 266 { 267 return getDate(findColumn(columnName)); 268 } 269 270 public java.sql.Date getDate(int columnIndex, Calendar cal) 271 throws SQLException 272 { 273 return getDate(columnIndex); 274 } 275 276 public java.sql.Date getDate(String columnName, Calendar cal) 277 throws SQLException 278 { 279 return getDate(findColumn(columnName), cal); 280 } 281 282 285 public double getDouble(int columnIndex) 286 throws SQLException 287 { 288 String v = getString(columnIndex); 289 290 if (v == null) 291 return 0; 292 else 293 return Double.parseDouble(v); 294 } 295 296 299 public double getDouble(String columnName) 300 throws SQLException 301 { 302 return getDouble(findColumn(columnName)); 303 } 304 305 public int getFetchDirection() 306 { 307 return 0; 308 } 309 310 public int getFetchSize() 311 { 312 return 0; 313 } 314 315 318 public float getFloat(int columnIndex) 319 throws SQLException 320 { 321 return (float) getDouble(columnIndex); 322 } 323 324 327 public float getFloat(String columnName) 328 throws SQLException 329 { 330 return (float) getDouble(findColumn(columnName)); 331 } 332 333 336 public int getInt(int columnIndex) 337 throws SQLException 338 { 339 String v = getString(columnIndex); 340 341 if (v == null) 342 return 0; 343 else 344 return Integer.parseInt(v); 345 } 346 347 350 public int getInt(String columnName) 351 throws SQLException 352 { 353 return getInt(findColumn(columnName)); 354 } 355 356 359 public long getLong(int columnIndex) 360 throws SQLException 361 { 362 String v = getString(columnIndex); 363 364 if (v == null) 365 return 0; 366 else 367 return Long.parseLong(v); 368 } 369 370 373 public long getLong(String columnName) 374 throws SQLException 375 { 376 return getLong(findColumn(columnName)); 377 } 378 379 public Object getObject(int columnIndex) 380 throws SQLException 381 { 382 return getString(columnIndex); 383 } 384 385 public Object getObject(String columnName) 386 throws SQLException 387 { 388 return getObject(findColumn(columnName)); 389 } 390 391 public Object getObject(int columnIndex, Map <String ,Class <?>> map) 392 throws SQLException 393 { 394 return getObject(columnIndex); 395 } 396 397 public Object getObject(String columnName, Map <String ,Class <?>> map) 398 throws SQLException 399 { 400 return getObject(findColumn(columnName), map); 401 } 402 403 public short getShort(int columnIndex) 404 throws SQLException 405 { 406 return (short) getInt(columnIndex); 407 } 408 409 public short getShort(String columnName) 410 throws SQLException 411 { 412 return getShort(findColumn(columnName)); 413 } 414 415 abstract public String getString(int columnIndex) 416 throws SQLException; 417 418 public String getString(String columnName) 419 throws SQLException 420 { 421 return getString(findColumn(columnName)); 422 } 423 424 public Time getTime(int columnIndex) 425 throws SQLException 426 { 427 throw new UnsupportedOperationException (); 428 } 429 430 public Time getTime(String columnName) 431 throws SQLException 432 { 433 return getTime(findColumn(columnName)); 434 } 435 436 public Time getTime(int columnIndex, Calendar calendar) 437 throws SQLException 438 { 439 return getTime(columnIndex); 440 } 441 442 public Time getTime(String columnName, Calendar calendar) 443 throws SQLException 444 { 445 return getTime(findColumn(columnName), calendar); 446 } 447 448 public Timestamp getTimestamp(int columnIndex) 449 throws SQLException 450 { 451 throw new UnsupportedOperationException (); 452 } 453 454 public Timestamp getTimestamp(String columnName) 455 throws SQLException 456 { 457 return getTimestamp(findColumn(columnName)); 458 } 459 460 public Timestamp getTimestamp(int columnIndex, Calendar calendar) 461 throws SQLException 462 { 463 return getTimestamp(columnIndex); 464 } 465 466 public Timestamp getTimestamp(String columnName, Calendar calendar) 467 throws SQLException 468 { 469 return getTimestamp(findColumn(columnName), calendar); 470 } 471 472 public InputStream getBinaryStream(int columnIndex) 473 throws SQLException 474 { 475 Blob blob = getBlob(columnIndex); 476 477 if (blob != null) 478 return blob.getBinaryStream(); 479 else 480 return null; 481 } 482 483 public InputStream getBinaryStream(String columnName) 484 throws SQLException 485 { 486 return getBinaryStream(findColumn(columnName)); 487 } 488 489 public InputStream getAsciiStream(int columnIndex) 490 throws SQLException 491 { 492 return getBinaryStream(columnIndex); 493 } 494 495 public InputStream getAsciiStream(String columnName) 496 throws SQLException 497 { 498 return getAsciiStream(findColumn(columnName)); 499 } 500 501 public InputStream getUnicodeStream(int columnIndex) 502 throws SQLException 503 { 504 throw new UnsupportedOperationException (); 505 } 506 507 public InputStream getUnicodeStream(String columnName) 508 throws SQLException 509 { 510 return getUnicodeStream(findColumn(columnName)); 511 } 512 513 public Array getArray(int columnIndex) 514 throws SQLException 515 { 516 throw new UnsupportedOperationException (); 517 } 518 519 public Array getArray(String columnName) 520 throws SQLException 521 { 522 return getArray(findColumn(columnName)); 523 } 524 525 public Blob getBlob(int columnIndex) 526 throws SQLException 527 { 528 throw new UnsupportedOperationException (); 529 } 530 531 public Blob getBlob(String columnName) 532 throws SQLException 533 { 534 return getBlob(findColumn(columnName)); 535 } 536 537 public Clob getClob(int columnIndex) 538 throws SQLException 539 { 540 throw new UnsupportedOperationException (); 541 } 542 543 public Clob getClob(String columnName) 544 throws SQLException 545 { 546 return getClob(findColumn(columnName)); 547 } 548 549 public Ref getRef(int columnIndex) 550 throws SQLException 551 { 552 throw new UnsupportedOperationException (); 553 } 554 555 public Ref getRef(String columnName) 556 throws SQLException 557 { 558 return getRef(findColumn(columnName)); 559 } 560 561 public SQLWarning getWarnings() 562 { 563 return null; 564 } 565 566 public void insertRow() 567 { 568 } 569 570 public void moveToCurrentRow() 571 { 572 } 573 574 public void moveToInsertRow() 575 { 576 } 577 578 public boolean previous() 579 { 580 return false; 581 } 582 583 public void refreshRow() 584 { 585 } 586 587 public boolean relative(int rows) 588 { 589 return false; 590 } 591 592 public boolean rowDeleted() 593 { 594 return false; 595 } 596 597 public boolean rowInserted() 598 { 599 return false; 600 } 601 602 public boolean rowUpdated() 603 { 604 return false; 605 } 606 607 public void setFetchDirection(int direction) 608 { 609 } 610 611 public void setFetchSize(int rows) 612 { 613 } 614 615 public void updateRow() 616 { 617 } 618 619 public void updateObject(int columnIndex, Object o) 620 { 621 } 622 623 public void updateObject(String columnName, Object o) 624 throws SQLException 625 { 626 updateObject(findColumn(columnName), o); 627 } 628 629 public void updateObject(int columnIndex, Object o, int scale) 630 { 631 } 632 633 public void updateObject(String columnName, Object o, int scale) 634 throws SQLException 635 { 636 updateObject(findColumn(columnName), o, scale); 637 } 638 639 public void updateNull(int columnIndex) 640 { 641 } 642 643 public void updateNull(String columnName) 644 throws SQLException 645 { 646 updateNull(findColumn(columnName)); 647 } 648 649 public void updateAsciiStream(int columnIndex, InputStream x, int length) 650 { 651 } 652 653 public void updateAsciiStream(String columnName, InputStream x, int length) 654 throws SQLException 655 { 656 updateAsciiStream(findColumn(columnName), x, length); 657 } 658 659 public void updateBigDecimal(int columnIndex, BigDecimal x) 660 { 661 } 662 663 public void updateBigDecimal(String columnName, BigDecimal x) 664 throws SQLException 665 { 666 updateBigDecimal(findColumn(columnName), x); 667 } 668 669 public void updateBinaryStream(int columnIndex, InputStream x, int length) 670 { 671 } 672 673 public void updateBinaryStream(String columnName, InputStream x, int length) 674 throws SQLException 675 { 676 updateBinaryStream(findColumn(columnName), x, length); 677 } 678 679 public void updateBoolean(int columnIndex, boolean x) 680 { 681 } 682 683 public void updateBoolean(String columnName, boolean x) 684 throws SQLException 685 { 686 updateBoolean(findColumn(columnName), x); 687 } 688 689 public void updateByte(int columnIndex, byte x) 690 { 691 } 692 693 public void updateByte(String columnName, byte x) 694 throws SQLException 695 { 696 updateByte(findColumn(columnName), x); 697 } 698 699 public void updateShort(int columnIndex, short x) 700 { 701 } 702 703 public void updateShort(String columnName, short x) 704 throws SQLException 705 { 706 updateShort(findColumn(columnName), x); 707 } 708 709 public void updateInt(int columnIndex, int x) 710 { 711 } 712 713 public void updateInt(String columnName, int x) 714 throws SQLException 715 { 716 updateInt(findColumn(columnName), x); 717 } 718 719 public void updateLong(int columnIndex, long x) 720 { 721 } 722 723 public void updateLong(String columnName, long x) 724 throws SQLException 725 { 726 updateLong(findColumn(columnName), x); 727 } 728 729 public void updateFloat(int columnIndex, float x) 730 { 731 } 732 733 public void updateFloat(String columnName, float x) 734 throws SQLException 735 { 736 updateFloat(findColumn(columnName), x); 737 } 738 739 public void updateDouble(int columnIndex, double x) 740 { 741 } 742 743 public void updateDouble(String columnName, double x) 744 throws SQLException 745 { 746 updateDouble(findColumn(columnName), x); 747 } 748 749 public void updateString(int columnIndex, String x) 750 { 751 } 752 753 public void updateString(String columnName, String x) 754 throws SQLException 755 { 756 updateString(findColumn(columnName), x); 757 } 758 759 public void updateBytes(int columnIndex, byte[] x) 760 { 761 } 762 763 public void updateBytes(String columnName, byte[] x) 764 throws SQLException 765 { 766 updateBytes(findColumn(columnName), x); 767 } 768 769 public void updateCharacterStream(int columnIndex, Reader x, int length) 770 { 771 } 772 773 public void updateCharacterStream(String columnName, Reader x, int length) 774 throws SQLException 775 { 776 updateCharacterStream(findColumn(columnName), x, length); 777 } 778 779 public void updateTime(int columnIndex, Time time) 780 throws SQLException 781 { 782 } 783 784 public void updateTime(String columnName, Time time) 785 throws SQLException 786 { 787 updateTime(findColumn(columnName), time); 788 } 789 790 public void updateDate(int columnIndex, java.sql.Date date) 791 throws SQLException 792 { 793 } 794 795 public void updateDate(String columnName, java.sql.Date date) 796 throws SQLException 797 { 798 updateDate(findColumn(columnName), date); 799 } 800 801 public void updateTimestamp(int columnIndex, Timestamp time) 802 throws SQLException 803 { 804 } 805 806 public void updateTimestamp(String columnName, Timestamp time) 807 throws SQLException 808 { 809 updateTimestamp(findColumn(columnName), time); 810 } 811 812 public void updateArray(int columnIndex, Array value) 813 throws SQLException 814 { 815 throw new UnsupportedOperationException (); 816 } 817 818 public void updateArray(String columnName, Array value) 819 throws SQLException 820 { 821 updateArray(findColumn(columnName), value); 822 } 823 824 public void updateBlob(int columnIndex, Blob value) 825 throws SQLException 826 { 827 throw new UnsupportedOperationException (); 828 } 829 830 public void updateBlob(String columnName, Blob value) 831 throws SQLException 832 { 833 updateBlob(findColumn(columnName), value); 834 } 835 836 public void updateClob(int columnIndex, Clob value) 837 throws SQLException 838 { 839 throw new UnsupportedOperationException (); 840 } 841 842 public void updateClob(String columnName, Clob value) 843 throws SQLException 844 { 845 updateClob(findColumn(columnName), value); 846 } 847 848 public void updateRef(int columnIndex, Ref value) 849 throws SQLException 850 { 851 throw new UnsupportedOperationException (); 852 } 853 854 public void updateRef(String columnName, Ref value) 855 throws SQLException 856 { 857 updateRef(findColumn(columnName), value); 858 } 859 860 public java.net.URL getURL(int column) 861 throws SQLException 862 { 863 throw new UnsupportedOperationException (); 864 } 865 866 public java.net.URL getURL(String column) 867 throws SQLException 868 { 869 return getURL(findColumn(column)); 870 } 871 872 public void close() 873 throws SQLException 874 { 875 } 876 } 877 | Popular Tags |