1 61 62 package org.apache.commons.dbutils.wrappers; 63 64 import java.io.ByteArrayInputStream ; 65 import java.io.CharArrayReader ; 66 import java.io.InputStream ; 67 import java.io.OutputStream ; 68 import java.io.Reader ; 69 import java.io.Writer ; 70 import java.lang.reflect.InvocationHandler ; 71 import java.lang.reflect.Method ; 72 import java.math.BigDecimal ; 73 import java.net.MalformedURLException ; 74 import java.net.URL ; 75 import java.sql.Blob ; 76 import java.sql.Clob ; 77 import java.sql.Ref ; 78 import java.sql.ResultSet ; 79 import java.sql.SQLException ; 80 import java.sql.Time ; 81 import java.sql.Timestamp ; 82 import java.util.Calendar ; 83 import java.util.Map ; 84 85 import org.apache.commons.dbutils.BaseTestCase; 86 import org.apache.commons.dbutils.ProxyFactory; 87 88 95 public class SqlNullCheckedResultSetTest extends BaseTestCase { 96 97 private ResultSet rs = null; 98 99 private SqlNullCheckedResultSet rs2 = null; 100 101 108 public SqlNullCheckedResultSetTest(String name) { 109 super(name); 110 } 111 112 115 public void setUp() throws Exception { 116 super.setUp(); 117 118 rs2 = 119 new SqlNullCheckedResultSet( 120 ProxyFactory.instance().createResultSet( 121 new SqlNullUncheckedMockResultSet())); 122 123 rs = ProxyFactory.instance().createResultSet(rs2); 124 } 125 126 129 public void testGetAsciiStream() throws SQLException { 130 131 assertNull(rs.getAsciiStream(1)); 132 assertTrue(rs.wasNull()); 133 assertNull(rs.getAsciiStream("column")); 134 assertTrue(rs.wasNull()); 135 InputStream stream = new ByteArrayInputStream (new byte[0]); 137 rs2.setNullAsciiStream(stream); 138 assertNotNull(rs.getAsciiStream(1)); 139 assertEquals(stream, rs.getAsciiStream(1)); 140 assertNotNull(rs.getAsciiStream("column")); 141 assertEquals(stream, rs.getAsciiStream("column")); 142 143 } 144 145 148 public void testGetBigDecimal() throws SQLException { 149 150 assertNull(rs.getBigDecimal(1)); 151 assertTrue(rs.wasNull()); 152 assertNull(rs.getBigDecimal("column")); 153 assertTrue(rs.wasNull()); 154 BigDecimal bd = new BigDecimal (5.0); 156 rs2.setNullBigDecimal(bd); 157 assertNotNull(rs.getBigDecimal(1)); 158 assertEquals(bd, rs.getBigDecimal(1)); 159 assertNotNull(rs.getBigDecimal("column")); 160 assertEquals(bd, rs.getBigDecimal("column")); 161 162 } 163 164 167 public void testGetBinaryStream() throws SQLException { 168 169 assertNull(rs.getBinaryStream(1)); 170 assertTrue(rs.wasNull()); 171 assertNull(rs.getBinaryStream("column")); 172 assertTrue(rs.wasNull()); 173 InputStream stream = new ByteArrayInputStream (new byte[0]); 175 rs2.setNullBinaryStream(stream); 176 assertNotNull(rs.getBinaryStream(1)); 177 assertEquals(stream, rs.getBinaryStream(1)); 178 assertNotNull(rs.getBinaryStream("column")); 179 assertEquals(stream, rs.getBinaryStream("column")); 180 181 } 182 183 186 public void testGetBlob() throws SQLException { 187 188 assertNull(rs.getBlob(1)); 189 assertTrue(rs.wasNull()); 190 assertNull(rs.getBlob("column")); 191 assertTrue(rs.wasNull()); 192 Blob blob = new SqlNullCheckedResultSetMockBlob(); 194 rs2.setNullBlob(blob); 195 assertNotNull(rs.getBlob(1)); 196 assertEquals(blob, rs.getBlob(1)); 197 assertNotNull(rs.getBlob("column")); 198 assertEquals(blob, rs.getBlob("column")); 199 200 } 201 202 205 public void testGetBoolean() throws SQLException { 206 207 assertEquals(false, rs.getBoolean(1)); 208 assertTrue(rs.wasNull()); 209 assertEquals(false, rs.getBoolean("column")); 210 assertTrue(rs.wasNull()); 211 rs2.setNullBoolean(true); 213 assertEquals(true, rs.getBoolean(1)); 214 assertEquals(true, rs.getBoolean("column")); 215 216 } 217 218 221 public void testGetByte() throws SQLException { 222 223 assertEquals((byte) 0, rs.getByte(1)); 224 assertTrue(rs.wasNull()); 225 assertEquals((byte) 0, rs.getByte("column")); 226 assertTrue(rs.wasNull()); 227 byte b = (byte) 10; 229 rs2.setNullByte(b); 230 assertEquals(b, rs.getByte(1)); 231 assertEquals(b, rs.getByte("column")); 232 233 } 234 235 238 public void testGetBytes() throws SQLException { 239 240 assertNull(rs.getBytes(1)); 241 assertTrue(rs.wasNull()); 242 assertNull(rs.getBytes("column")); 243 assertTrue(rs.wasNull()); 244 byte[] b = new byte[5]; 246 for (int i = 0; i < 5; i++) { 247 b[0] = (byte) i; 248 } 249 rs2.setNullBytes(b); 250 assertNotNull(rs.getBytes(1)); 251 assertEquals(b, rs.getBytes(1)); 252 assertNotNull(rs.getBytes("column")); 253 assertEquals(b, rs.getBytes("column")); 254 255 } 256 257 260 public void testGetCharacterStream() throws SQLException { 261 262 assertNull(rs.getCharacterStream(1)); 263 assertTrue(rs.wasNull()); 264 assertNull(rs.getCharacterStream("column")); 265 assertTrue(rs.wasNull()); 266 Reader reader = new CharArrayReader ("this is a string".toCharArray()); 268 rs2.setNullCharacterStream(reader); 269 assertNotNull(rs.getCharacterStream(1)); 270 assertEquals(reader, rs.getCharacterStream(1)); 271 assertNotNull(rs.getCharacterStream("column")); 272 assertEquals(reader, rs.getCharacterStream("column")); 273 274 } 275 276 279 public void testGetClob() throws SQLException { 280 281 assertNull(rs.getClob(1)); 282 assertTrue(rs.wasNull()); 283 assertNull(rs.getClob("column")); 284 assertTrue(rs.wasNull()); 285 Clob clob = new SqlNullCheckedResultSetMockClob(); 287 rs2.setNullClob(clob); 288 assertNotNull(rs.getClob(1)); 289 assertEquals(clob, rs.getClob(1)); 290 assertNotNull(rs.getClob("column")); 291 assertEquals(clob, rs.getClob("column")); 292 293 } 294 295 298 public void testGetDate() throws SQLException { 299 300 assertNull(rs.getDate(1)); 301 assertTrue(rs.wasNull()); 302 assertNull(rs.getDate("column")); 303 assertTrue(rs.wasNull()); 304 assertNull(rs.getDate(1, Calendar.getInstance())); 305 assertTrue(rs.wasNull()); 306 assertNull(rs.getDate("column", Calendar.getInstance())); 307 assertTrue(rs.wasNull()); 308 java.sql.Date date = new java.sql.Date (new java.util.Date ().getTime()); 310 rs2.setNullDate(date); 311 assertNotNull(rs.getDate(1)); 312 assertEquals(date, rs.getDate(1)); 313 assertNotNull(rs.getDate("column")); 314 assertEquals(date, rs.getDate("column")); 315 assertNotNull(rs.getDate(1, Calendar.getInstance())); 316 assertEquals(date, rs.getDate(1, Calendar.getInstance())); 317 assertNotNull(rs.getDate("column", Calendar.getInstance())); 318 assertEquals(date, rs.getDate("column", Calendar.getInstance())); 319 320 } 321 322 325 public void testGetDouble() throws SQLException { 326 327 assertEquals(0.0, rs.getDouble(1), 0.0); 328 assertTrue(rs.wasNull()); 329 assertEquals(0.0, rs.getDouble("column"), 0.0); 330 assertTrue(rs.wasNull()); 331 double d = 10.0; 333 rs2.setNullDouble(d); 334 assertEquals(d, rs.getDouble(1), 0.0); 335 assertEquals(d, rs.getDouble("column"), 0.0); 336 337 } 338 339 342 public void testGetFloat() throws SQLException { 343 344 assertEquals((float) 0, rs.getFloat(1), 0.0); 345 assertTrue(rs.wasNull()); 346 assertEquals((float) 0, rs.getFloat("column"), 0.0); 347 assertTrue(rs.wasNull()); 348 float f = (float) 10.0; 350 rs2.setNullFloat(f); 351 assertEquals(f, rs.getFloat(1), 0.0); 352 assertEquals(f, rs.getFloat("column"), 0.0); 353 354 } 355 356 359 public void testGetInt() throws SQLException { 360 361 assertEquals(0, rs.getInt(1)); 362 assertTrue(rs.wasNull()); 363 assertEquals(0, rs.getInt("column")); 364 assertTrue(rs.wasNull()); 365 int i = 10; 367 rs2.setNullInt(i); 368 assertEquals(i, rs.getInt(1)); 369 assertEquals(i, rs.getInt("column")); 370 371 } 372 373 376 public void testGetLong() throws SQLException { 377 378 assertEquals((long) 0, rs.getLong(1)); 379 assertTrue(rs.wasNull()); 380 assertEquals((long) 0, rs.getLong("column")); 381 assertTrue(rs.wasNull()); 382 long l = (long) 10; 384 rs2.setNullLong(l); 385 assertEquals(l, rs.getLong(1)); 386 assertEquals(l, rs.getLong("column")); 387 388 } 389 390 393 public void testGetObject() throws SQLException { 394 395 assertNull(rs.getObject(1)); 396 assertTrue(rs.wasNull()); 397 assertNull(rs.getObject("column")); 398 assertTrue(rs.wasNull()); 399 assertNull(rs.getObject(1, (Map ) null)); 400 assertTrue(rs.wasNull()); 401 assertNull(rs.getObject("column", (Map ) null)); 402 assertTrue(rs.wasNull()); 403 Object o = new Object (); 405 rs2.setNullObject(o); 406 assertNotNull(rs.getObject(1)); 407 assertEquals(o, rs.getObject(1)); 408 assertNotNull(rs.getObject("column")); 409 assertEquals(o, rs.getObject("column")); 410 assertNotNull(rs.getObject(1, (Map ) null)); 411 assertEquals(o, rs.getObject(1, (Map ) null)); 412 assertNotNull(rs.getObject("column", (Map ) null)); 413 assertEquals(o, rs.getObject("column", (Map ) null)); 414 415 } 416 417 420 public void testGetRef() throws SQLException { 421 422 assertNull(rs.getRef(1)); 423 assertTrue(rs.wasNull()); 424 assertNull(rs.getRef("column")); 425 assertTrue(rs.wasNull()); 426 Ref ref = new SqlNullCheckedResultSetMockRef(); 428 rs2.setNullRef(ref); 429 assertNotNull(rs.getRef(1)); 430 assertEquals(ref, rs.getRef(1)); 431 assertNotNull(rs.getRef("column")); 432 assertEquals(ref, rs.getRef("column")); 433 434 } 435 436 439 public void testGetShort() throws SQLException { 440 441 assertEquals((short) 0, rs.getShort(1)); 442 assertTrue(rs.wasNull()); 443 assertEquals((short) 0, rs.getShort("column")); 444 assertTrue(rs.wasNull()); 445 short s = (short) 10; 447 rs2.setNullShort(s); 448 assertEquals(s, rs.getShort(1)); 449 assertEquals(s, rs.getShort("column")); 450 } 451 452 455 public void testGetString() throws SQLException { 456 assertEquals(null, rs.getString(1)); 457 assertTrue(rs.wasNull()); 458 assertEquals(null, rs.getString("column")); 459 assertTrue(rs.wasNull()); 460 String s = "hello, world"; 462 rs2.setNullString(s); 463 assertEquals(s, rs.getString(1)); 464 assertEquals(s, rs.getString("column")); 465 } 466 467 470 public void testGetTime() throws SQLException { 471 472 assertNull(rs.getTime(1)); 473 assertTrue(rs.wasNull()); 474 assertNull(rs.getTime("column")); 475 assertTrue(rs.wasNull()); 476 assertNull(rs.getTime(1, Calendar.getInstance())); 477 assertTrue(rs.wasNull()); 478 assertNull(rs.getTime("column", Calendar.getInstance())); 479 assertTrue(rs.wasNull()); 480 Time time = new Time (new java.util.Date ().getTime()); 482 rs2.setNullTime(time); 483 assertNotNull(rs.getTime(1)); 484 assertEquals(time, rs.getTime(1)); 485 assertNotNull(rs.getTime("column")); 486 assertEquals(time, rs.getTime("column")); 487 assertNotNull(rs.getTime(1, Calendar.getInstance())); 488 assertEquals(time, rs.getTime(1, Calendar.getInstance())); 489 assertNotNull(rs.getTime("column", Calendar.getInstance())); 490 assertEquals(time, rs.getTime("column", Calendar.getInstance())); 491 492 } 493 494 497 public void testGetTimestamp() throws SQLException { 498 499 assertNull(rs.getTimestamp(1)); 500 assertTrue(rs.wasNull()); 501 assertNull(rs.getTimestamp("column")); 502 assertTrue(rs.wasNull()); 503 assertNull(rs.getTimestamp(1, Calendar.getInstance())); 504 assertTrue(rs.wasNull()); 505 assertNull(rs.getTimestamp("column", Calendar.getInstance())); 506 assertTrue(rs.wasNull()); 507 Timestamp ts = new Timestamp (new java.util.Date ().getTime()); 509 rs2.setNullTimestamp(ts); 510 assertNotNull(rs.getTimestamp(1)); 511 assertEquals(ts, rs.getTimestamp(1)); 512 assertNotNull(rs.getTimestamp("column")); 513 assertEquals(ts, rs.getTimestamp("column")); 514 assertNotNull(rs.getTimestamp(1, Calendar.getInstance())); 515 assertEquals(ts, rs.getTimestamp(1, Calendar.getInstance())); 516 assertNotNull(rs.getTimestamp("column", Calendar.getInstance())); 517 assertEquals(ts, rs.getTimestamp("column", Calendar.getInstance())); 518 } 519 520 523 public void testGetURL() throws SQLException , MalformedURLException { 524 assertEquals(null, rs.getURL(1)); 525 assertTrue(rs.wasNull()); 526 assertEquals(null, rs.getURL("column")); 527 assertTrue(rs.wasNull()); 528 URL u = new URL ("http://www.apache.org"); 530 rs2.setNullURL(u); 531 assertEquals(u, rs.getURL(1)); 532 assertEquals(u, rs.getURL("column")); 533 } 534 535 538 public void testSetNullAsciiStream() throws SQLException { 539 540 assertNull(rs2.getNullAsciiStream()); 541 InputStream stream = new ByteArrayInputStream (new byte[0]); 543 rs2.setNullAsciiStream(stream); 544 assertNotNull(rs.getAsciiStream(1)); 545 assertEquals(stream, rs.getAsciiStream(1)); 546 assertNotNull(rs.getAsciiStream("column")); 547 assertEquals(stream, rs.getAsciiStream("column")); 548 549 } 550 551 554 public void testSetNullBigDecimal() throws SQLException { 555 556 assertNull(rs2.getNullBigDecimal()); 557 BigDecimal bd = new BigDecimal (5.0); 559 rs2.setNullBigDecimal(bd); 560 assertNotNull(rs.getBigDecimal(1)); 561 assertEquals(bd, rs.getBigDecimal(1)); 562 assertNotNull(rs.getBigDecimal("column")); 563 assertEquals(bd, rs.getBigDecimal("column")); 564 565 } 566 567 570 public void testSetNullBinaryStream() throws SQLException { 571 572 assertNull(rs2.getNullBinaryStream()); 573 InputStream stream = new ByteArrayInputStream (new byte[0]); 575 rs2.setNullBinaryStream(stream); 576 assertNotNull(rs.getBinaryStream(1)); 577 assertEquals(stream, rs.getBinaryStream(1)); 578 assertNotNull(rs.getBinaryStream("column")); 579 assertEquals(stream, rs.getBinaryStream("column")); 580 581 } 582 583 586 public void testSetNullBlob() throws SQLException { 587 588 assertNull(rs2.getNullBlob()); 589 Blob blob = new SqlNullCheckedResultSetMockBlob(); 591 rs2.setNullBlob(blob); 592 assertNotNull(rs.getBlob(1)); 593 assertEquals(blob, rs.getBlob(1)); 594 assertNotNull(rs.getBlob("column")); 595 assertEquals(blob, rs.getBlob("column")); 596 597 } 598 599 602 public void testSetNullBoolean() throws SQLException { 603 604 assertEquals(false, rs2.getNullBoolean()); 605 rs2.setNullBoolean(true); 607 assertEquals(true, rs.getBoolean(1)); 608 assertEquals(true, rs.getBoolean("column")); 609 610 } 611 612 615 public void testSetNullByte() throws SQLException { 616 617 assertEquals((byte) 0, rs2.getNullByte()); 618 byte b = (byte) 10; 620 rs2.setNullByte(b); 621 assertEquals(b, rs.getByte(1)); 622 assertEquals(b, rs.getByte("column")); 623 624 } 625 626 629 public void testSetNullBytes() throws SQLException { 630 631 assertNull(rs2.getNullBytes()); 632 byte[] b = new byte[5]; 634 for (int i = 0; i < 5; i++) { 635 b[0] = (byte) i; 636 } 637 rs2.setNullBytes(b); 638 assertNotNull(rs.getBytes(1)); 639 assertEquals(b, rs.getBytes(1)); 640 assertNotNull(rs.getBytes("column")); 641 assertEquals(b, rs.getBytes("column")); 642 643 } 644 645 648 public void testSetNullCharacterStream() throws SQLException { 649 650 assertNull(rs2.getNullCharacterStream()); 651 Reader reader = new CharArrayReader ("this is a string".toCharArray()); 653 rs2.setNullCharacterStream(reader); 654 assertNotNull(rs.getCharacterStream(1)); 655 assertEquals(reader, rs.getCharacterStream(1)); 656 assertNotNull(rs.getCharacterStream("column")); 657 assertEquals(reader, rs.getCharacterStream("column")); 658 659 } 660 661 664 public void testSetNullClob() throws SQLException { 665 666 assertNull(rs2.getNullClob()); 667 Clob clob = new SqlNullCheckedResultSetMockClob(); 669 rs2.setNullClob(clob); 670 assertNotNull(rs.getClob(1)); 671 assertEquals(clob, rs.getClob(1)); 672 assertNotNull(rs.getClob("column")); 673 assertEquals(clob, rs.getClob("column")); 674 675 } 676 677 680 public void testSetNullDate() throws SQLException { 681 682 assertNull(rs2.getNullDate()); 683 java.sql.Date date = new java.sql.Date (new java.util.Date ().getTime()); 685 rs2.setNullDate(date); 686 assertNotNull(rs.getDate(1)); 687 assertEquals(date, rs.getDate(1)); 688 assertNotNull(rs.getDate("column")); 689 assertEquals(date, rs.getDate("column")); 690 assertNotNull(rs.getDate(1, Calendar.getInstance())); 691 assertEquals(date, rs.getDate(1, Calendar.getInstance())); 692 assertNotNull(rs.getDate("column", Calendar.getInstance())); 693 assertEquals(date, rs.getDate("column", Calendar.getInstance())); 694 695 } 696 697 700 public void testSetNullDouble() throws SQLException { 701 702 assertEquals((double) 0.0, rs2.getNullDouble(), 0.0); 703 double d = (double) 10.0; 705 rs2.setNullDouble(d); 706 assertEquals(d, rs.getDouble(1), 0.0); 707 assertEquals(d, rs.getDouble("column"), 0.0); 708 709 } 710 711 714 public void testSetNullFloat() throws SQLException { 715 716 assertEquals((float) 0.0, rs2.getNullFloat(), 0.0); 717 float f = (float) 10.0; 719 rs2.setNullFloat(f); 720 assertEquals(f, rs.getFloat(1), 0.0); 721 assertEquals(f, rs.getFloat("column"), 0.0); 722 723 } 724 725 728 public void testSetNullInt() throws SQLException { 729 730 assertEquals(0, rs2.getNullInt()); 731 assertEquals((int) 0, rs.getInt(1)); 732 assertTrue(rs.wasNull()); 733 assertEquals((int) 0, rs.getInt("column")); 734 assertTrue(rs.wasNull()); 735 int i = (int) 10; 737 rs2.setNullInt(i); 738 assertEquals(i, rs.getInt(1)); 739 assertEquals(i, rs.getInt("column")); 740 741 } 742 743 746 public void testSetNullLong() throws SQLException { 747 748 assertEquals((long) 0, rs2.getNullLong()); 749 long l = (long) 10; 751 rs2.setNullLong(l); 752 assertEquals(l, rs.getLong(1)); 753 assertEquals(l, rs.getLong("column")); 754 755 } 756 757 760 public void testSetNullObject() throws SQLException { 761 762 assertNull(rs2.getNullObject()); 763 Object o = new Object (); 765 rs2.setNullObject(o); 766 assertNotNull(rs.getObject(1)); 767 assertEquals(o, rs.getObject(1)); 768 assertNotNull(rs.getObject("column")); 769 assertEquals(o, rs.getObject("column")); 770 assertNotNull(rs.getObject(1, (Map ) null)); 771 assertEquals(o, rs.getObject(1, (Map ) null)); 772 assertNotNull(rs.getObject("column", (Map ) null)); 773 assertEquals(o, rs.getObject("column", (Map ) null)); 774 775 } 776 777 780 public void testSetNullShort() throws SQLException { 781 782 assertEquals((short) 0, rs2.getNullShort()); 783 short s = (short) 10; 785 rs2.setNullShort(s); 786 assertEquals(s, rs.getShort(1)); 787 assertEquals(s, rs.getShort("column")); 788 789 } 790 791 794 public void testSetNullString() throws SQLException { 795 assertEquals(null, rs2.getNullString()); 796 String s = "hello, world"; 798 rs2.setNullString(s); 799 assertEquals(s, rs.getString(1)); 800 assertEquals(s, rs.getString("column")); 801 } 802 803 806 public void testSetNullRef() throws SQLException { 807 assertNull(rs2.getNullRef()); 808 Ref ref = new SqlNullCheckedResultSetMockRef(); 810 rs2.setNullRef(ref); 811 assertNotNull(rs.getRef(1)); 812 assertEquals(ref, rs.getRef(1)); 813 assertNotNull(rs.getRef("column")); 814 assertEquals(ref, rs.getRef("column")); 815 } 816 817 820 public void testSetNullTime() throws SQLException { 821 assertEquals(null, rs2.getNullTime()); 822 Time time = new Time (new java.util.Date ().getTime()); 824 rs2.setNullTime(time); 825 assertNotNull(rs.getTime(1)); 826 assertEquals(time, rs.getTime(1)); 827 assertNotNull(rs.getTime("column")); 828 assertEquals(time, rs.getTime("column")); 829 assertNotNull(rs.getTime(1, Calendar.getInstance())); 830 assertEquals(time, rs.getTime(1, Calendar.getInstance())); 831 assertNotNull(rs.getTime("column", Calendar.getInstance())); 832 assertEquals(time, rs.getTime("column", Calendar.getInstance())); 833 } 834 835 838 public void testSetNullTimestamp() throws SQLException { 839 assertEquals(null, rs2.getNullTimestamp()); 840 Timestamp ts = new Timestamp (new java.util.Date ().getTime()); 842 rs2.setNullTimestamp(ts); 843 assertNotNull(rs.getTimestamp(1)); 844 assertEquals(ts, rs.getTimestamp(1)); 845 assertNotNull(rs.getTimestamp("column")); 846 assertEquals(ts, rs.getTimestamp("column")); 847 assertNotNull(rs.getTimestamp(1, Calendar.getInstance())); 848 assertEquals(ts, rs.getTimestamp(1, Calendar.getInstance())); 849 assertNotNull(rs.getTimestamp("column", Calendar.getInstance())); 850 assertEquals(ts, rs.getTimestamp("column", Calendar.getInstance())); 851 } 852 853 856 public void testSetNullURL() throws SQLException , MalformedURLException { 857 assertEquals(null, rs2.getNullURL()); 858 URL u = new URL ("http://jakarta.apache.org"); 860 rs2.setNullURL(u); 861 assertEquals(u, rs.getURL(1)); 862 assertEquals(u, rs.getURL("column")); 863 } 864 } 865 866 class SqlNullUncheckedMockResultSet implements InvocationHandler { 867 868 872 public Object invoke(Object proxy, Method method, Object [] args) 873 throws Throwable { 874 875 Class returnType = method.getReturnType(); 876 877 if (method.getName().equals("wasNull")) { 878 return Boolean.TRUE; 879 880 } else if (returnType.equals(Boolean.TYPE)) { 881 return Boolean.FALSE; 882 883 } else if (returnType.equals(Integer.TYPE)) { 884 return new Integer (0); 885 886 } else if (returnType.equals(Short.TYPE)) { 887 return new Short ((short) 0); 888 889 } else if (returnType.equals(Double.TYPE)) { 890 return new Double (0); 891 892 } else if (returnType.equals(Long.TYPE)) { 893 return new Long (0); 894 895 } else if (returnType.equals(Byte.TYPE)) { 896 return new Byte ((byte) 0); 897 898 } else if (returnType.equals(Float.TYPE)) { 899 return new Float (0); 900 901 } else { 902 return null; 903 } 904 } 905 } 906 907 class SqlNullCheckedResultSetMockBlob implements Blob { 908 909 public InputStream getBinaryStream() throws SQLException { 910 return new ByteArrayInputStream (new byte[0]); 911 } 912 913 public byte[] getBytes(long param, int param1) throws SQLException { 914 return new byte[0]; 915 } 916 917 public long length() throws SQLException { 918 return 0; 919 } 920 921 public long position(byte[] values, long param) throws SQLException { 922 return 0; 923 } 924 925 public long position(Blob blob, long param) throws SQLException { 926 return 0; 927 } 928 929 public void truncate(long len) throws SQLException { 930 931 } 932 933 public int setBytes(long pos, byte[] bytes) throws SQLException { 934 return 0; 935 } 936 937 public int setBytes(long pos, byte[] bytes, int offset, int len) 938 throws SQLException { 939 return 0; 940 } 941 942 public OutputStream setBinaryStream(long pos) throws SQLException { 943 return null; 944 } 945 946 } 947 948 class SqlNullCheckedResultSetMockClob implements Clob { 949 950 public InputStream getAsciiStream() throws SQLException { 951 return null; 952 } 953 954 public Reader getCharacterStream() throws SQLException { 955 return null; 956 } 957 958 public String getSubString(long param, int param1) throws SQLException { 959 return ""; 960 } 961 962 public long length() throws SQLException { 963 return 0; 964 } 965 966 public long position(Clob clob, long param) throws SQLException { 967 return 0; 968 } 969 970 public long position(String str, long param) throws SQLException { 971 return 0; 972 } 973 974 public void truncate(long len) throws SQLException { 975 976 } 977 978 public OutputStream setAsciiStream(long pos) throws SQLException { 979 return null; 980 } 981 982 public Writer setCharacterStream(long pos) throws SQLException { 983 return null; 984 } 985 986 public int setString(long pos, String str) throws SQLException { 987 return 0; 988 } 989 990 public int setString(long pos, String str, int offset, int len) 991 throws SQLException { 992 return 0; 993 } 994 995 } 996 997 class SqlNullCheckedResultSetMockRef implements Ref { 998 999 public String getBaseTypeName() throws SQLException { 1000 return ""; 1001 } 1002 1003 public Object getObject() throws SQLException { 1004 return null; 1005 } 1006 1007 public void setObject(Object value) throws SQLException { 1008 1009 } 1010 1011 public Object getObject(Map map) throws SQLException { 1012 return null; 1013 } 1014 1015} 1016 | Popular Tags |