KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smallsql > database > SSResultSet


1 /* =============================================================
2  * SmallSQL : a free Java DBMS library for the Java(tm) platform
3  * =============================================================
4  *
5  * (C) Copyright 2004-2006, by Volker Berlin.
6  *
7  * Project Info: http://www.smallsql.de/
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------
28  * SSResultSet.java
29  * ---------------
30  * Author: Volker Berlin
31  *
32  */

33 package smallsql.database;
34
35 import java.sql.*;
36 import java.math.*;
37 import java.io.InputStream JavaDoc;
38 import java.io.Reader JavaDoc;
39 import java.util.Map JavaDoc;
40 import java.util.Calendar JavaDoc;
41 import java.net.URL JavaDoc;
42
43
44 public class SSResultSet implements ResultSet {
45
46     SSResultSetMetaData metaData = new SSResultSetMetaData();
47     private CommandSelect cmd;
48     private boolean wasNull;
49     SSStatement st;
50     private boolean isUpdatable;
51     private boolean isInsertRow;
52     private ExpressionValue[] values;
53     private int fetchDirection;
54     private int fetchSize;
55
56     SSResultSet( SSStatement st, CommandSelect cmd ){
57         this.st = st;
58         metaData.columns = cmd.columnExpressions;
59         this.cmd = cmd;
60         isUpdatable = st != null && st.rsConcurrency == CONCUR_UPDATABLE && !cmd.isGroupResult();
61     }
62
63 /*==============================================================================
64
65     Public Interface
66
67 ==============================================================================*/

68
69     public void close(){
70         st.con.log.println("ResultSet.close");
71         cmd = null;
72     }
73     
74     
75     public boolean wasNull(){
76         return wasNull;
77     }
78     
79     
80     public String JavaDoc getString(int columnIndex) throws SQLException {
81         try{
82             String JavaDoc obj = getValue(columnIndex).getString();
83             wasNull = obj == null;
84             return obj;
85         }catch(Exception JavaDoc e){
86             throw Utils.createSQLException( e );
87         }
88     }
89     public boolean getBoolean(int columnIndex) throws SQLException {
90         try{
91             Expression expr = getValue(columnIndex);
92             wasNull = expr.isNull();
93             return expr.getBoolean();
94         }catch(Exception JavaDoc e){
95             throw Utils.createSQLException( e );
96         }
97     }
98     public byte getByte(int columnIndex) throws SQLException {
99         return (byte)getInt( columnIndex );
100     }
101     public short getShort(int columnIndex) throws SQLException {
102         return (short)getInt( columnIndex );
103     }
104     public int getInt(int columnIndex) throws SQLException {
105         try{
106             Expression expr = getValue(columnIndex);
107             wasNull = expr.isNull();
108             return expr.getInt();
109         }catch(Exception JavaDoc e){
110             throw Utils.createSQLException( e );
111         }
112     }
113     public long getLong(int columnIndex) throws SQLException {
114         try{
115             Expression expr = getValue(columnIndex);
116             wasNull = expr.isNull();
117             return expr.getLong();
118         }catch(Exception JavaDoc e){
119             throw Utils.createSQLException( e );
120         }
121     }
122     public float getFloat(int columnIndex) throws SQLException {
123         try{
124             Expression expr = getValue(columnIndex);
125             wasNull = expr.isNull();
126             return expr.getFloat();
127         }catch(Exception JavaDoc e){
128             throw Utils.createSQLException( e );
129         }
130     }
131     public double getDouble(int columnIndex) throws SQLException {
132         try{
133             Expression expr = getValue(columnIndex);
134             wasNull = expr.isNull();
135             return expr.getDouble();
136         }catch(Exception JavaDoc e){
137             throw Utils.createSQLException( e );
138         }
139     }
140     public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
141         try{
142             MutableNumeric obj = getValue(columnIndex).getNumeric();
143             wasNull = obj == null;
144             if(wasNull) return null;
145             return obj.toBigDecimal(scale);
146         }catch(Exception JavaDoc e){
147             throw Utils.createSQLException( e );
148         }
149     }
150     public byte[] getBytes(int columnIndex) throws SQLException {
151         try{
152             byte[] obj = getValue(columnIndex).getBytes();
153             wasNull = obj == null;
154             return obj;
155         }catch(Exception JavaDoc e){
156             throw Utils.createSQLException( e );
157         }
158     }
159     public Date getDate(int columnIndex) throws SQLException {
160         try{
161             Expression expr = getValue(columnIndex);
162             wasNull = expr.isNull();
163             if(wasNull) return null;
164             return DateTime.getDate( expr.getLong() );
165         }catch(Exception JavaDoc e){
166             throw Utils.createSQLException( e );
167         }
168     }
169     
170     
171     public Time getTime(int columnIndex) throws SQLException {
172         try{
173             Expression expr = getValue(columnIndex);
174             wasNull = expr.isNull();
175             if(wasNull) return null;
176             return DateTime.getTime( expr.getLong() );
177         }catch(Exception JavaDoc e){
178             throw Utils.createSQLException( e );
179         }
180     }
181     public Timestamp getTimestamp(int columnIndex) throws SQLException {
182         try{
183             Expression expr = getValue(columnIndex);
184             wasNull = expr.isNull();
185             if(wasNull) return null;
186             return DateTime.getTimestamp( expr.getLong() );
187         }catch(Exception JavaDoc e){
188             throw Utils.createSQLException( e );
189         }
190     }
191     
192     
193     public InputStream JavaDoc getAsciiStream(int columnIndex) throws SQLException {
194         /**@todo: Implement this java.sql.ResultSet.getAsciiStream method*/
195         throw Utils.createUnsupportedException("getAsciiStream");
196     }
197     
198     
199     public InputStream JavaDoc getUnicodeStream(int columnIndex) throws SQLException {
200         /**@todo: Implement this java.sql.ResultSet.getUnicodeStream method*/
201         throw Utils.createUnsupportedException("getUnicodeStream");
202     }
203     
204     
205     public InputStream JavaDoc getBinaryStream(int columnIndex) throws SQLException {
206         /**@todo: Implement this java.sql.ResultSet.getBinaryStream method*/
207         throw Utils.createUnsupportedException("getBinaryStream");
208     }
209     
210     
211     public String JavaDoc getString(String JavaDoc columnName) throws SQLException {
212         return getString( findColumn( columnName ) );
213     }
214     public boolean getBoolean(String JavaDoc columnName) throws SQLException {
215         return getBoolean( findColumn( columnName ) );
216     }
217     public byte getByte(String JavaDoc columnName) throws SQLException {
218         return getByte( findColumn( columnName ) );
219     }
220     public short getShort(String JavaDoc columnName) throws SQLException {
221         return getShort( findColumn( columnName ) );
222     }
223     public int getInt(String JavaDoc columnName) throws SQLException {
224         return getInt( findColumn( columnName ) );
225     }
226     public long getLong(String JavaDoc columnName) throws SQLException {
227         return getLong( findColumn( columnName ) );
228     }
229     public float getFloat(String JavaDoc columnName) throws SQLException {
230         return getFloat( findColumn( columnName ) );
231     }
232     public double getDouble(String JavaDoc columnName) throws SQLException {
233         return getDouble( findColumn( columnName ) );
234     }
235     public BigDecimal getBigDecimal(String JavaDoc columnName, int scale) throws SQLException {
236         return getBigDecimal( findColumn( columnName ), scale );
237     }
238     public byte[] getBytes(String JavaDoc columnName) throws SQLException {
239         return getBytes( findColumn( columnName ) );
240     }
241     public Date getDate(String JavaDoc columnName) throws SQLException {
242         return getDate( findColumn( columnName ) );
243     }
244     public Time getTime(String JavaDoc columnName) throws SQLException {
245         return getTime( findColumn( columnName ) );
246     }
247     public Timestamp getTimestamp(String JavaDoc columnName) throws SQLException {
248         return getTimestamp( findColumn( columnName ) );
249     }
250     public InputStream JavaDoc getAsciiStream(String JavaDoc columnName) throws SQLException {
251         return getAsciiStream( findColumn( columnName ) );
252     }
253     public InputStream JavaDoc getUnicodeStream(String JavaDoc columnName) throws SQLException {
254         return getUnicodeStream( findColumn( columnName ) );
255     }
256     public InputStream JavaDoc getBinaryStream(String JavaDoc columnName) throws SQLException {
257         return getBinaryStream( findColumn( columnName ) );
258     }
259     
260     
261     public SQLWarning getWarnings(){
262         return null;
263     }
264     
265     
266     public void clearWarnings(){
267         //TODO support for Warnings
268
}
269     
270     
271     public String JavaDoc getCursorName(){
272         return null;
273     }
274     
275     
276     public ResultSetMetaData getMetaData(){
277         return metaData;
278     }
279     
280     
281     public Object JavaDoc getObject(int columnIndex) throws SQLException {
282         try{
283             Object JavaDoc obj = getValue(columnIndex).getApiObject();
284             wasNull = obj == null;
285             return obj;
286         }catch(Exception JavaDoc e){
287             throw Utils.createSQLException( e );
288         }
289     }
290     public Object JavaDoc getObject(String JavaDoc columnName) throws SQLException {
291         return getObject( findColumn( columnName ) );
292     }
293     
294     
295     public int findColumn(String JavaDoc columnName) throws SQLException {
296         return getCmd().findColumn(columnName) + 1;
297     }
298     
299
300     public Reader JavaDoc getCharacterStream(int columnIndex) throws SQLException {
301         /**@todo: Implement this java.sql.ResultSet.getCharacterStream method*/
302         throw Utils.createUnsupportedException("getCharacterStream");
303     }
304     
305     
306     public Reader JavaDoc getCharacterStream(String JavaDoc columnName) throws SQLException {
307         return getCharacterStream( findColumn( columnName ) );
308     }
309     
310     
311     public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
312         try{
313             MutableNumeric obj = getValue(columnIndex).getNumeric();
314             wasNull = obj == null;
315             if(wasNull) return null;
316             return obj.toBigDecimal();
317         }catch(Exception JavaDoc e){
318             throw Utils.createSQLException( e );
319         }
320     }
321     public BigDecimal getBigDecimal(String JavaDoc columnName) throws SQLException {
322         return getBigDecimal( findColumn( columnName ) );
323     }
324     public boolean isBeforeFirst() throws SQLException {
325         return getCmd().isBeforeFirst();
326     }
327     
328     
329     public boolean isAfterLast() throws SQLException {
330         try{
331             return getCmd().isAfterLast();
332         }catch(Exception JavaDoc e){
333             throw Utils.createSQLException(e);
334         }
335     }
336     
337     
338     public boolean isFirst() throws SQLException {
339         return getCmd().isFirst();
340     }
341     
342     
343     public boolean isLast() throws SQLException {
344         try{
345             return getCmd().isLast();
346         }catch(Exception JavaDoc e){
347             throw Utils.createSQLException(e);
348         }
349     }
350     
351     
352     public void beforeFirst() throws SQLException {
353         try{
354             moveToCurrentRow();
355             getCmd().beforeFirst();
356         }catch(Exception JavaDoc e){
357             throw Utils.createSQLException(e);
358         }
359     }
360     
361     
362     public boolean first() throws SQLException {
363         try{
364             if(st.rsType == ResultSet.TYPE_FORWARD_ONLY) throw Utils.createSQLException("ResultSet is forward only.");
365             moveToCurrentRow();
366             return getCmd().first();
367         }catch(Exception JavaDoc e){
368             throw Utils.createSQLException(e);
369         }
370     }
371     
372     
373     public boolean previous() throws SQLException {
374         try{
375             moveToCurrentRow();
376             return getCmd().previous();
377         }catch(Exception JavaDoc e){
378             throw Utils.createSQLException(e);
379         }
380     }
381     
382     
383     public boolean next() throws SQLException {
384         try{
385             moveToCurrentRow();
386             return getCmd().next();
387         }catch(Exception JavaDoc e){
388             throw Utils.createSQLException(e);
389         }
390     }
391     
392     
393     public boolean last() throws SQLException {
394         try{
395             moveToCurrentRow();
396             return getCmd().last();
397         }catch(Exception JavaDoc e){
398             throw Utils.createSQLException(e);
399         }
400     }
401     
402     
403     public void afterLast() throws SQLException {
404         try{
405             if(st.rsType == ResultSet.TYPE_FORWARD_ONLY) throw Utils.createSQLException("ResultSet is forward only.");
406             moveToCurrentRow();
407             getCmd().afterLast();
408         }catch(Exception JavaDoc e){
409             throw Utils.createSQLException(e);
410         }
411     }
412     
413     
414     public boolean absolute(int row) throws SQLException {
415         try{
416             moveToCurrentRow();
417             return getCmd().absolute(row);
418         }catch(Exception JavaDoc e){
419             throw Utils.createSQLException(e);
420         }
421     }
422     
423     
424     public boolean relative(int rows) throws SQLException {
425         try{
426             moveToCurrentRow();
427             return getCmd().relative(rows);
428         }catch(Exception JavaDoc e){
429             throw Utils.createSQLException(e);
430         }
431     }
432     
433     
434     public int getRow() throws SQLException {
435         try{
436             return getCmd().getRow();
437         }catch(Exception JavaDoc e){
438             throw Utils.createSQLException(e);
439         }
440     }
441     
442     
443     public void setFetchDirection(int direction){
444         fetchDirection = direction;
445     }
446     
447     
448     public int getFetchDirection(){
449         return fetchDirection;
450     }
451     
452     
453     public void setFetchSize(int rows){
454         fetchSize = rows;
455     }
456     
457     
458     public int getFetchSize(){
459         return fetchSize;
460     }
461     
462     
463     public int getType() throws SQLException {
464         return getCmd().join.isScrollable() ? ResultSet.TYPE_SCROLL_SENSITIVE : ResultSet.TYPE_FORWARD_ONLY;
465     }
466     
467     
468     public int getConcurrency(){
469         return isUpdatable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY;
470     }
471     
472     
473     public boolean rowUpdated(){
474         return false;
475     }
476     
477     
478     public boolean rowInserted() throws SQLException {
479         return getCmd().join.rowInserted();
480     }
481     
482     
483     public boolean rowDeleted() throws SQLException {
484         return getCmd().join.rowDeleted();
485     }
486     
487     
488     public void updateNull(int columnIndex) throws SQLException {
489         updateValue( columnIndex, null, SQLTokenizer.NULL);
490     }
491     public void updateBoolean(int columnIndex, boolean x) throws SQLException {
492         updateValue( columnIndex, x ? Boolean.TRUE : Boolean.FALSE, SQLTokenizer.BOOLEAN);
493     }
494     public void updateByte(int columnIndex, byte x) throws SQLException {
495         updateValue( columnIndex, Utils.getShort(x), SQLTokenizer.TINYINT);
496     }
497     public void updateShort(int columnIndex, short x) throws SQLException {
498         updateValue( columnIndex, Utils.getShort(x), SQLTokenizer.SMALLINT);
499     }
500     public void updateInt(int columnIndex, int x) throws SQLException {
501         updateValue( columnIndex, Utils.getInteger(x), SQLTokenizer.INT);
502     }
503     public void updateLong(int columnIndex, long x) throws SQLException {
504         updateValue( columnIndex, new Long JavaDoc(x), SQLTokenizer.BIGINT);
505     }
506     public void updateFloat(int columnIndex, float x) throws SQLException {
507         updateValue( columnIndex, new Float JavaDoc(x), SQLTokenizer.REAL);
508     }
509     public void updateDouble(int columnIndex, double x) throws SQLException {
510         updateValue( columnIndex, new Double JavaDoc(x), SQLTokenizer.DOUBLE);
511     }
512     public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
513         updateValue( columnIndex, x, SQLTokenizer.DECIMAL);
514     }
515     public void updateString(int columnIndex, String JavaDoc x) throws SQLException {
516         updateValue( columnIndex, x, SQLTokenizer.VARCHAR);
517     }
518     public void updateBytes(int columnIndex, byte[] x) throws SQLException {
519         updateValue( columnIndex, x, SQLTokenizer.VARBINARY);
520     }
521     public void updateDate(int columnIndex, Date x) throws SQLException {
522         updateValue( columnIndex, DateTime.valueOf(x), SQLTokenizer.DATE);
523     }
524     public void updateTime(int columnIndex, Time x) throws SQLException {
525         updateValue( columnIndex, DateTime.valueOf(x), SQLTokenizer.TIME);
526     }
527     public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
528         updateValue( columnIndex, DateTime.valueOf(x), SQLTokenizer.TIMESTAMP);
529     }
530     public void updateAsciiStream(int columnIndex, InputStream JavaDoc x, int length) throws SQLException {
531         updateValue( columnIndex, x, SQLTokenizer.LONGVARCHAR, length);
532     }
533     public void updateBinaryStream(int columnIndex, InputStream JavaDoc x, int length) throws SQLException {
534         updateValue( columnIndex, x, SQLTokenizer.LONGVARBINARY, length);
535     }
536     
537     
538     public void updateCharacterStream(int columnIndex, Reader JavaDoc x, int length) throws SQLException {
539         /**@todo: Implement this java.sql.ResultSet.updateCharacterStream method*/
540         throw Utils.createUnsupportedException("Reader object");
541     }
542     
543     
544     public void updateObject(int columnIndex, Object JavaDoc x, int scale) throws SQLException {
545         //TODO scale to consider
546
updateValue( columnIndex, x, -1);
547     }
548     
549     
550     public void updateObject(int columnIndex, Object JavaDoc x) throws SQLException {
551         updateValue( columnIndex, x, -1);
552     }
553     public void updateNull(String JavaDoc columnName) throws SQLException {
554         updateNull( findColumn( columnName ) );
555     }
556     public void updateBoolean(String JavaDoc columnName, boolean x) throws SQLException {
557         updateBoolean( findColumn( columnName ), x );
558     }
559     public void updateByte(String JavaDoc columnName, byte x) throws SQLException {
560         updateByte( findColumn( columnName ), x );
561     }
562     public void updateShort(String JavaDoc columnName, short x) throws SQLException {
563         updateShort( findColumn( columnName ), x );
564     }
565     public void updateInt(String JavaDoc columnName, int x) throws SQLException {
566         updateInt( findColumn( columnName ), x );
567     }
568     public void updateLong(String JavaDoc columnName, long x) throws SQLException {
569         updateLong( findColumn( columnName ), x );
570     }
571     public void updateFloat(String JavaDoc columnName, float x) throws SQLException {
572         updateFloat( findColumn( columnName ), x );
573     }
574     public void updateDouble(String JavaDoc columnName, double x) throws SQLException {
575         updateDouble( findColumn( columnName ), x );
576     }
577     public void updateBigDecimal(String JavaDoc columnName, BigDecimal x) throws SQLException {
578         updateBigDecimal( findColumn( columnName ), x );
579     }
580     public void updateString(String JavaDoc columnName, String JavaDoc x) throws SQLException {
581         updateString( findColumn( columnName ), x );
582     }
583     public void updateBytes(String JavaDoc columnName, byte[] x) throws SQLException {
584         updateBytes( findColumn( columnName ), x );
585     }
586     public void updateDate(String JavaDoc columnName, Date x) throws SQLException {
587         updateDate( findColumn( columnName ), x );
588     }
589     public void updateTime(String JavaDoc columnName, Time x) throws SQLException {
590         updateTime( findColumn( columnName ), x );
591     }
592     public void updateTimestamp(String JavaDoc columnName, Timestamp x) throws SQLException {
593         updateTimestamp( findColumn( columnName ), x );
594     }
595     public void updateAsciiStream(String JavaDoc columnName, InputStream JavaDoc x, int length) throws SQLException {
596         updateAsciiStream( findColumn( columnName ), x, length );
597     }
598     public void updateBinaryStream(String JavaDoc columnName, InputStream JavaDoc x, int length) throws SQLException {
599         updateBinaryStream( findColumn( columnName ), x, length );
600     }
601     public void updateCharacterStream(String JavaDoc columnName, Reader JavaDoc x, int length) throws SQLException {
602         updateCharacterStream( findColumn( columnName ), x, length );
603     }
604     public void updateObject(String JavaDoc columnName, Object JavaDoc x, int scale) throws SQLException {
605         updateObject( findColumn( columnName ), x, scale );
606     }
607     public void updateObject(String JavaDoc columnName, Object JavaDoc x) throws SQLException {
608         updateObject( findColumn( columnName ), x );
609     }
610     public void insertRow() throws SQLException {
611         st.con.log.println("insertRow()");
612         getCmd().insertRow( st.con, values);
613         cancelRowUpdates();
614     }
615     
616     
617     public void updateRow() throws SQLException {
618         try {
619             if(values == null) return;
620             st.con.log.println("updateRow()");
621             final CommandSelect command = getCmd();
622             command.updateRow( st.con, values);
623             command.relative(0); //refresh the row
624
cancelRowUpdates();
625         } catch (Exception JavaDoc e) {
626             throw Utils.createSQLException(e);
627         }
628     }
629     
630     
631     public void deleteRow() throws SQLException {
632         st.con.log.println("deleteRow()");
633         getCmd().deleteRow(st.con);
634         cancelRowUpdates();
635     }
636     public void refreshRow() throws SQLException {
637         relative(0);
638     }
639     
640
641     public void cancelRowUpdates() {
642         if(values != null){
643             for(int i=values.length-1; i>=0; i--){
644                 values[i].clear();
645             }
646         }
647     }
648     
649
650     public void moveToInsertRow() throws SQLException {
651         if(isUpdatable){
652             isInsertRow = true;
653         }else{
654             throw Utils.createSQLException("ResultSet is read only.");
655         }
656     }
657     
658     
659     public void moveToCurrentRow(){
660         isInsertRow = false;
661         cancelRowUpdates();
662     }
663     
664     
665     public Statement getStatement() {
666         return st;
667     }
668     
669     
670     public Object JavaDoc getObject(int i, Map JavaDoc map) throws SQLException {
671         return getObject( i );
672     }
673     
674     
675     public Ref getRef(int i) throws SQLException {
676         /**@todo: Implement this java.sql.ResultSet.getRef method*/
677         throw Utils.createUnsupportedException("Ref object");
678     }
679     
680     
681     public Blob getBlob(int i) throws SQLException {
682         /**@todo: Implement this java.sql.ResultSet.getBlob method*/
683         throw Utils.createUnsupportedException("Blob object");
684     }
685     
686     
687     public Clob getClob(int i) throws SQLException {
688         /**@todo: Implement this java.sql.ResultSet.getClob method*/
689         throw Utils.createUnsupportedException("Clob object");
690     }
691     
692     
693     public Array getArray(int i) throws SQLException {
694         /**@todo: Implement this java.sql.ResultSet.getArray method*/
695         throw Utils.createUnsupportedException("Array");
696     }
697     
698     
699     public Object JavaDoc getObject(String JavaDoc columnName, Map JavaDoc map) throws SQLException {
700         return getObject( columnName );
701     }
702     public Ref getRef(String JavaDoc columnName) throws SQLException {
703         return getRef( findColumn( columnName ) );
704     }
705     public Blob getBlob(String JavaDoc columnName) throws SQLException {
706         return getBlob( findColumn( columnName ) );
707     }
708     public Clob getClob(String JavaDoc columnName) throws SQLException {
709         return getClob( findColumn( columnName ) );
710     }
711     public Array getArray(String JavaDoc columnName) throws SQLException {
712         return getArray( findColumn( columnName ) );
713     }
714     
715     
716     public Date getDate(int columnIndex, Calendar JavaDoc cal) throws SQLException {
717         try{
718             if(cal == null){
719                 return getDate(columnIndex);
720             }
721             Expression expr = getValue(columnIndex);
722             wasNull = expr.isNull();
723             if(wasNull) return null;
724             return new Date(DateTime.addDateTimeOffset( expr.getLong(), cal.getTimeZone() ));
725         }catch(Exception JavaDoc e){
726             throw Utils.createSQLException( e );
727         }
728     }
729     
730     
731     public Date getDate(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException {
732         return getDate( findColumn( columnName ), cal );
733     }
734     
735     
736     public Time getTime(int columnIndex, Calendar JavaDoc cal) throws SQLException {
737         try{
738             if(cal == null){
739                 return getTime(columnIndex);
740             }
741             Expression expr = getValue(columnIndex);
742             wasNull = expr.isNull();
743             if(wasNull) return null;
744             return new Time(DateTime.addDateTimeOffset( expr.getLong(), cal.getTimeZone() ));
745         }catch(Exception JavaDoc e){
746             throw Utils.createSQLException( e );
747         }
748     }
749     
750     
751     public Time getTime(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException {
752         return getTime( findColumn( columnName ), cal );
753     }
754     
755     
756     public Timestamp getTimestamp(int columnIndex, Calendar JavaDoc cal) throws SQLException {
757         try{
758             if(cal == null){
759                 return getTimestamp(columnIndex);
760             }
761             Expression expr = getValue(columnIndex);
762             wasNull = expr.isNull();
763             if(wasNull) return null;
764             return new Timestamp(DateTime.addDateTimeOffset( expr.getLong(), cal.getTimeZone() ));
765         }catch(Exception JavaDoc e){
766             throw Utils.createSQLException( e );
767         }
768     }
769     
770     
771     public Timestamp getTimestamp(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException {
772         return getTimestamp( findColumn( columnName ), cal );
773     }
774     
775     
776     public URL JavaDoc getURL(int columnIndex) throws SQLException {
777         try{
778             Expression expr = getValue(columnIndex);
779             wasNull = expr.isNull();
780             if(wasNull) return null;
781             return new URL JavaDoc( expr.getString() );
782         }catch(Exception JavaDoc e){
783             throw Utils.createSQLException( e );
784         }
785     }
786     
787     
788     public URL JavaDoc getURL(String JavaDoc columnName) throws SQLException {
789         return getURL( findColumn( columnName ) );
790     }
791     
792     
793     public void updateRef(int columnIndex, Ref x) throws SQLException {
794         /**@todo: Implement this java.sql.ResultSet.updateRef method*/
795         throw Utils.createUnsupportedException("Ref");
796     }
797     
798     
799     public void updateRef(String JavaDoc columnName, Ref x) throws SQLException {
800         updateRef( findColumn( columnName ), x );
801     }
802     
803     
804     public void updateBlob(int columnIndex, Blob x) throws SQLException {
805         /**@todo: Implement this java.sql.ResultSet.updateBlob method*/
806         throw Utils.createUnsupportedException("Blob");
807     }
808     
809     
810     public void updateBlob(String JavaDoc columnName, Blob x) throws SQLException {
811         updateBlob( findColumn( columnName ), x );
812     }
813     
814     
815     public void updateClob(int columnIndex, Clob x) throws SQLException {
816         /**@todo: Implement this java.sql.ResultSet.updateClob method*/
817         throw Utils.createUnsupportedException("Clob");
818     }
819     
820     
821     public void updateClob(String JavaDoc columnName, Clob x) throws SQLException {
822         updateClob( findColumn( columnName ), x );
823     }
824     
825     
826     public void updateArray(int columnIndex, Array x) throws SQLException {
827         /**@todo: Implement this java.sql.ResultSet.updateArray method*/
828         throw Utils.createUnsupportedException("Array");
829     }
830     
831     
832     public void updateArray(String JavaDoc columnName, Array x) throws SQLException {
833         updateArray( findColumn( columnName ), x );
834     }
835     
836     /*========================================================
837
838     private methods
839
840     =========================================================*/

841
842     /**
843      * Get the expression of a column.
844      * This expression can be used to request a value of the current row.
845      */

846     final private Expression getValue(int columnIndex) throws SQLException{
847         if(values != null){
848             ExpressionValue value = values[ metaData.getColumnIdx( columnIndex ) ];
849             if(!value.isEmpty())
850                 return value;
851         }
852         return metaData.getColumnExpression(columnIndex);
853     }
854     
855
856     final private ExpressionValue getUpdateValue(int columnIndex) throws SQLException{
857         if(values == null){
858             int count = metaData.getColumnCount();
859             values = new ExpressionValue[count];
860             while(count-- > 0){
861                 values[count] = new ExpressionValue();
862             }
863         }
864         return values[ metaData.getColumnIdx( columnIndex ) ];
865     }
866     
867     
868     final private void updateValue(int columnIndex, Object JavaDoc x, int dataType) throws SQLException{
869         getUpdateValue( columnIndex ).set( x, dataType );
870         if(st.con.log.isLogging()){
871             
872             st.con.log.println("parameter '"+metaData.getColumnName(columnIndex)+"' = "+x+"; type="+dataType);
873         }
874     }
875     
876     
877     final private void updateValue(int columnIndex, Object JavaDoc x, int dataType, int length) throws SQLException{
878         getUpdateValue( columnIndex ).set( x, dataType, length );
879         if(st.con.log.isLogging()){
880             st.con.log.println("parameter '"+metaData.getColumnName(columnIndex)+"' = "+x+"; type="+dataType+"; length="+length);
881         }
882     }
883
884
885     final private CommandSelect getCmd() throws SQLException {
886         if(cmd == null) throw Utils.createSQLException("ResultSet is closed.");
887         return cmd;
888     }
889 }
Popular Tags