KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > db > jdbc > AbstractResultSet


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29 package com.caucho.db.jdbc;
30
31 import com.caucho.sql.SQLExceptionWrapper;
32 import com.caucho.util.L10N;
33
34 import java.io.IOException JavaDoc;
35 import java.io.InputStream JavaDoc;
36 import java.io.Reader JavaDoc;
37 import java.math.BigDecimal JavaDoc;
38 import java.sql.*;
39 import java.util.Calendar JavaDoc;
40 import java.util.Map JavaDoc;
41
42 /**
43  * The JDBC statement implementation.
44  */

45 abstract public class AbstractResultSet implements java.sql.ResultSet JavaDoc {
46   protected final static L10N L = new L10N(AbstractResultSet.class);
47   private int _rowNumber;
48   
49   public boolean absolute(int row)
50   {
51     return false;
52   }
53
54   public void afterLast()
55   {
56   }
57
58   public void beforeFirst()
59   {
60   }
61
62   public void cancelRowUpdates()
63   {
64   }
65
66   public void clearWarnings()
67   {
68   }
69
70   public void deleteRow()
71   {
72   }
73
74   public int getRow()
75     throws SQLException
76   {
77     if (_rowNumber < 0)
78       throw new SQLException("can't call getRow() after close()");
79     
80     return _rowNumber;
81   }
82
83   public boolean isBeforeFirst()
84     throws SQLException
85   {
86     return _rowNumber == 0;
87   }
88
89   public boolean isAfterLast()
90   {
91     return false;
92   }
93
94   public boolean isFirst()
95     throws SQLException
96   {
97     return _rowNumber == 1;
98   }
99
100   public boolean first()
101     throws SQLException
102   {
103     return isFirst();
104   }
105
106   public boolean isLast()
107     throws SQLException
108   {
109     return false;
110   }
111
112   public boolean last()
113     throws SQLException
114   {
115     return isLast();
116   }
117
118   public int getConcurrency()
119   {
120     return 0;
121   }
122
123   public String JavaDoc getCursorName()
124   {
125     return null;
126   }
127
128   abstract public java.sql.Statement JavaDoc getStatement()
129     throws SQLException;
130
131   abstract public java.sql.ResultSetMetaData JavaDoc getMetaData()
132     throws SQLException;
133
134   abstract public boolean next()
135     throws SQLException;
136
137   abstract public boolean wasNull()
138     throws SQLException;
139
140   abstract public int findColumn(String JavaDoc columnName)
141     throws SQLException;
142
143   public int getType()
144   {
145     return 0;
146   }
147
148   public BigDecimal JavaDoc getBigDecimal(int columnIndex)
149     throws SQLException
150   {
151     return null;
152   }
153
154   public BigDecimal JavaDoc getBigDecimal(int columnIndex, int scale)
155     throws SQLException
156   {
157     return getBigDecimal(columnIndex).setScale(scale);
158   }
159
160   public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName)
161     throws SQLException
162   {
163     return getBigDecimal(findColumn(columnName));
164   }
165
166   public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName, int scale)
167     throws SQLException
168   {
169     return getBigDecimal(findColumn(columnName), scale);
170   }
171
172   /**
173    * Returns the boolean value for the column.
174    */

175   public boolean getBoolean(int columnIndex)
176     throws SQLException
177   {
178     String JavaDoc v = getString(columnIndex);
179
180     return (v != null && ! v.equals("") && ! v.equals("0") && ! v.equals("n"));
181   }
182
183   /**
184    * Returns the boolean value for the named column.
185    */

186   public boolean getBoolean(String JavaDoc columnName)
187     throws SQLException
188   {
189     return getBoolean(findColumn(columnName));
190   }
191
192   public byte getByte(int columnIndex)
193     throws SQLException
194   {
195     return (byte) getInt(columnIndex);
196   }
197
198   public byte getByte(String JavaDoc columnName)
199     throws SQLException
200   {
201     return getByte(findColumn(columnName));
202   }
203
204   /**
205    * Returns the byte value for the column.
206    */

207   public byte []getBytes(int columnIndex)
208     throws SQLException
209   {
210     try {
211       Blob blob = getBlob(columnIndex);
212
213       if (blob == null)
214     return null;
215
216       int length = (int) blob.length();
217
218       byte []bytes = new byte[length];
219
220       InputStream JavaDoc is = blob.getBinaryStream();
221
222       try {
223     int offset = 0;
224     int sublen;
225
226     while (length > 0 && (sublen = is.read(bytes, offset, length)) > 0) {
227       offset += sublen;
228       length -= sublen;
229     }
230       } finally {
231     is.close();
232       }
233
234       return bytes;
235     } catch (IOException JavaDoc e) {
236       throw new SQLExceptionWrapper(e);
237     }
238   }
239
240   public byte []getBytes(String JavaDoc columnName)
241     throws SQLException
242   {
243     return getBytes(findColumn(columnName));
244   }
245
246   public Reader JavaDoc getCharacterStream(int columnIndex)
247     throws SQLException
248   {
249     throw new UnsupportedOperationException JavaDoc();
250   }
251
252   public Reader JavaDoc getCharacterStream(String JavaDoc columnName)
253     throws SQLException
254   {
255     return getCharacterStream(findColumn(columnName));
256   }
257
258   public java.sql.Date JavaDoc getDate(int columnIndex)
259     throws SQLException
260   {
261     throw new UnsupportedOperationException JavaDoc();
262   }
263
264   public java.sql.Date JavaDoc getDate(String JavaDoc columnName)
265     throws SQLException
266   {
267     return getDate(findColumn(columnName));
268   }
269
270   public java.sql.Date JavaDoc getDate(int columnIndex, Calendar JavaDoc cal)
271     throws SQLException
272   {
273     return getDate(columnIndex);
274   }
275
276   public java.sql.Date JavaDoc getDate(String JavaDoc columnName, Calendar JavaDoc cal)
277     throws SQLException
278   {
279     return getDate(findColumn(columnName), cal);
280   }
281
282   /**
283    * Returns the double value for the column.
284    */

285   public double getDouble(int columnIndex)
286     throws SQLException
287   {
288     String JavaDoc v = getString(columnIndex);
289
290     if (v == null)
291       return 0;
292     else
293       return Double.parseDouble(v);
294   }
295
296   /**
297    * Returns the double value for the named column.
298    */

299   public double getDouble(String JavaDoc columnName)
300     throws SQLException
301   {
302     return getDouble(findColumn(columnName));
303   }
304
305   public int getFetchDirection()
306   {
307     return 0;
308   }
309
310   public int getFetchSize()
311   {
312     return 0;
313   }
314
315   /**
316    * Returns the float value for the column.
317    */

318   public float getFloat(int columnIndex)
319     throws SQLException
320   {
321     return (float) getDouble(columnIndex);
322   }
323
324   /**
325    * Returns the float value for the named column.
326    */

327   public float getFloat(String JavaDoc columnName)
328     throws SQLException
329   {
330     return (float) getDouble(findColumn(columnName));
331   }
332
333   /**
334    * Returns the integer value for the column.
335    */

336   public int getInt(int columnIndex)
337     throws SQLException
338   {
339     String JavaDoc v = getString(columnIndex);
340
341     if (v == null)
342       return 0;
343     else
344       return Integer.parseInt(v);
345   }
346
347   /**
348    * Returns the integer value for the named column.
349    */

350   public int getInt(String JavaDoc columnName)
351     throws SQLException
352   {
353     return getInt(findColumn(columnName));
354   }
355
356   /**
357    * Returns the long value for the column.
358    */

359   public long getLong(int columnIndex)
360     throws SQLException
361   {
362     String JavaDoc v = getString(columnIndex);
363
364     if (v == null)
365       return 0;
366     else
367       return Long.parseLong(v);
368   }
369
370   /**
371    * Returns the long value for the named column.
372    */

373   public long getLong(String JavaDoc columnName)
374     throws SQLException
375   {
376     return getLong(findColumn(columnName));
377   }
378
379   public Object JavaDoc getObject(int columnIndex)
380     throws SQLException
381   {
382     return getString(columnIndex);
383   }
384
385   public Object JavaDoc getObject(String JavaDoc columnName)
386     throws SQLException
387   {
388     return getObject(findColumn(columnName));
389   }
390
391   public Object JavaDoc getObject(int columnIndex, Map JavaDoc<String JavaDoc,Class JavaDoc<?>> map)
392     throws SQLException
393   {
394     return getObject(columnIndex);
395   }
396
397   public Object JavaDoc getObject(String JavaDoc columnName, Map JavaDoc<String JavaDoc,Class JavaDoc<?>> map)
398     throws SQLException
399   {
400     return getObject(findColumn(columnName), map);
401   }
402
403   public short getShort(int columnIndex)
404     throws SQLException
405   {
406     return (short) getInt(columnIndex);
407   }
408
409   public short getShort(String JavaDoc columnName)
410     throws SQLException
411   {
412     return getShort(findColumn(columnName));
413   }
414
415   abstract public String JavaDoc getString(int columnIndex)
416     throws SQLException;
417
418   public String JavaDoc getString(String JavaDoc columnName)
419     throws SQLException
420   {
421     return getString(findColumn(columnName));
422   }
423
424   public Time getTime(int columnIndex)
425     throws SQLException
426   {
427     throw new UnsupportedOperationException JavaDoc();
428   }
429
430   public Time getTime(String JavaDoc columnName)
431     throws SQLException
432   {
433     return getTime(findColumn(columnName));
434   }
435
436   public Time getTime(int columnIndex, Calendar JavaDoc calendar)
437     throws SQLException
438   {
439     return getTime(columnIndex);
440   }
441
442   public Time getTime(String JavaDoc columnName, Calendar JavaDoc calendar)
443     throws SQLException
444   {
445     return getTime(findColumn(columnName), calendar);
446   }
447
448   public Timestamp getTimestamp(int columnIndex)
449     throws SQLException
450   {
451     throw new UnsupportedOperationException JavaDoc();
452   }
453
454   public Timestamp getTimestamp(String JavaDoc columnName)
455     throws SQLException
456   {
457     return getTimestamp(findColumn(columnName));
458   }
459
460   public Timestamp getTimestamp(int columnIndex, Calendar JavaDoc calendar)
461     throws SQLException
462   {
463     return getTimestamp(columnIndex);
464   }
465
466   public Timestamp getTimestamp(String JavaDoc columnName, Calendar JavaDoc calendar)
467     throws SQLException
468   {
469     return getTimestamp(findColumn(columnName), calendar);
470   }
471
472   public InputStream JavaDoc getBinaryStream(int columnIndex)
473     throws SQLException
474   {
475     Blob blob = getBlob(columnIndex);
476
477     if (blob != null)
478       return blob.getBinaryStream();
479     else
480       return null;
481   }
482
483   public InputStream JavaDoc getBinaryStream(String JavaDoc columnName)
484     throws SQLException
485   {
486     return getBinaryStream(findColumn(columnName));
487   }
488
489   public InputStream JavaDoc getAsciiStream(int columnIndex)
490     throws SQLException
491   {
492     return getBinaryStream(columnIndex);
493   }
494
495   public InputStream JavaDoc getAsciiStream(String JavaDoc columnName)
496     throws SQLException
497   {
498     return getAsciiStream(findColumn(columnName));
499   }
500
501   public InputStream JavaDoc getUnicodeStream(int columnIndex)
502     throws SQLException
503   {
504     throw new UnsupportedOperationException JavaDoc();
505   }
506
507   public InputStream JavaDoc getUnicodeStream(String JavaDoc columnName)
508     throws SQLException
509   {
510     return getUnicodeStream(findColumn(columnName));
511   }
512
513   public Array getArray(int columnIndex)
514     throws SQLException
515   {
516     throw new UnsupportedOperationException JavaDoc();
517   }
518
519   public Array getArray(String JavaDoc columnName)
520     throws SQLException
521   {
522     return getArray(findColumn(columnName));
523   }
524
525   public Blob getBlob(int columnIndex)
526     throws SQLException
527   {
528     throw new UnsupportedOperationException JavaDoc();
529   }
530
531   public Blob getBlob(String JavaDoc columnName)
532     throws SQLException
533   {
534     return getBlob(findColumn(columnName));
535   }
536
537   public Clob getClob(int columnIndex)
538     throws SQLException
539   {
540     throw new UnsupportedOperationException JavaDoc();
541   }
542
543   public Clob getClob(String JavaDoc columnName)
544     throws SQLException
545   {
546     return getClob(findColumn(columnName));
547   }
548
549   public Ref getRef(int columnIndex)
550     throws SQLException
551   {
552     throw new UnsupportedOperationException JavaDoc();
553   }
554
555   public Ref getRef(String JavaDoc columnName)
556     throws SQLException
557   {
558     return getRef(findColumn(columnName));
559   }
560
561   public SQLWarning getWarnings()
562   {
563     return null;
564   }
565
566   public void insertRow()
567   {
568   }
569
570   public void moveToCurrentRow()
571   {
572   }
573
574   public void moveToInsertRow()
575   {
576   }
577
578   public boolean previous()
579   {
580     return false;
581   }
582
583   public void refreshRow()
584   {
585   }
586
587   public boolean relative(int rows)
588   {
589     return false;
590   }
591
592   public boolean rowDeleted()
593   {
594     return false;
595   }
596
597   public boolean rowInserted()
598   {
599     return false;
600   }
601
602   public boolean rowUpdated()
603   {
604     return false;
605   }
606
607   public void setFetchDirection(int direction)
608   {
609   }
610
611   public void setFetchSize(int rows)
612   {
613   }
614
615   public void updateRow()
616   {
617   }
618
619   public void updateObject(int columnIndex, Object JavaDoc o)
620   {
621   }
622
623   public void updateObject(String JavaDoc columnName, Object JavaDoc o)
624     throws SQLException
625   {
626     updateObject(findColumn(columnName), o);
627   }
628
629   public void updateObject(int columnIndex, Object JavaDoc o, int scale)
630   {
631   }
632
633   public void updateObject(String JavaDoc columnName, Object JavaDoc o, int scale)
634     throws SQLException
635   {
636     updateObject(findColumn(columnName), o, scale);
637   }
638
639   public void updateNull(int columnIndex)
640   {
641   }
642
643   public void updateNull(String JavaDoc columnName)
644     throws SQLException
645   {
646     updateNull(findColumn(columnName));
647   }
648
649   public void updateAsciiStream(int columnIndex, InputStream JavaDoc x, int length)
650   {
651   }
652
653   public void updateAsciiStream(String JavaDoc columnName, InputStream JavaDoc x, int length)
654     throws SQLException
655   {
656     updateAsciiStream(findColumn(columnName), x, length);
657   }
658
659   public void updateBigDecimal(int columnIndex, BigDecimal JavaDoc x)
660   {
661   }
662
663   public void updateBigDecimal(String JavaDoc columnName, BigDecimal JavaDoc x)
664     throws SQLException
665   {
666     updateBigDecimal(findColumn(columnName), x);
667   }
668
669   public void updateBinaryStream(int columnIndex, InputStream JavaDoc x, int length)
670   {
671   }
672
673   public void updateBinaryStream(String JavaDoc columnName, InputStream JavaDoc x, int length)
674     throws SQLException
675   {
676     updateBinaryStream(findColumn(columnName), x, length);
677   }
678
679   public void updateBoolean(int columnIndex, boolean x)
680   {
681   }
682
683   public void updateBoolean(String JavaDoc columnName, boolean x)
684     throws SQLException
685   {
686     updateBoolean(findColumn(columnName), x);
687   }
688
689   public void updateByte(int columnIndex, byte x)
690   {
691   }
692
693   public void updateByte(String JavaDoc columnName, byte x)
694     throws SQLException
695   {
696     updateByte(findColumn(columnName), x);
697   }
698
699   public void updateShort(int columnIndex, short x)
700   {
701   }
702
703   public void updateShort(String JavaDoc columnName, short x)
704     throws SQLException
705   {
706     updateShort(findColumn(columnName), x);
707   }
708
709   public void updateInt(int columnIndex, int x)
710   {
711   }
712
713   public void updateInt(String JavaDoc columnName, int x)
714     throws SQLException
715   {
716     updateInt(findColumn(columnName), x);
717   }
718
719   public void updateLong(int columnIndex, long x)
720   {
721   }
722
723   public void updateLong(String JavaDoc columnName, long x)
724     throws SQLException
725   {
726     updateLong(findColumn(columnName), x);
727   }
728
729   public void updateFloat(int columnIndex, float x)
730   {
731   }
732
733   public void updateFloat(String JavaDoc columnName, float x)
734     throws SQLException
735   {
736     updateFloat(findColumn(columnName), x);
737   }
738
739   public void updateDouble(int columnIndex, double x)
740   {
741   }
742
743   public void updateDouble(String JavaDoc columnName, double x)
744     throws SQLException
745   {
746     updateDouble(findColumn(columnName), x);
747   }
748
749   public void updateString(int columnIndex, String JavaDoc x)
750   {
751   }
752
753   public void updateString(String JavaDoc columnName, String JavaDoc x)
754     throws SQLException
755   {
756     updateString(findColumn(columnName), x);
757   }
758
759   public void updateBytes(int columnIndex, byte[] x)
760   {
761   }
762
763   public void updateBytes(String JavaDoc columnName, byte[] x)
764     throws SQLException
765   {
766     updateBytes(findColumn(columnName), x);
767   }
768
769   public void updateCharacterStream(int columnIndex, Reader JavaDoc x, int length)
770   {
771   }
772
773   public void updateCharacterStream(String JavaDoc columnName, Reader JavaDoc x, int length)
774     throws SQLException
775   {
776     updateCharacterStream(findColumn(columnName), x, length);
777   }
778
779   public void updateTime(int columnIndex, Time time)
780     throws SQLException
781   {
782   }
783
784   public void updateTime(String JavaDoc columnName, Time time)
785     throws SQLException
786   {
787     updateTime(findColumn(columnName), time);
788   }
789
790   public void updateDate(int columnIndex, java.sql.Date JavaDoc date)
791     throws SQLException
792   {
793   }
794
795   public void updateDate(String JavaDoc columnName, java.sql.Date JavaDoc date)
796     throws SQLException
797   {
798     updateDate(findColumn(columnName), date);
799   }
800
801   public void updateTimestamp(int columnIndex, Timestamp time)
802     throws SQLException
803   {
804   }
805
806   public void updateTimestamp(String JavaDoc columnName, Timestamp time)
807     throws SQLException
808   {
809     updateTimestamp(findColumn(columnName), time);
810   }
811
812   public void updateArray(int columnIndex, Array value)
813     throws SQLException
814   {
815     throw new UnsupportedOperationException JavaDoc();
816   }
817
818   public void updateArray(String JavaDoc columnName, Array value)
819     throws SQLException
820   {
821     updateArray(findColumn(columnName), value);
822   }
823
824   public void updateBlob(int columnIndex, Blob value)
825     throws SQLException
826   {
827     throw new UnsupportedOperationException JavaDoc();
828   }
829
830   public void updateBlob(String JavaDoc columnName, Blob value)
831     throws SQLException
832   {
833     updateBlob(findColumn(columnName), value);
834   }
835
836   public void updateClob(int columnIndex, Clob value)
837     throws SQLException
838   {
839     throw new UnsupportedOperationException JavaDoc();
840   }
841
842   public void updateClob(String JavaDoc columnName, Clob value)
843     throws SQLException
844   {
845     updateClob(findColumn(columnName), value);
846   }
847
848   public void updateRef(int columnIndex, Ref value)
849     throws SQLException
850   {
851     throw new UnsupportedOperationException JavaDoc();
852   }
853
854   public void updateRef(String JavaDoc columnName, Ref value)
855     throws SQLException
856   {
857     updateRef(findColumn(columnName), value);
858   }
859
860   public java.net.URL JavaDoc getURL(int column)
861     throws SQLException
862   {
863     throw new UnsupportedOperationException JavaDoc();
864   }
865
866   public java.net.URL JavaDoc getURL(String JavaDoc column)
867     throws SQLException
868   {
869     return getURL(findColumn(column));
870   }
871
872   public void close()
873     throws SQLException
874   {
875   }
876 }
877
Popular Tags