1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.dbutils.wrappers;
18
19 import java.io.ByteArrayInputStream;
20 import java.io.CharArrayReader;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.io.Reader;
24 import java.io.Writer;
25 import java.lang.reflect.InvocationHandler;
26 import java.lang.reflect.Method;
27 import java.math.BigDecimal;
28 import java.net.MalformedURLException;
29 import java.net.URL;
30 import java.sql.Blob;
31 import java.sql.Clob;
32 import java.sql.Ref;
33 import java.sql.ResultSet;
34 import java.sql.SQLException;
35 import java.sql.Time;
36 import java.sql.Timestamp;
37 import java.util.Calendar;
38 import java.util.Map;
39
40 import org.apache.commons.dbutils.BaseTestCase;
41 import org.apache.commons.dbutils.ProxyFactory;
42
43
44
45
46 public class SqlNullCheckedResultSetTest extends BaseTestCase {
47
48 private ResultSet rs = null;
49
50 private SqlNullCheckedResultSet rs2 = null;
51
52
53
54
55 public void setUp() throws Exception {
56 super.setUp();
57
58 rs2 =
59 new SqlNullCheckedResultSet(
60 ProxyFactory.instance().createResultSet(
61 new SqlNullUncheckedMockResultSet()));
62
63 rs = ProxyFactory.instance().createResultSet(rs2);
64 }
65
66
67
68
69 public void testGetAsciiStream() throws SQLException {
70
71 assertNull(rs.getAsciiStream(1));
72 assertTrue(rs.wasNull());
73 assertNull(rs.getAsciiStream("column"));
74 assertTrue(rs.wasNull());
75
76 InputStream stream = new ByteArrayInputStream(new byte[0]);
77 rs2.setNullAsciiStream(stream);
78 assertNotNull(rs.getAsciiStream(1));
79 assertEquals(stream, rs.getAsciiStream(1));
80 assertNotNull(rs.getAsciiStream("column"));
81 assertEquals(stream, rs.getAsciiStream("column"));
82
83 }
84
85
86
87
88 public void testGetBigDecimal() throws SQLException {
89
90 assertNull(rs.getBigDecimal(1));
91 assertTrue(rs.wasNull());
92 assertNull(rs.getBigDecimal("column"));
93 assertTrue(rs.wasNull());
94
95 BigDecimal bd = new BigDecimal(5.0);
96 rs2.setNullBigDecimal(bd);
97 assertNotNull(rs.getBigDecimal(1));
98 assertEquals(bd, rs.getBigDecimal(1));
99 assertNotNull(rs.getBigDecimal("column"));
100 assertEquals(bd, rs.getBigDecimal("column"));
101
102 }
103
104
105
106
107 public void testGetBinaryStream() throws SQLException {
108
109 assertNull(rs.getBinaryStream(1));
110 assertTrue(rs.wasNull());
111 assertNull(rs.getBinaryStream("column"));
112 assertTrue(rs.wasNull());
113
114 InputStream stream = new ByteArrayInputStream(new byte[0]);
115 rs2.setNullBinaryStream(stream);
116 assertNotNull(rs.getBinaryStream(1));
117 assertEquals(stream, rs.getBinaryStream(1));
118 assertNotNull(rs.getBinaryStream("column"));
119 assertEquals(stream, rs.getBinaryStream("column"));
120
121 }
122
123
124
125
126 public void testGetBlob() throws SQLException {
127
128 assertNull(rs.getBlob(1));
129 assertTrue(rs.wasNull());
130 assertNull(rs.getBlob("column"));
131 assertTrue(rs.wasNull());
132
133 Blob blob = new SqlNullCheckedResultSetMockBlob();
134 rs2.setNullBlob(blob);
135 assertNotNull(rs.getBlob(1));
136 assertEquals(blob, rs.getBlob(1));
137 assertNotNull(rs.getBlob("column"));
138 assertEquals(blob, rs.getBlob("column"));
139
140 }
141
142
143
144
145 public void testGetBoolean() throws SQLException {
146
147 assertEquals(false, rs.getBoolean(1));
148 assertTrue(rs.wasNull());
149 assertEquals(false, rs.getBoolean("column"));
150 assertTrue(rs.wasNull());
151
152 rs2.setNullBoolean(true);
153 assertEquals(true, rs.getBoolean(1));
154 assertEquals(true, rs.getBoolean("column"));
155
156 }
157
158
159
160
161 public void testGetByte() throws SQLException {
162
163 assertEquals((byte) 0, rs.getByte(1));
164 assertTrue(rs.wasNull());
165 assertEquals((byte) 0, rs.getByte("column"));
166 assertTrue(rs.wasNull());
167
168 byte b = (byte) 10;
169 rs2.setNullByte(b);
170 assertEquals(b, rs.getByte(1));
171 assertEquals(b, rs.getByte("column"));
172
173 }
174
175
176
177
178 public void testGetBytes() throws SQLException {
179
180 assertNull(rs.getBytes(1));
181 assertTrue(rs.wasNull());
182 assertNull(rs.getBytes("column"));
183 assertTrue(rs.wasNull());
184
185 byte[] b = new byte[5];
186 for (int i = 0; i < 5; i++) {
187 b[0] = (byte) i;
188 }
189 rs2.setNullBytes(b);
190 assertNotNull(rs.getBytes(1));
191 assertEquals(b, rs.getBytes(1));
192 assertNotNull(rs.getBytes("column"));
193 assertEquals(b, rs.getBytes("column"));
194
195 }
196
197
198
199
200 public void testGetCharacterStream() throws SQLException {
201
202 assertNull(rs.getCharacterStream(1));
203 assertTrue(rs.wasNull());
204 assertNull(rs.getCharacterStream("column"));
205 assertTrue(rs.wasNull());
206
207 Reader reader = new CharArrayReader("this is a string".toCharArray());
208 rs2.setNullCharacterStream(reader);
209 assertNotNull(rs.getCharacterStream(1));
210 assertEquals(reader, rs.getCharacterStream(1));
211 assertNotNull(rs.getCharacterStream("column"));
212 assertEquals(reader, rs.getCharacterStream("column"));
213
214 }
215
216
217
218
219 public void testGetClob() throws SQLException {
220
221 assertNull(rs.getClob(1));
222 assertTrue(rs.wasNull());
223 assertNull(rs.getClob("column"));
224 assertTrue(rs.wasNull());
225
226 Clob clob = new SqlNullCheckedResultSetMockClob();
227 rs2.setNullClob(clob);
228 assertNotNull(rs.getClob(1));
229 assertEquals(clob, rs.getClob(1));
230 assertNotNull(rs.getClob("column"));
231 assertEquals(clob, rs.getClob("column"));
232
233 }
234
235
236
237
238 public void testGetDate() throws SQLException {
239
240 assertNull(rs.getDate(1));
241 assertTrue(rs.wasNull());
242 assertNull(rs.getDate("column"));
243 assertTrue(rs.wasNull());
244 assertNull(rs.getDate(1, Calendar.getInstance()));
245 assertTrue(rs.wasNull());
246 assertNull(rs.getDate("column", Calendar.getInstance()));
247 assertTrue(rs.wasNull());
248
249 java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
250 rs2.setNullDate(date);
251 assertNotNull(rs.getDate(1));
252 assertEquals(date, rs.getDate(1));
253 assertNotNull(rs.getDate("column"));
254 assertEquals(date, rs.getDate("column"));
255 assertNotNull(rs.getDate(1, Calendar.getInstance()));
256 assertEquals(date, rs.getDate(1, Calendar.getInstance()));
257 assertNotNull(rs.getDate("column", Calendar.getInstance()));
258 assertEquals(date, rs.getDate("column", Calendar.getInstance()));
259
260 }
261
262
263
264
265 public void testGetDouble() throws SQLException {
266
267 assertEquals(0.0, rs.getDouble(1), 0.0);
268 assertTrue(rs.wasNull());
269 assertEquals(0.0, rs.getDouble("column"), 0.0);
270 assertTrue(rs.wasNull());
271
272 double d = 10.0;
273 rs2.setNullDouble(d);
274 assertEquals(d, rs.getDouble(1), 0.0);
275 assertEquals(d, rs.getDouble("column"), 0.0);
276
277 }
278
279
280
281
282 public void testGetFloat() throws SQLException {
283 assertEquals(0, rs.getFloat(1), 0.0);
284 assertTrue(rs.wasNull());
285 assertEquals(0, rs.getFloat("column"), 0.0);
286 assertTrue(rs.wasNull());
287
288 float f = 10;
289 rs2.setNullFloat(f);
290 assertEquals(f, rs.getFloat(1), 0.0);
291 assertEquals(f, rs.getFloat("column"), 0.0);
292 }
293
294
295
296
297 public void testGetInt() throws SQLException {
298 assertEquals(0, rs.getInt(1));
299 assertTrue(rs.wasNull());
300 assertEquals(0, rs.getInt("column"));
301 assertTrue(rs.wasNull());
302
303 int i = 10;
304 rs2.setNullInt(i);
305 assertEquals(i, rs.getInt(1));
306 assertEquals(i, rs.getInt("column"));
307 }
308
309
310
311
312 public void testGetLong() throws SQLException {
313 assertEquals(0, rs.getLong(1));
314 assertTrue(rs.wasNull());
315 assertEquals(0, rs.getLong("column"));
316 assertTrue(rs.wasNull());
317
318 long l = 10;
319 rs2.setNullLong(l);
320 assertEquals(l, rs.getLong(1));
321 assertEquals(l, rs.getLong("column"));
322 }
323
324
325
326
327 public void testGetObject() throws SQLException {
328
329 assertNull(rs.getObject(1));
330 assertTrue(rs.wasNull());
331 assertNull(rs.getObject("column"));
332 assertTrue(rs.wasNull());
333 assertNull(rs.getObject(1, (Map) null));
334 assertTrue(rs.wasNull());
335 assertNull(rs.getObject("column", (Map) null));
336 assertTrue(rs.wasNull());
337
338 Object o = new Object();
339 rs2.setNullObject(o);
340 assertNotNull(rs.getObject(1));
341 assertEquals(o, rs.getObject(1));
342 assertNotNull(rs.getObject("column"));
343 assertEquals(o, rs.getObject("column"));
344 assertNotNull(rs.getObject(1, (Map) null));
345 assertEquals(o, rs.getObject(1, (Map) null));
346 assertNotNull(rs.getObject("column", (Map) null));
347 assertEquals(o, rs.getObject("column", (Map) null));
348
349 }
350
351
352
353
354 public void testGetRef() throws SQLException {
355
356 assertNull(rs.getRef(1));
357 assertTrue(rs.wasNull());
358 assertNull(rs.getRef("column"));
359 assertTrue(rs.wasNull());
360
361 Ref ref = new SqlNullCheckedResultSetMockRef();
362 rs2.setNullRef(ref);
363 assertNotNull(rs.getRef(1));
364 assertEquals(ref, rs.getRef(1));
365 assertNotNull(rs.getRef("column"));
366 assertEquals(ref, rs.getRef("column"));
367
368 }
369
370
371
372
373 public void testGetShort() throws SQLException {
374
375 assertEquals((short) 0, rs.getShort(1));
376 assertTrue(rs.wasNull());
377 assertEquals((short) 0, rs.getShort("column"));
378 assertTrue(rs.wasNull());
379
380 short s = (short) 10;
381 rs2.setNullShort(s);
382 assertEquals(s, rs.getShort(1));
383 assertEquals(s, rs.getShort("column"));
384 }
385
386
387
388
389 public void testGetString() throws SQLException {
390 assertEquals(null, rs.getString(1));
391 assertTrue(rs.wasNull());
392 assertEquals(null, rs.getString("column"));
393 assertTrue(rs.wasNull());
394
395 String s = "hello, world";
396 rs2.setNullString(s);
397 assertEquals(s, rs.getString(1));
398 assertEquals(s, rs.getString("column"));
399 }
400
401
402
403
404 public void testGetTime() throws SQLException {
405
406 assertNull(rs.getTime(1));
407 assertTrue(rs.wasNull());
408 assertNull(rs.getTime("column"));
409 assertTrue(rs.wasNull());
410 assertNull(rs.getTime(1, Calendar.getInstance()));
411 assertTrue(rs.wasNull());
412 assertNull(rs.getTime("column", Calendar.getInstance()));
413 assertTrue(rs.wasNull());
414
415 Time time = new Time(new java.util.Date().getTime());
416 rs2.setNullTime(time);
417 assertNotNull(rs.getTime(1));
418 assertEquals(time, rs.getTime(1));
419 assertNotNull(rs.getTime("column"));
420 assertEquals(time, rs.getTime("column"));
421 assertNotNull(rs.getTime(1, Calendar.getInstance()));
422 assertEquals(time, rs.getTime(1, Calendar.getInstance()));
423 assertNotNull(rs.getTime("column", Calendar.getInstance()));
424 assertEquals(time, rs.getTime("column", Calendar.getInstance()));
425
426 }
427
428
429
430
431 public void testGetTimestamp() throws SQLException {
432
433 assertNull(rs.getTimestamp(1));
434 assertTrue(rs.wasNull());
435 assertNull(rs.getTimestamp("column"));
436 assertTrue(rs.wasNull());
437 assertNull(rs.getTimestamp(1, Calendar.getInstance()));
438 assertTrue(rs.wasNull());
439 assertNull(rs.getTimestamp("column", Calendar.getInstance()));
440 assertTrue(rs.wasNull());
441
442 Timestamp ts = new Timestamp(new java.util.Date().getTime());
443 rs2.setNullTimestamp(ts);
444 assertNotNull(rs.getTimestamp(1));
445 assertEquals(ts, rs.getTimestamp(1));
446 assertNotNull(rs.getTimestamp("column"));
447 assertEquals(ts, rs.getTimestamp("column"));
448 assertNotNull(rs.getTimestamp(1, Calendar.getInstance()));
449 assertEquals(ts, rs.getTimestamp(1, Calendar.getInstance()));
450 assertNotNull(rs.getTimestamp("column", Calendar.getInstance()));
451 assertEquals(ts, rs.getTimestamp("column", Calendar.getInstance()));
452 }
453
454
455
456
457
458
459 public void testURL() throws SQLException, MalformedURLException,
460 IllegalAccessException, IllegalArgumentException,
461 java.lang.reflect.InvocationTargetException
462 {
463 Method getUrlInt = null;
464 Method getUrlString = null;
465 try {
466 getUrlInt = ResultSet.class.getMethod("getURL",
467 new Class[] { Integer.TYPE } );
468 getUrlString = ResultSet.class.getMethod("getURL",
469 new Class[] { String.class } );
470 } catch(NoSuchMethodException e) {
471
472 } catch(SecurityException e) {
473
474 }
475 if (getUrlInt != null && getUrlString != null) {
476 assertEquals(null, getUrlInt.invoke(rs,
477 new Object[] { new Integer(1) } ) );
478 assertTrue(rs.wasNull());
479 assertEquals(null, getUrlString.invoke(rs,
480 new Object[] { "column" } ) );
481 assertTrue(rs.wasNull());
482
483 URL u = new URL("http://www.apache.org");
484 rs2.setNullURL(u);
485 assertEquals(u, getUrlInt.invoke(rs,
486 new Object[] { new Integer(1) } ) );
487 assertEquals(u, getUrlString.invoke(rs,
488 new Object[] { "column" } ) );
489 }
490 }
491
492
493
494
495 public void testSetNullAsciiStream() throws SQLException {
496
497 assertNull(rs2.getNullAsciiStream());
498
499 InputStream stream = new ByteArrayInputStream(new byte[0]);
500 rs2.setNullAsciiStream(stream);
501 assertNotNull(rs.getAsciiStream(1));
502 assertEquals(stream, rs.getAsciiStream(1));
503 assertNotNull(rs.getAsciiStream("column"));
504 assertEquals(stream, rs.getAsciiStream("column"));
505
506 }
507
508
509
510
511 public void testSetNullBigDecimal() throws SQLException {
512
513 assertNull(rs2.getNullBigDecimal());
514
515 BigDecimal bd = new BigDecimal(5.0);
516 rs2.setNullBigDecimal(bd);
517 assertNotNull(rs.getBigDecimal(1));
518 assertEquals(bd, rs.getBigDecimal(1));
519 assertNotNull(rs.getBigDecimal("column"));
520 assertEquals(bd, rs.getBigDecimal("column"));
521
522 }
523
524
525
526
527 public void testSetNullBinaryStream() throws SQLException {
528
529 assertNull(rs2.getNullBinaryStream());
530
531 InputStream stream = new ByteArrayInputStream(new byte[0]);
532 rs2.setNullBinaryStream(stream);
533 assertNotNull(rs.getBinaryStream(1));
534 assertEquals(stream, rs.getBinaryStream(1));
535 assertNotNull(rs.getBinaryStream("column"));
536 assertEquals(stream, rs.getBinaryStream("column"));
537
538 }
539
540
541
542
543 public void testSetNullBlob() throws SQLException {
544
545 assertNull(rs2.getNullBlob());
546
547 Blob blob = new SqlNullCheckedResultSetMockBlob();
548 rs2.setNullBlob(blob);
549 assertNotNull(rs.getBlob(1));
550 assertEquals(blob, rs.getBlob(1));
551 assertNotNull(rs.getBlob("column"));
552 assertEquals(blob, rs.getBlob("column"));
553
554 }
555
556
557
558
559 public void testSetNullBoolean() throws SQLException {
560
561 assertEquals(false, rs2.getNullBoolean());
562
563 rs2.setNullBoolean(true);
564 assertEquals(true, rs.getBoolean(1));
565 assertEquals(true, rs.getBoolean("column"));
566
567 }
568
569
570
571
572 public void testSetNullByte() throws SQLException {
573
574 assertEquals((byte) 0, rs2.getNullByte());
575
576 byte b = (byte) 10;
577 rs2.setNullByte(b);
578 assertEquals(b, rs.getByte(1));
579 assertEquals(b, rs.getByte("column"));
580
581 }
582
583
584
585
586 public void testSetNullBytes() throws SQLException {
587
588 assertNull(rs2.getNullBytes());
589
590 byte[] b = new byte[5];
591 for (int i = 0; i < 5; i++) {
592 b[0] = (byte) i;
593 }
594 rs2.setNullBytes(b);
595 assertNotNull(rs.getBytes(1));
596 assertEquals(b, rs.getBytes(1));
597 assertNotNull(rs.getBytes("column"));
598 assertEquals(b, rs.getBytes("column"));
599
600 }
601
602
603
604
605 public void testSetNullCharacterStream() throws SQLException {
606
607 assertNull(rs2.getNullCharacterStream());
608
609 Reader reader = new CharArrayReader("this is a string".toCharArray());
610 rs2.setNullCharacterStream(reader);
611 assertNotNull(rs.getCharacterStream(1));
612 assertEquals(reader, rs.getCharacterStream(1));
613 assertNotNull(rs.getCharacterStream("column"));
614 assertEquals(reader, rs.getCharacterStream("column"));
615
616 }
617
618
619
620
621 public void testSetNullClob() throws SQLException {
622
623 assertNull(rs2.getNullClob());
624
625 Clob clob = new SqlNullCheckedResultSetMockClob();
626 rs2.setNullClob(clob);
627 assertNotNull(rs.getClob(1));
628 assertEquals(clob, rs.getClob(1));
629 assertNotNull(rs.getClob("column"));
630 assertEquals(clob, rs.getClob("column"));
631
632 }
633
634
635
636
637 public void testSetNullDate() throws SQLException {
638
639 assertNull(rs2.getNullDate());
640
641 java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
642 rs2.setNullDate(date);
643 assertNotNull(rs.getDate(1));
644 assertEquals(date, rs.getDate(1));
645 assertNotNull(rs.getDate("column"));
646 assertEquals(date, rs.getDate("column"));
647 assertNotNull(rs.getDate(1, Calendar.getInstance()));
648 assertEquals(date, rs.getDate(1, Calendar.getInstance()));
649 assertNotNull(rs.getDate("column", Calendar.getInstance()));
650 assertEquals(date, rs.getDate("column", Calendar.getInstance()));
651
652 }
653
654
655
656
657 public void testSetNullDouble() throws SQLException {
658 assertEquals(0.0, rs2.getNullDouble(), 0.0);
659
660 double d = 10.0;
661 rs2.setNullDouble(d);
662 assertEquals(d, rs.getDouble(1), 0.0);
663 assertEquals(d, rs.getDouble("column"), 0.0);
664 }
665
666
667
668
669 public void testSetNullFloat() throws SQLException {
670 assertEquals((float) 0.0, rs2.getNullFloat(), 0.0);
671
672 float f = (float) 10.0;
673 rs2.setNullFloat(f);
674 assertEquals(f, rs.getFloat(1), 0.0);
675 assertEquals(f, rs.getFloat("column"), 0.0);
676 }
677
678
679
680
681 public void testSetNullInt() throws SQLException {
682 assertEquals(0, rs2.getNullInt());
683 assertEquals(0, rs.getInt(1));
684 assertTrue(rs.wasNull());
685 assertEquals(0, rs.getInt("column"));
686 assertTrue(rs.wasNull());
687
688 int i = 10;
689 rs2.setNullInt(i);
690 assertEquals(i, rs.getInt(1));
691 assertEquals(i, rs.getInt("column"));
692 }
693
694
695
696
697 public void testSetNullLong() throws SQLException {
698 assertEquals(0, rs2.getNullLong());
699
700 long l = 10;
701 rs2.setNullLong(l);
702 assertEquals(l, rs.getLong(1));
703 assertEquals(l, rs.getLong("column"));
704 }
705
706
707
708
709 public void testSetNullObject() throws SQLException {
710 assertNull(rs2.getNullObject());
711
712 Object o = new Object();
713 rs2.setNullObject(o);
714 assertNotNull(rs.getObject(1));
715 assertEquals(o, rs.getObject(1));
716 assertNotNull(rs.getObject("column"));
717 assertEquals(o, rs.getObject("column"));
718 assertNotNull(rs.getObject(1, (Map) null));
719 assertEquals(o, rs.getObject(1, (Map) null));
720 assertNotNull(rs.getObject("column", (Map) null));
721 assertEquals(o, rs.getObject("column", (Map) null));
722 }
723
724
725
726
727 public void testSetNullShort() throws SQLException {
728
729 assertEquals((short) 0, rs2.getNullShort());
730
731 short s = (short) 10;
732 rs2.setNullShort(s);
733 assertEquals(s, rs.getShort(1));
734 assertEquals(s, rs.getShort("column"));
735
736 }
737
738
739
740
741 public void testSetNullString() throws SQLException {
742 assertEquals(null, rs2.getNullString());
743
744 String s = "hello, world";
745 rs2.setNullString(s);
746 assertEquals(s, rs.getString(1));
747 assertEquals(s, rs.getString("column"));
748 }
749
750
751
752
753 public void testSetNullRef() throws SQLException {
754 assertNull(rs2.getNullRef());
755
756 Ref ref = new SqlNullCheckedResultSetMockRef();
757 rs2.setNullRef(ref);
758 assertNotNull(rs.getRef(1));
759 assertEquals(ref, rs.getRef(1));
760 assertNotNull(rs.getRef("column"));
761 assertEquals(ref, rs.getRef("column"));
762 }
763
764
765
766
767 public void testSetNullTime() throws SQLException {
768 assertEquals(null, rs2.getNullTime());
769
770 Time time = new Time(new java.util.Date().getTime());
771 rs2.setNullTime(time);
772 assertNotNull(rs.getTime(1));
773 assertEquals(time, rs.getTime(1));
774 assertNotNull(rs.getTime("column"));
775 assertEquals(time, rs.getTime("column"));
776 assertNotNull(rs.getTime(1, Calendar.getInstance()));
777 assertEquals(time, rs.getTime(1, Calendar.getInstance()));
778 assertNotNull(rs.getTime("column", Calendar.getInstance()));
779 assertEquals(time, rs.getTime("column", Calendar.getInstance()));
780 }
781
782
783
784
785 public void testSetNullTimestamp() throws SQLException {
786 assertEquals(null, rs2.getNullTimestamp());
787
788 Timestamp ts = new Timestamp(new java.util.Date().getTime());
789 rs2.setNullTimestamp(ts);
790 assertNotNull(rs.getTimestamp(1));
791 assertEquals(ts, rs.getTimestamp(1));
792 assertNotNull(rs.getTimestamp("column"));
793 assertEquals(ts, rs.getTimestamp("column"));
794 assertNotNull(rs.getTimestamp(1, Calendar.getInstance()));
795 assertEquals(ts, rs.getTimestamp(1, Calendar.getInstance()));
796 assertNotNull(rs.getTimestamp("column", Calendar.getInstance()));
797 assertEquals(ts, rs.getTimestamp("column", Calendar.getInstance()));
798 }
799
800 }
801
802 class SqlNullUncheckedMockResultSet implements InvocationHandler {
803
804
805
806
807
808 public Object invoke(Object proxy, Method method, Object[] args)
809 throws Throwable {
810
811 Class returnType = method.getReturnType();
812
813 if (method.getName().equals("wasNull")) {
814 return Boolean.TRUE;
815
816 } else if (returnType.equals(Boolean.TYPE)) {
817 return Boolean.FALSE;
818
819 } else if (returnType.equals(Integer.TYPE)) {
820 return new Integer(0);
821
822 } else if (returnType.equals(Short.TYPE)) {
823 return new Short((short) 0);
824
825 } else if (returnType.equals(Double.TYPE)) {
826 return new Double(0);
827
828 } else if (returnType.equals(Long.TYPE)) {
829 return new Long(0);
830
831 } else if (returnType.equals(Byte.TYPE)) {
832 return new Byte((byte) 0);
833
834 } else if (returnType.equals(Float.TYPE)) {
835 return new Float(0);
836
837 } else {
838 return null;
839 }
840 }
841 }
842
843 class SqlNullCheckedResultSetMockBlob implements Blob {
844
845 public InputStream getBinaryStream() throws SQLException {
846 return new ByteArrayInputStream(new byte[0]);
847 }
848
849 public byte[] getBytes(long param, int param1) throws SQLException {
850 return new byte[0];
851 }
852
853 public long length() throws SQLException {
854 return 0;
855 }
856
857 public long position(byte[] values, long param) throws SQLException {
858 return 0;
859 }
860
861 public long position(Blob blob, long param) throws SQLException {
862 return 0;
863 }
864
865 public void truncate(long len) throws SQLException {
866
867 }
868
869 public int setBytes(long pos, byte[] bytes) throws SQLException {
870 return 0;
871 }
872
873 public int setBytes(long pos, byte[] bytes, int offset, int len)
874 throws SQLException {
875 return 0;
876 }
877
878 public OutputStream setBinaryStream(long pos) throws SQLException {
879 return null;
880 }
881
882 public void free() throws SQLException {
883
884 }
885
886 public InputStream getBinaryStream(long pos, long length) throws SQLException {
887 return null;
888 }
889
890 }
891
892 class SqlNullCheckedResultSetMockClob implements Clob {
893
894 public InputStream getAsciiStream() throws SQLException {
895 return null;
896 }
897
898 public Reader getCharacterStream() throws SQLException {
899 return null;
900 }
901
902 public String getSubString(long param, int param1) throws SQLException {
903 return "";
904 }
905
906 public long length() throws SQLException {
907 return 0;
908 }
909
910 public long position(Clob clob, long param) throws SQLException {
911 return 0;
912 }
913
914 public long position(String str, long param) throws SQLException {
915 return 0;
916 }
917
918 public void truncate(long len) throws SQLException {
919
920 }
921
922 public OutputStream setAsciiStream(long pos) throws SQLException {
923 return null;
924 }
925
926 public Writer setCharacterStream(long pos) throws SQLException {
927 return null;
928 }
929
930 public int setString(long pos, String str) throws SQLException {
931 return 0;
932 }
933
934 public int setString(long pos, String str, int offset, int len)
935 throws SQLException {
936 return 0;
937 }
938
939 public void free() throws SQLException {
940
941 }
942
943 public Reader getCharacterStream(long pos, long length) throws SQLException {
944 return null;
945 }
946
947 }
948
949 class SqlNullCheckedResultSetMockRef implements Ref {
950
951 public String getBaseTypeName() throws SQLException {
952 return "";
953 }
954
955 public Object getObject() throws SQLException {
956 return null;
957 }
958
959 public void setObject(Object value) throws SQLException {
960
961 }
962
963 public Object getObject(Map map) throws SQLException {
964 return null;
965 }
966
967 }