KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jdbc > WrappedResultSet


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.resource.adapter.jdbc;
23
24 import java.io.InputStream JavaDoc;
25 import java.io.Reader JavaDoc;
26 import java.math.BigDecimal JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.sql.Array JavaDoc;
29 import java.sql.Blob JavaDoc;
30 import java.sql.Clob JavaDoc;
31 import java.sql.Date JavaDoc;
32 import java.sql.Ref JavaDoc;
33 import java.sql.ResultSet JavaDoc;
34 import java.sql.ResultSetMetaData JavaDoc;
35 import java.sql.SQLException JavaDoc;
36 import java.sql.SQLWarning JavaDoc;
37 import java.sql.Statement JavaDoc;
38 import java.sql.Time JavaDoc;
39 import java.sql.Timestamp JavaDoc;
40 import java.util.Calendar JavaDoc;
41 import java.util.Map JavaDoc;
42
43 /**
44  * A wrapper for a result set
45  *
46  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
47  * @version $Revision: 54958 $
48  */

49 public class WrappedResultSet implements ResultSet JavaDoc
50 {
51    /** The wrapped statement */
52    private WrappedStatement statement;
53
54    /** The real result set */
55    private ResultSet JavaDoc resultSet;
56
57    /** Whether we are closed */
58    private boolean closed = false;
59
60    /** The state lock */
61    private Object JavaDoc lock = new Object JavaDoc();
62    
63    /**
64     * Create a new wrapped result set
65     *
66     * @param statement the wrapped statement
67     * @param resultSet the real result set
68     */

69    public WrappedResultSet(WrappedStatement statement, ResultSet JavaDoc resultSet)
70    {
71       if (statement == null)
72          throw new IllegalArgumentException JavaDoc("Null statement!");
73       if (resultSet == null)
74          throw new IllegalArgumentException JavaDoc("Null result set!");
75       this.statement = statement;
76       this.resultSet = resultSet;
77    }
78
79    public boolean equals(Object JavaDoc o)
80    {
81       if (o == null)
82          return false;
83       else if (o == this)
84          return true;
85       else if (o instanceof WrappedResultSet)
86          return (resultSet.equals(((WrappedResultSet) o).resultSet));
87       else if (o instanceof ResultSet JavaDoc)
88          return resultSet.equals(o);
89       return false;
90    }
91
92    public int hashCode()
93    {
94       return resultSet.hashCode();
95    }
96
97    public String JavaDoc toString()
98    {
99       return resultSet.toString();
100    }
101
102    public ResultSet JavaDoc getUnderlyingResultSet() throws SQLException JavaDoc
103    {
104       checkState();
105       return resultSet;
106    }
107
108    public boolean absolute(int row) throws SQLException JavaDoc
109    {
110       checkState();
111       try
112       {
113          return resultSet.absolute(row);
114       }
115       catch (Throwable JavaDoc t)
116       {
117          throw checkException(t);
118       }
119    }
120
121    public void afterLast() throws SQLException JavaDoc
122    {
123       checkState();
124       try
125       {
126          resultSet.afterLast();
127       }
128       catch (Throwable JavaDoc t)
129       {
130          throw checkException(t);
131       }
132    }
133
134    public void beforeFirst() throws SQLException JavaDoc
135    {
136       checkState();
137       try
138       {
139          resultSet.beforeFirst();
140       }
141       catch (Throwable JavaDoc t)
142       {
143          throw checkException(t);
144       }
145    }
146
147    public void cancelRowUpdates() throws SQLException JavaDoc
148    {
149       checkState();
150       try
151       {
152          resultSet.cancelRowUpdates();
153       }
154       catch (Throwable JavaDoc t)
155       {
156          throw checkException(t);
157       }
158    }
159
160    public void clearWarnings() throws SQLException JavaDoc
161    {
162       checkState();
163       try
164       {
165          resultSet.clearWarnings();
166       }
167       catch (Throwable JavaDoc t)
168       {
169          throw checkException(t);
170       }
171    }
172
173    public void close() throws SQLException JavaDoc
174    {
175       synchronized (lock)
176       {
177          if (closed)
178            return;
179          closed = true;
180       }
181       statement.unregisterResultSet(this);
182       internalClose();
183    }
184
185    public void deleteRow() throws SQLException JavaDoc
186    {
187       checkState();
188       try
189       {
190          resultSet.deleteRow();
191       }
192       catch (Throwable JavaDoc t)
193       {
194          throw checkException(t);
195       }
196    }
197
198    public int findColumn(String JavaDoc columnName) throws SQLException JavaDoc
199    {
200       checkState();
201       try
202       {
203          return resultSet.findColumn(columnName);
204       }
205       catch (Throwable JavaDoc t)
206       {
207          throw checkException(t);
208       }
209    }
210
211    public boolean first() throws SQLException JavaDoc
212    {
213       checkState();
214       try
215       {
216          return resultSet.first();
217       }
218       catch (Throwable JavaDoc t)
219       {
220          throw checkException(t);
221       }
222    }
223
224    public Array JavaDoc getArray(int i) throws SQLException JavaDoc
225    {
226       checkState();
227       try
228       {
229          return resultSet.getArray(i);
230       }
231       catch (Throwable JavaDoc t)
232       {
233          throw checkException(t);
234       }
235    }
236
237    public Array JavaDoc getArray(String JavaDoc colName) throws SQLException JavaDoc
238    {
239       checkState();
240       try
241       {
242          return resultSet.getArray(colName);
243       }
244       catch (Throwable JavaDoc t)
245       {
246          throw checkException(t);
247       }
248    }
249
250    public InputStream JavaDoc getAsciiStream(int columnIndex) throws SQLException JavaDoc
251    {
252       checkState();
253       try
254       {
255          return resultSet.getAsciiStream(columnIndex);
256       }
257       catch (Throwable JavaDoc t)
258       {
259          throw checkException(t);
260       }
261    }
262
263    public InputStream JavaDoc getAsciiStream(String JavaDoc columnName) throws SQLException JavaDoc
264    {
265       checkState();
266       try
267       {
268          return resultSet.getAsciiStream(columnName);
269       }
270       catch (Throwable JavaDoc t)
271       {
272          throw checkException(t);
273       }
274    }
275
276    public BigDecimal JavaDoc getBigDecimal(int columnIndex) throws SQLException JavaDoc
277    {
278       checkState();
279       try
280       {
281          return resultSet.getBigDecimal(columnIndex);
282       }
283       catch (Throwable JavaDoc t)
284       {
285          throw checkException(t);
286       }
287    }
288
289    /**
290     * @deprecated
291     */

292    public BigDecimal JavaDoc getBigDecimal(int columnIndex, int scale) throws SQLException JavaDoc
293    {
294       checkState();
295       try
296       {
297          return resultSet.getBigDecimal(columnIndex, scale);
298       }
299       catch (Throwable JavaDoc t)
300       {
301          throw checkException(t);
302       }
303    }
304
305    public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName) throws SQLException JavaDoc
306    {
307       checkState();
308       try
309       {
310          return resultSet.getBigDecimal(columnName);
311       }
312       catch (Throwable JavaDoc t)
313       {
314          throw checkException(t);
315       }
316    }
317
318    /**
319     * @deprecated
320     */

321    public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName, int scale) throws SQLException JavaDoc
322    {
323       checkState();
324       try
325       {
326          return resultSet.getBigDecimal(columnName, scale);
327       }
328       catch (Throwable JavaDoc t)
329       {
330          throw checkException(t);
331       }
332    }
333
334    public InputStream JavaDoc getBinaryStream(int columnIndex) throws SQLException JavaDoc
335    {
336       checkState();
337       try
338       {
339          return resultSet.getBinaryStream(columnIndex);
340       }
341       catch (Throwable JavaDoc t)
342       {
343          throw checkException(t);
344       }
345    }
346
347    public InputStream JavaDoc getBinaryStream(String JavaDoc columnName) throws SQLException JavaDoc
348    {
349       checkState();
350       try
351       {
352          return resultSet.getBinaryStream(columnName);
353       }
354       catch (Throwable JavaDoc t)
355       {
356          throw checkException(t);
357       }
358    }
359
360    public Blob JavaDoc getBlob(int i) throws SQLException JavaDoc
361    {
362       checkState();
363       try
364       {
365          return resultSet.getBlob(i);
366       }
367       catch (Throwable JavaDoc t)
368       {
369          throw checkException(t);
370       }
371    }
372
373    public Blob JavaDoc getBlob(String JavaDoc colName) throws SQLException JavaDoc
374    {
375       checkState();
376       try
377       {
378          return resultSet.getBlob(colName);
379       }
380       catch (Throwable JavaDoc t)
381       {
382          throw checkException(t);
383       }
384    }
385
386    public boolean getBoolean(int columnIndex) throws SQLException JavaDoc
387    {
388       checkState();
389       try
390       {
391          return resultSet.getBoolean(columnIndex);
392       }
393       catch (Throwable JavaDoc t)
394       {
395          throw checkException(t);
396       }
397    }
398
399    public boolean getBoolean(String JavaDoc columnName) throws SQLException JavaDoc
400    {
401       checkState();
402       try
403       {
404          return resultSet.getBoolean(columnName);
405       }
406       catch (Throwable JavaDoc t)
407       {
408          throw checkException(t);
409       }
410    }
411
412    public byte getByte(int columnIndex) throws SQLException JavaDoc
413    {
414       checkState();
415       try
416       {
417          return resultSet.getByte(columnIndex);
418       }
419       catch (Throwable JavaDoc t)
420       {
421          throw checkException(t);
422       }
423    }
424
425    public byte getByte(String JavaDoc columnName) throws SQLException JavaDoc
426    {
427       checkState();
428       try
429       {
430          return resultSet.getByte(columnName);
431       }
432       catch (Throwable JavaDoc t)
433       {
434          throw checkException(t);
435       }
436    }
437
438    public byte[] getBytes(int columnIndex) throws SQLException JavaDoc
439    {
440       checkState();
441       try
442       {
443          return resultSet.getBytes(columnIndex);
444       }
445       catch (Throwable JavaDoc t)
446       {
447          throw checkException(t);
448       }
449    }
450
451    public byte[] getBytes(String JavaDoc columnName) throws SQLException JavaDoc
452    {
453       checkState();
454       try
455       {
456          return resultSet.getBytes(columnName);
457       }
458       catch (Throwable JavaDoc t)
459       {
460          throw checkException(t);
461       }
462    }
463
464    public Reader JavaDoc getCharacterStream(int columnIndex) throws SQLException JavaDoc
465    {
466       checkState();
467       try
468       {
469          return resultSet.getCharacterStream(columnIndex);
470       }
471       catch (Throwable JavaDoc t)
472       {
473          throw checkException(t);
474       }
475    }
476
477    public Reader JavaDoc getCharacterStream(String JavaDoc columnName) throws SQLException JavaDoc
478    {
479       checkState();
480       try
481       {
482          return resultSet.getCharacterStream(columnName);
483       }
484       catch (Throwable JavaDoc t)
485       {
486          throw checkException(t);
487       }
488    }
489
490    public Clob JavaDoc getClob(int i) throws SQLException JavaDoc
491    {
492       checkState();
493       try
494       {
495          return resultSet.getClob(i);
496       }
497       catch (Throwable JavaDoc t)
498       {
499          throw checkException(t);
500       }
501    }
502
503    public Clob JavaDoc getClob(String JavaDoc colName) throws SQLException JavaDoc
504    {
505       checkState();
506       try
507       {
508          return resultSet.getClob(colName);
509       }
510       catch (Throwable JavaDoc t)
511       {
512          throw checkException(t);
513       }
514    }
515
516    public int getConcurrency() throws SQLException JavaDoc
517    {
518       checkState();
519       try
520       {
521          return resultSet.getConcurrency();
522       }
523       catch (Throwable JavaDoc t)
524       {
525          throw checkException(t);
526       }
527    }
528
529    public String JavaDoc getCursorName() throws SQLException JavaDoc
530    {
531       checkState();
532       try
533       {
534          return resultSet.getCursorName();
535       }
536       catch (Throwable JavaDoc t)
537       {
538          throw checkException(t);
539       }
540    }
541
542    public Date JavaDoc getDate(int columnIndex) throws SQLException JavaDoc
543    {
544       checkState();
545       try
546       {
547          return resultSet.getDate(columnIndex);
548       }
549       catch (Throwable JavaDoc t)
550       {
551          throw checkException(t);
552       }
553    }
554
555    public Date JavaDoc getDate(int columnIndex, Calendar JavaDoc cal) throws SQLException JavaDoc
556    {
557       checkState();
558       try
559       {
560          return resultSet.getDate(columnIndex, cal);
561       }
562       catch (Throwable JavaDoc t)
563       {
564          throw checkException(t);
565       }
566    }
567
568    public Date JavaDoc getDate(String JavaDoc columnName) throws SQLException JavaDoc
569    {
570       checkState();
571       try
572       {
573          return resultSet.getDate(columnName);
574       }
575       catch (Throwable JavaDoc t)
576       {
577          throw checkException(t);
578       }
579    }
580
581    public Date JavaDoc getDate(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException JavaDoc
582    {
583       checkState();
584       try
585       {
586          return resultSet.getDate(columnName, cal);
587       }
588       catch (Throwable JavaDoc t)
589       {
590          throw checkException(t);
591       }
592    }
593
594    public double getDouble(int columnIndex) throws SQLException JavaDoc
595    {
596       checkState();
597       try
598       {
599          return resultSet.getDouble(columnIndex);
600       }
601       catch (Throwable JavaDoc t)
602       {
603          throw checkException(t);
604       }
605    }
606
607    public double getDouble(String JavaDoc columnName) throws SQLException JavaDoc
608    {
609       checkState();
610       try
611       {
612          return resultSet.getDouble(columnName);
613       }
614       catch (Throwable JavaDoc t)
615       {
616          throw checkException(t);
617       }
618    }
619
620    public int getFetchDirection() throws SQLException JavaDoc
621    {
622       checkState();
623       try
624       {
625          return resultSet.getFetchDirection();
626       }
627       catch (Throwable JavaDoc t)
628       {
629          throw checkException(t);
630       }
631    }
632
633    public int getFetchSize() throws SQLException JavaDoc
634    {
635       checkState();
636       try
637       {
638          return resultSet.getFetchSize();
639       }
640       catch (Throwable JavaDoc t)
641       {
642          throw checkException(t);
643       }
644    }
645
646    public float getFloat(int columnIndex) throws SQLException JavaDoc
647    {
648       checkState();
649       try
650       {
651          return resultSet.getFloat(columnIndex);
652       }
653       catch (Throwable JavaDoc t)
654       {
655          throw checkException(t);
656       }
657    }
658
659    public float getFloat(String JavaDoc columnName) throws SQLException JavaDoc
660    {
661       checkState();
662       try
663       {
664          return resultSet.getFloat(columnName);
665       }
666       catch (Throwable JavaDoc t)
667       {
668          throw checkException(t);
669       }
670    }
671
672    public int getInt(int columnIndex) throws SQLException JavaDoc
673    {
674       checkState();
675       try
676       {
677          return resultSet.getInt(columnIndex);
678       }
679       catch (Throwable JavaDoc t)
680       {
681          throw checkException(t);
682       }
683    }
684
685    public int getInt(String JavaDoc columnName) throws SQLException JavaDoc
686    {
687       checkState();
688       try
689       {
690          return resultSet.getInt(columnName);
691       }
692       catch (Throwable JavaDoc t)
693       {
694          throw checkException(t);
695       }
696    }
697
698    public long getLong(int columnIndex) throws SQLException JavaDoc
699    {
700       checkState();
701       try
702       {
703          return resultSet.getLong(columnIndex);
704       }
705       catch (Throwable JavaDoc t)
706       {
707          throw checkException(t);
708       }
709    }
710
711    public long getLong(String JavaDoc columnName) throws SQLException JavaDoc
712    {
713       checkState();
714       try
715       {
716          return resultSet.getLong(columnName);
717       }
718       catch (Throwable JavaDoc t)
719       {
720          throw checkException(t);
721       }
722    }
723
724    public ResultSetMetaData JavaDoc getMetaData() throws SQLException JavaDoc
725    {
726       checkState();
727       try
728       {
729          return resultSet.getMetaData();
730       }
731       catch (Throwable JavaDoc t)
732       {
733          throw checkException(t);
734       }
735    }
736
737    public Object JavaDoc getObject(int columnIndex) throws SQLException JavaDoc
738    {
739       checkState();
740       try
741       {
742          return resultSet.getObject(columnIndex);
743       }
744       catch (Throwable JavaDoc t)
745       {
746          throw checkException(t);
747       }
748    }
749
750    public Object JavaDoc getObject(int i, Map JavaDoc map) throws SQLException JavaDoc
751    {
752       checkState();
753       try
754       {
755          return resultSet.getObject(i, map);
756       }
757       catch (Throwable JavaDoc t)
758       {
759          throw checkException(t);
760       }
761    }
762
763    public Object JavaDoc getObject(String JavaDoc columnName) throws SQLException JavaDoc
764    {
765       checkState();
766       try
767       {
768          return resultSet.getObject(columnName);
769       }
770       catch (Throwable JavaDoc t)
771       {
772          throw checkException(t);
773       }
774    }
775
776    public Object JavaDoc getObject(String JavaDoc colName, Map JavaDoc map) throws SQLException JavaDoc
777    {
778       checkState();
779       try
780       {
781          return resultSet.getObject(colName, map);
782       }
783       catch (Throwable JavaDoc t)
784       {
785          throw checkException(t);
786       }
787    }
788
789    public Ref JavaDoc getRef(int i) throws SQLException JavaDoc
790    {
791       checkState();
792       try
793       {
794          return resultSet.getRef(i);
795       }
796       catch (Throwable JavaDoc t)
797       {
798          throw checkException(t);
799       }
800    }
801
802    public Ref JavaDoc getRef(String JavaDoc colName) throws SQLException JavaDoc
803    {
804       checkState();
805       try
806       {
807          return resultSet.getRef(colName);
808       }
809       catch (Throwable JavaDoc t)
810       {
811          throw checkException(t);
812       }
813    }
814
815    public int getRow() throws SQLException JavaDoc
816    {
817       checkState();
818       try
819       {
820          return resultSet.getRow();
821       }
822       catch (Throwable JavaDoc t)
823       {
824          throw checkException(t);
825       }
826    }
827
828    public short getShort(int columnIndex) throws SQLException JavaDoc
829    {
830       checkState();
831       try
832       {
833          return resultSet.getShort(columnIndex);
834       }
835       catch (Throwable JavaDoc t)
836       {
837          throw checkException(t);
838       }
839    }
840
841    public short getShort(String JavaDoc columnName) throws SQLException JavaDoc
842    {
843       checkState();
844       try
845       {
846          return resultSet.getShort(columnName);
847       }
848       catch (Throwable JavaDoc t)
849       {
850          throw checkException(t);
851       }
852    }
853
854    public Statement JavaDoc getStatement() throws SQLException JavaDoc
855    {
856       checkState();
857       return statement;
858    }
859
860    public String JavaDoc getString(int columnIndex) throws SQLException JavaDoc
861    {
862       checkState();
863       try
864       {
865          return resultSet.getString(columnIndex);
866       }
867       catch (Throwable JavaDoc t)
868       {
869          throw checkException(t);
870       }
871    }
872
873    public String JavaDoc getString(String JavaDoc columnName) throws SQLException JavaDoc
874    {
875       checkState();
876       try
877       {
878          return resultSet.getString(columnName);
879       }
880       catch (Throwable JavaDoc t)
881       {
882          throw checkException(t);
883       }
884    }
885
886    public Time JavaDoc getTime(int columnIndex) throws SQLException JavaDoc
887    {
888       checkState();
889       try
890       {
891          return resultSet.getTime(columnIndex);
892       }
893       catch (Throwable JavaDoc t)
894       {
895          throw checkException(t);
896       }
897    }
898
899    public Time JavaDoc getTime(int columnIndex, Calendar JavaDoc cal) throws SQLException