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