KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > TesterResultSet


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.dbcp;
18
19 import java.math.BigDecimal JavaDoc;
20 import java.sql.Array JavaDoc;
21 import java.sql.Blob JavaDoc;
22 import java.sql.Clob JavaDoc;
23 import java.sql.Ref JavaDoc;
24 import java.sql.ResultSet JavaDoc;
25 import java.sql.ResultSetMetaData JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.sql.SQLWarning JavaDoc;
28 import java.sql.Statement JavaDoc;
29 import java.util.Calendar JavaDoc;
30
31 /**
32  * A dummy {@link ResultSet}, for testing purposes.
33  *
34  * @author Rodney Waldhoff
35  * @author Dirk Verbeeck
36  * @version $Revision: 1.13 $ $Date: 2004/03/27 17:47:34 $
37  */

38 public class TesterResultSet implements ResultSet JavaDoc {
39     public TesterResultSet(Statement JavaDoc stmt) {
40         _statement = stmt;
41     }
42
43     public TesterResultSet(Statement JavaDoc stmt, Object JavaDoc[][] data) {
44         _statement = stmt;
45         _data = data;
46     }
47
48     public TesterResultSet(Statement JavaDoc stmt, Object JavaDoc[][] data, int type, int concurrency) {
49         _statement = stmt;
50         _data = data;
51         _type = type;
52         _concurrency = concurrency;
53     }
54     
55     protected int _type = ResultSet.TYPE_FORWARD_ONLY;
56     protected int _concurrency = ResultSet.CONCUR_READ_ONLY;
57
58     protected Object JavaDoc[][] _data = null;
59     protected int _currentRow = -1;
60     
61     protected Statement JavaDoc _statement = null;
62     protected int _rowsLeft = 2;
63     protected boolean _open = true;
64
65     public boolean next() throws SQLException JavaDoc {
66         checkOpen();
67         if (_data != null) {
68             _currentRow++;
69             return _currentRow < _data.length;
70         }
71         else {
72             if(--_rowsLeft > 0) {
73                 return true;
74             } else {
75                 return false;
76             }
77         }
78     }
79
80     public void close() throws SQLException JavaDoc {
81         checkOpen();
82         ((TesterStatement)_statement)._resultSet = null;
83         _open = false;
84     }
85
86     public boolean wasNull() throws SQLException JavaDoc {
87         checkOpen();
88         return false;
89     }
90
91     public String JavaDoc getString(int columnIndex) throws SQLException JavaDoc {
92         checkOpen();
93         if (columnIndex == -1) {
94             throw new SQLException JavaDoc("broken connection");
95         }
96         if (_data != null) {
97             return (String JavaDoc) getObject(columnIndex);
98         }
99         return "String" + columnIndex;
100     }
101
102     public boolean getBoolean(int columnIndex) throws SQLException JavaDoc {
103         checkOpen();
104         return true;
105     }
106
107     public byte getByte(int columnIndex) throws SQLException JavaDoc {
108         checkOpen();
109         return (byte)columnIndex;
110     }
111
112     public short getShort(int columnIndex) throws SQLException JavaDoc {
113         checkOpen();
114         return (short)columnIndex;
115     }
116
117     public int getInt(int columnIndex) throws SQLException JavaDoc {
118         checkOpen();
119         return (short)columnIndex;
120     }
121
122     public long getLong(int columnIndex) throws SQLException JavaDoc {
123         checkOpen();
124         return (long)columnIndex;
125     }
126
127     public float getFloat(int columnIndex) throws SQLException JavaDoc {
128         checkOpen();
129         return (float)columnIndex;
130     }
131
132     public double getDouble(int columnIndex) throws SQLException JavaDoc {
133         checkOpen();
134         return (double)columnIndex;
135     }
136
137     /** @deprecated */
138     public BigDecimal JavaDoc getBigDecimal(int columnIndex, int scale) throws SQLException JavaDoc {
139         checkOpen();
140         return new BigDecimal JavaDoc((double)columnIndex);
141     }
142
143     public byte[] getBytes(int columnIndex) throws SQLException JavaDoc {
144         checkOpen();
145         return new byte[] { (byte)columnIndex };
146     }
147
148     public java.sql.Date JavaDoc getDate(int columnIndex) throws SQLException JavaDoc {
149         checkOpen();
150         return null;
151     }
152
153     public java.sql.Time JavaDoc getTime(int columnIndex) throws SQLException JavaDoc {
154         checkOpen();
155         return null;
156     }
157
158     public java.sql.Timestamp JavaDoc getTimestamp(int columnIndex) throws SQLException JavaDoc {
159         checkOpen();
160         return null;
161     }
162
163     public java.io.InputStream JavaDoc getAsciiStream(int columnIndex) throws SQLException JavaDoc {
164         checkOpen();
165         return null;
166     }
167
168     /** @deprecated */
169     public java.io.InputStream JavaDoc getUnicodeStream(int columnIndex) throws SQLException JavaDoc {
170         checkOpen();
171         return null;
172     }
173
174     public java.io.InputStream JavaDoc getBinaryStream(int columnIndex) throws SQLException JavaDoc {
175         checkOpen();
176         return null;
177     }
178
179     public String JavaDoc getString(String JavaDoc columnName) throws SQLException JavaDoc {
180         checkOpen();
181         return columnName;
182     }
183
184     public boolean getBoolean(String JavaDoc columnName) throws SQLException JavaDoc {
185         checkOpen();
186         return true;
187     }
188
189     public byte getByte(String JavaDoc columnName) throws SQLException JavaDoc {
190         checkOpen();
191         return (byte)(columnName.hashCode());
192     }
193
194     public short getShort(String JavaDoc columnName) throws SQLException JavaDoc {
195         checkOpen();
196         return (short)(columnName.hashCode());
197     }
198
199     public int getInt(String JavaDoc columnName) throws SQLException JavaDoc {
200         checkOpen();
201         return (columnName.hashCode());
202     }
203
204     public long getLong(String JavaDoc columnName) throws SQLException JavaDoc {
205         checkOpen();
206         return (long)(columnName.hashCode());
207     }
208
209     public float getFloat(String JavaDoc columnName) throws SQLException JavaDoc {
210         checkOpen();
211         return (float)(columnName.hashCode());
212     }
213
214     public double getDouble(String JavaDoc columnName) throws SQLException JavaDoc {
215         checkOpen();
216         return (double)(columnName.hashCode());
217     }
218
219     /** @deprecated */
220     public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName, int scale) throws SQLException JavaDoc {
221         checkOpen();
222         return new BigDecimal JavaDoc((double)columnName.hashCode());
223     }
224
225     public byte[] getBytes(String JavaDoc columnName) throws SQLException JavaDoc {
226         checkOpen();
227         return columnName.getBytes();
228     }
229
230     public java.sql.Date JavaDoc getDate(String JavaDoc columnName) throws SQLException JavaDoc {
231         checkOpen();
232         return null;
233     }
234
235     public java.sql.Time JavaDoc getTime(String JavaDoc columnName) throws SQLException JavaDoc {
236         checkOpen();
237         return null;
238     }
239
240     public java.sql.Timestamp JavaDoc getTimestamp(String JavaDoc columnName) throws SQLException JavaDoc {
241         checkOpen();
242         return null;
243     }
244
245     public java.io.InputStream JavaDoc getAsciiStream(String JavaDoc columnName) throws SQLException JavaDoc {
246         checkOpen();
247         return null;
248     }
249
250     /** @deprecated */
251     public java.io.InputStream JavaDoc getUnicodeStream(String JavaDoc columnName) throws SQLException JavaDoc {
252         checkOpen();
253         return null;
254     }
255
256     public java.io.InputStream JavaDoc getBinaryStream(String JavaDoc columnName) throws SQLException JavaDoc {
257         checkOpen();
258         return null;
259     }
260
261    public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
262        checkOpen();
263        return null;
264    }
265
266     public void clearWarnings() throws SQLException JavaDoc {
267         checkOpen();
268     }
269
270     public String JavaDoc getCursorName() throws SQLException JavaDoc {
271         checkOpen();
272         return null;
273     }
274
275     public ResultSetMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
276         checkOpen();
277         return null;
278     }
279
280     public Object JavaDoc getObject(int columnIndex) throws SQLException JavaDoc {
281         checkOpen();
282         if (_data != null) {
283             return _data[_currentRow][columnIndex-1];
284         }
285         return new Object JavaDoc();
286     }
287
288     public Object JavaDoc getObject(String JavaDoc columnName) throws SQLException JavaDoc {
289         checkOpen();
290         return columnName;
291     }
292
293     public int findColumn(String JavaDoc columnName) throws SQLException JavaDoc {
294         checkOpen();
295         return 1;
296     }
297
298
299     public java.io.Reader JavaDoc getCharacterStream(int columnIndex) throws SQLException JavaDoc {
300         checkOpen();
301         return null;
302     }
303
304     public java.io.Reader JavaDoc getCharacterStream(String JavaDoc columnName) throws SQLException JavaDoc {
305         checkOpen();
306         return null;
307     }
308
309     public BigDecimal JavaDoc getBigDecimal(int columnIndex) throws SQLException JavaDoc {
310         checkOpen();
311         return new BigDecimal JavaDoc((double)columnIndex);
312     }
313
314     public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName) throws SQLException JavaDoc {
315         checkOpen();
316         return new BigDecimal JavaDoc((double)columnName.hashCode());
317     }
318
319     public boolean isBeforeFirst() throws SQLException JavaDoc {
320         checkOpen();
321         return _rowsLeft == 2;
322     }
323
324     public boolean isAfterLast() throws SQLException JavaDoc {
325         checkOpen();
326         return _rowsLeft < 0;
327     }
328
329     public boolean isFirst() throws SQLException JavaDoc {
330         checkOpen();
331         return _rowsLeft == 1;
332     }
333
334     public boolean isLast() throws SQLException JavaDoc {
335         checkOpen();
336         return _rowsLeft == 0;
337     }
338
339     public void beforeFirst() throws SQLException JavaDoc {
340         checkOpen();
341     }
342
343     public void afterLast() throws SQLException JavaDoc {
344         checkOpen();
345     }
346
347     public boolean first() throws SQLException JavaDoc {
348         checkOpen();
349         return false;
350     }
351
352     public boolean last() throws SQLException JavaDoc {
353         checkOpen();
354         return false;
355     }
356
357     public int getRow() throws SQLException JavaDoc {
358         checkOpen();
359         return 3 - _rowsLeft;
360     }
361
362     public boolean absolute( int row ) throws SQLException JavaDoc {
363         checkOpen();
364         return false;
365     }
366
367     public boolean relative( int rows ) throws SQLException JavaDoc {
368         checkOpen();
369         return false;
370     }
371
372     public boolean previous() throws SQLException JavaDoc {
373         checkOpen();
374         return false;
375     }
376
377     public void setFetchDirection(int direction) throws SQLException JavaDoc {
378         checkOpen();
379     }
380
381     public int getFetchDirection() throws SQLException JavaDoc {
382         checkOpen();
383         return 1;
384     }
385
386     public void setFetchSize(int rows) throws SQLException JavaDoc {
387         checkOpen();
388     }
389
390     public int getFetchSize() throws SQLException JavaDoc {
391         checkOpen();
392         return 2;
393     }
394
395     public int getType() throws SQLException JavaDoc {
396         return this._type;
397     }
398
399     public int getConcurrency() throws SQLException JavaDoc {
400         return this._concurrency;
401     }
402
403     public boolean rowUpdated() throws SQLException JavaDoc {
404         checkOpen();
405         return false;
406     }
407
408     public boolean rowInserted() throws SQLException JavaDoc {
409         checkOpen();
410         return false;
411     }
412
413     public boolean rowDeleted() throws SQLException JavaDoc {
414         checkOpen();
415         return false;
416     }
417
418     public void updateNull(int columnIndex) throws SQLException JavaDoc {
419         checkOpen();
420     }
421
422     public void updateBoolean(int columnIndex, boolean x) throws SQLException JavaDoc {
423         checkOpen();
424     }
425
426     public void updateByte(int columnIndex, byte x) throws SQLException JavaDoc {
427         checkOpen();
428     }
429
430     public void updateShort(int columnIndex, short x) throws SQLException JavaDoc {
431         checkOpen();
432     }
433
434     public void updateInt(int columnIndex, int x) throws SQLException JavaDoc {
435         checkOpen();
436     }
437
438     public void updateLong(int columnIndex, long x) throws SQLException JavaDoc {
439         checkOpen();
440     }
441
442     public void updateFloat(int columnIndex, float x) throws SQLException JavaDoc {
443         checkOpen();
444     }
445
446     public void updateDouble(int columnIndex, double x) throws SQLException JavaDoc {
447         checkOpen();
448     }
449
450     public void updateBigDecimal(int columnIndex, BigDecimal JavaDoc x) throws SQLException JavaDoc {
451         checkOpen();
452     }
453
454     public void updateString(int columnIndex, String JavaDoc x) throws SQLException JavaDoc {
455         checkOpen();
456     }
457
458     public void updateBytes(int columnIndex, byte x[]) throws SQLException JavaDoc {
459         checkOpen();
460     }
461
462     public void updateDate(int columnIndex, java.sql.Date JavaDoc x) throws SQLException JavaDoc {
463         checkOpen();
464     }
465
466     public void updateTime(int columnIndex, java.sql.Time JavaDoc x) throws SQLException JavaDoc {
467         checkOpen();
468     }
469
470     public void updateTimestamp(int columnIndex, java.sql.Timestamp JavaDoc x) throws SQLException JavaDoc {
471         checkOpen();
472     }
473
474
475     public void updateAsciiStream(int columnIndex,
476                java.io.InputStream JavaDoc x,
477                int length) throws SQLException JavaDoc {
478         checkOpen();
479     }
480
481     public void updateBinaryStream(int columnIndex,
482                 java.io.InputStream JavaDoc x,
483                 int length) throws SQLException JavaDoc {
484         checkOpen();
485     }
486
487     public void updateCharacterStream(int columnIndex,
488                  java.io.Reader JavaDoc x,
489                  int length) throws SQLException JavaDoc {
490         checkOpen();
491     }
492
493     public void updateObject(int columnIndex, Object JavaDoc x, int scale)
494       throws SQLException JavaDoc {
495         checkOpen();
496     }
497
498     public void updateObject(int columnIndex, Object JavaDoc x) throws SQLException JavaDoc {
499         checkOpen();
500     }
501
502     public void updateNull(String JavaDoc columnName) throws SQLException JavaDoc {
503         checkOpen();
504     }
505
506     public void updateBoolean(String JavaDoc columnName, boolean x) throws SQLException JavaDoc {
507         checkOpen();
508     }
509
510     public void updateByte(String JavaDoc columnName, byte x) throws SQLException JavaDoc {
511         checkOpen();
512     }
513
514     public void updateShort(String JavaDoc columnName, short x) throws SQLException JavaDoc {
515         checkOpen();
516     }
517
518     public void updateInt(String JavaDoc columnName, int x) throws SQLException JavaDoc {
519         checkOpen();
520     }
521
522     public void updateLong(String JavaDoc columnName, long x) throws SQLException JavaDoc {
523         checkOpen();
524     }
525
526     public void updateFloat(String JavaDoc columnName, float x) throws SQLException JavaDoc {
527         checkOpen();
528     }
529
530     public void updateDouble(String JavaDoc columnName, double x) throws SQLException JavaDoc {
531         checkOpen();
532     }
533
534     public void updateBigDecimal(String JavaDoc columnName, BigDecimal JavaDoc x) throws SQLException JavaDoc {
535         checkOpen();
536     }
537
538     public void updateString(String JavaDoc columnName, String JavaDoc x) throws SQLException JavaDoc {
539         checkOpen();
540     }
541
542     public void updateBytes(String JavaDoc columnName, byte x[]) throws SQLException JavaDoc {
543         checkOpen();
544     }
545
546     public void updateDate(String JavaDoc columnName, java.sql.Date JavaDoc x) throws SQLException JavaDoc {
547         checkOpen();
548     }
549
550     public void updateTime(String JavaDoc columnName, java.sql.Time JavaDoc x) throws SQLException JavaDoc {
551         checkOpen();
552     }
553
554     public void updateTimestamp(String JavaDoc columnName, java.sql.Timestamp JavaDoc x)
555       throws SQLException JavaDoc {
556         checkOpen();
557     }
558
559     public void updateAsciiStream(String JavaDoc columnName,
560                java.io.InputStream JavaDoc x,
561                int length) throws SQLException JavaDoc {
562         checkOpen();
563     }
564
565     public void updateBinaryStream(String JavaDoc columnName,
566                 java.io.InputStream JavaDoc x,
567                 int length) throws SQLException JavaDoc {
568         checkOpen();
569     }
570
571     public void updateCharacterStream(String JavaDoc columnName,
572                  java.io.Reader JavaDoc reader,
573                  int length) throws SQLException JavaDoc {
574         checkOpen();
575     }
576
577     public void updateObject(String JavaDoc columnName, Object JavaDoc x, int scale)
578       throws SQLException JavaDoc {
579         checkOpen();
580     }
581
582     public void updateObject(String JavaDoc columnName, Object JavaDoc x) throws SQLException JavaDoc {
583         checkOpen();
584     }
585
586     public void insertRow() throws SQLException JavaDoc {
587         checkOpen();
588     }
589
590     public void updateRow() throws SQLException JavaDoc {
591         checkOpen();
592     }
593
594     public void deleteRow() throws SQLException JavaDoc {
595         checkOpen();
596     }
597
598     public void refreshRow() throws SQLException JavaDoc {
599         checkOpen();
600     }
601
602     public void cancelRowUpdates() throws SQLException JavaDoc {
603         checkOpen();
604     }
605
606     public void moveToInsertRow() throws SQLException JavaDoc {
607         checkOpen();
608     }
609
610     public void moveToCurrentRow() throws SQLException JavaDoc {
611         checkOpen();
612     }
613
614     public Statement JavaDoc getStatement() throws SQLException JavaDoc {
615         checkOpen();
616         return _statement;
617     }
618
619
620     public Object JavaDoc getObject(int i, java.util.Map JavaDoc map) throws SQLException JavaDoc {
621         checkOpen();
622         return new Object JavaDoc();
623     }
624
625     public Ref JavaDoc getRef(int i) throws SQLException JavaDoc {
626         checkOpen();
627         return null;
628     }
629
630     public Blob JavaDoc getBlob(int i) throws SQLException JavaDoc {
631         checkOpen();
632         return null;
633     }
634
635     public Clob JavaDoc getClob(int i) throws SQLException JavaDoc {
636         checkOpen();
637         return null;
638     }
639
640     public Array JavaDoc getArray(int i) throws SQLException JavaDoc {
641         checkOpen();
642         return null;
643     }
644
645     public Object JavaDoc getObject(String JavaDoc colName, java.util.Map JavaDoc map) throws SQLException JavaDoc {
646         checkOpen();
647         return colName;
648     }
649
650     public Ref JavaDoc getRef(String JavaDoc colName) throws SQLException JavaDoc {
651         checkOpen();
652         return null;
653     }
654
655     public Blob JavaDoc getBlob(String JavaDoc colName) throws SQLException JavaDoc {
656         checkOpen();
657         return null;
658     }
659
660     public Clob JavaDoc getClob(String JavaDoc colName) throws SQLException JavaDoc {
661         checkOpen();
662         return null;
663     }
664
665     public Array JavaDoc getArray(String JavaDoc colName) throws SQLException JavaDoc {
666         checkOpen();
667         return null;
668     }
669
670     public java.sql.Date JavaDoc getDate(int columnIndex, Calendar JavaDoc cal) throws SQLException JavaDoc {
671         checkOpen();
672         return null;
673     }
674
675     public java.sql.Date JavaDoc getDate(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException JavaDoc {
676         checkOpen();
677         return null;
678     }
679
680     public java.sql.Time JavaDoc getTime(int columnIndex, Calendar JavaDoc cal) throws SQLException JavaDoc {
681         checkOpen();
682         return null;
683     }
684
685     public java.sql.Time JavaDoc getTime(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException JavaDoc {
686         checkOpen();
687         return null;
688     }
689
690     public java.sql.Timestamp JavaDoc getTimestamp(int columnIndex, Calendar JavaDoc cal) throws SQLException JavaDoc {
691         checkOpen();
692         return null;
693     }
694
695     public java.sql.Timestamp JavaDoc getTimestamp(String JavaDoc columnName, Calendar JavaDoc cal)
696       throws SQLException JavaDoc {
697         checkOpen();
698         return null;
699     }
700
701     protected void checkOpen() throws SQLException JavaDoc {
702         if(!_open) {
703             throw new SQLException JavaDoc("ResultSet is closed.");
704         }
705     }
706
707     // ------------------- JDBC 3.0 -----------------------------------------
708
// Will be commented by the build process on a JDBC 2.0 system
709

710 /* JDBC_3_ANT_KEY_BEGIN */
711
712     public java.net.URL JavaDoc getURL(int columnIndex) throws SQLException JavaDoc {
713         throw new SQLException JavaDoc("Not implemented.");
714     }
715
716     public java.net.URL JavaDoc getURL(String JavaDoc columnName) throws SQLException JavaDoc {
717         throw new SQLException JavaDoc("Not implemented.");
718     }
719
720     public void updateRef(int columnIndex, java.sql.Ref JavaDoc x)
721         throws SQLException JavaDoc {
722         throw new SQLException JavaDoc("Not implemented.");
723     }
724
725     public void updateRef(String JavaDoc columnName, java.sql.Ref JavaDoc x)
726         throws SQLException JavaDoc {
727         throw new SQLException JavaDoc("Not implemented.");
728     }
729
730     public void updateBlob(int columnIndex, java.sql.Blob JavaDoc x)
731         throws SQLException JavaDoc {
732         throw new SQLException JavaDoc("Not implemented.");
733     }
734
735     public void updateBlob(String JavaDoc columnName, java.sql.Blob JavaDoc x)
736         throws SQLException JavaDoc {
737         throw new SQLException JavaDoc("Not implemented.");
738     }
739
740     public void updateClob(int columnIndex, java.sql.Clob JavaDoc x)
741         throws SQLException JavaDoc {
742         throw new SQLException JavaDoc("Not implemented.");
743     }
744
745     public void updateClob(String JavaDoc columnName, java.sql.Clob JavaDoc x)
746         throws SQLException JavaDoc {
747         throw new SQLException JavaDoc("Not implemented.");
748     }
749
750     public void updateArray(int columnIndex, java.sql.Array JavaDoc x)
751         throws SQLException JavaDoc {
752         throw new SQLException JavaDoc("Not implemented.");
753     }
754
755     public void updateArray(String JavaDoc columnName, java.sql.Array JavaDoc x)
756         throws SQLException JavaDoc {
757         throw new SQLException JavaDoc("Not implemented.");
758     }
759
760 /* JDBC_3_ANT_KEY_END */
761
762 }
763
Popular Tags