001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.dbcp;
019:
020: import java.math.BigDecimal;
021: import java.sql.Array;
022: import java.sql.Blob;
023: import java.sql.Clob;
024: import java.sql.Ref;
025: import java.sql.ResultSet;
026: import java.sql.ResultSetMetaData;
027: import java.sql.SQLException;
028: import java.sql.SQLWarning;
029: import java.sql.Statement;
030: import java.util.Calendar;
031:
032: /**
033: * A dummy {@link ResultSet}, for testing purposes.
034: *
035: * @author Rodney Waldhoff
036: * @author Dirk Verbeeck
037: * @version $Revision: 479142 $ $Date: 2006-11-25 09:31:27 -0700 (Sat, 25 Nov 2006) $
038: */
039: public class TesterResultSet implements ResultSet {
040: public TesterResultSet(Statement stmt) {
041: _statement = stmt;
042: }
043:
044: public TesterResultSet(Statement stmt, Object[][] data) {
045: _statement = stmt;
046: _data = data;
047: }
048:
049: public TesterResultSet(Statement stmt, Object[][] data, int type,
050: int concurrency) {
051: _statement = stmt;
052: _data = data;
053: _type = type;
054: _concurrency = concurrency;
055: }
056:
057: protected int _type = ResultSet.TYPE_FORWARD_ONLY;
058: protected int _concurrency = ResultSet.CONCUR_READ_ONLY;
059:
060: protected Object[][] _data = null;
061: protected int _currentRow = -1;
062:
063: protected Statement _statement = null;
064: protected int _rowsLeft = 2;
065: protected boolean _open = true;
066:
067: public boolean next() throws SQLException {
068: checkOpen();
069: if (_data != null) {
070: _currentRow++;
071: return _currentRow < _data.length;
072: } else {
073: if (--_rowsLeft > 0) {
074: return true;
075: } else {
076: return false;
077: }
078: }
079: }
080:
081: public void close() throws SQLException {
082: checkOpen();
083: ((TesterStatement) _statement)._resultSet = null;
084: _open = false;
085: }
086:
087: public boolean wasNull() throws SQLException {
088: checkOpen();
089: return false;
090: }
091:
092: public String getString(int columnIndex) throws SQLException {
093: checkOpen();
094: if (columnIndex == -1) {
095: throw new SQLException("broken connection");
096: }
097: if (_data != null) {
098: return (String) getObject(columnIndex);
099: }
100: return "String" + columnIndex;
101: }
102:
103: public boolean getBoolean(int columnIndex) throws SQLException {
104: checkOpen();
105: return true;
106: }
107:
108: public byte getByte(int columnIndex) throws SQLException {
109: checkOpen();
110: return (byte) columnIndex;
111: }
112:
113: public short getShort(int columnIndex) throws SQLException {
114: checkOpen();
115: return (short) columnIndex;
116: }
117:
118: public int getInt(int columnIndex) throws SQLException {
119: checkOpen();
120: return (short) columnIndex;
121: }
122:
123: public long getLong(int columnIndex) throws SQLException {
124: checkOpen();
125: return (long) columnIndex;
126: }
127:
128: public float getFloat(int columnIndex) throws SQLException {
129: checkOpen();
130: return (float) columnIndex;
131: }
132:
133: public double getDouble(int columnIndex) throws SQLException {
134: checkOpen();
135: return (double) columnIndex;
136: }
137:
138: /** @deprecated */
139: public BigDecimal getBigDecimal(int columnIndex, int scale)
140: throws SQLException {
141: checkOpen();
142: return new BigDecimal((double) columnIndex);
143: }
144:
145: public byte[] getBytes(int columnIndex) throws SQLException {
146: checkOpen();
147: return new byte[] { (byte) columnIndex };
148: }
149:
150: public java.sql.Date getDate(int columnIndex) throws SQLException {
151: checkOpen();
152: return null;
153: }
154:
155: public java.sql.Time getTime(int columnIndex) throws SQLException {
156: checkOpen();
157: return null;
158: }
159:
160: public java.sql.Timestamp getTimestamp(int columnIndex)
161: throws SQLException {
162: checkOpen();
163: return null;
164: }
165:
166: public java.io.InputStream getAsciiStream(int columnIndex)
167: throws SQLException {
168: checkOpen();
169: return null;
170: }
171:
172: /** @deprecated */
173: public java.io.InputStream getUnicodeStream(int columnIndex)
174: throws SQLException {
175: checkOpen();
176: return null;
177: }
178:
179: public java.io.InputStream getBinaryStream(int columnIndex)
180: throws SQLException {
181: checkOpen();
182: return null;
183: }
184:
185: public String getString(String columnName) throws SQLException {
186: checkOpen();
187: return columnName;
188: }
189:
190: public boolean getBoolean(String columnName) throws SQLException {
191: checkOpen();
192: return true;
193: }
194:
195: public byte getByte(String columnName) throws SQLException {
196: checkOpen();
197: return (byte) (columnName.hashCode());
198: }
199:
200: public short getShort(String columnName) throws SQLException {
201: checkOpen();
202: return (short) (columnName.hashCode());
203: }
204:
205: public int getInt(String columnName) throws SQLException {
206: checkOpen();
207: return (columnName.hashCode());
208: }
209:
210: public long getLong(String columnName) throws SQLException {
211: checkOpen();
212: return (long) (columnName.hashCode());
213: }
214:
215: public float getFloat(String columnName) throws SQLException {
216: checkOpen();
217: return (float) (columnName.hashCode());
218: }
219:
220: public double getDouble(String columnName) throws SQLException {
221: checkOpen();
222: return (double) (columnName.hashCode());
223: }
224:
225: /** @deprecated */
226: public BigDecimal getBigDecimal(String columnName, int scale)
227: throws SQLException {
228: checkOpen();
229: return new BigDecimal((double) columnName.hashCode());
230: }
231:
232: public byte[] getBytes(String columnName) throws SQLException {
233: checkOpen();
234: return columnName.getBytes();
235: }
236:
237: public java.sql.Date getDate(String columnName) throws SQLException {
238: checkOpen();
239: return null;
240: }
241:
242: public java.sql.Time getTime(String columnName) throws SQLException {
243: checkOpen();
244: return null;
245: }
246:
247: public java.sql.Timestamp getTimestamp(String columnName)
248: throws SQLException {
249: checkOpen();
250: return null;
251: }
252:
253: public java.io.InputStream getAsciiStream(String columnName)
254: throws SQLException {
255: checkOpen();
256: return null;
257: }
258:
259: /** @deprecated */
260: public java.io.InputStream getUnicodeStream(String columnName)
261: throws SQLException {
262: checkOpen();
263: return null;
264: }
265:
266: public java.io.InputStream getBinaryStream(String columnName)
267: throws SQLException {
268: checkOpen();
269: return null;
270: }
271:
272: public SQLWarning getWarnings() throws SQLException {
273: checkOpen();
274: return null;
275: }
276:
277: public void clearWarnings() throws SQLException {
278: checkOpen();
279: }
280:
281: public String getCursorName() throws SQLException {
282: checkOpen();
283: return null;
284: }
285:
286: public ResultSetMetaData getMetaData() throws SQLException {
287: checkOpen();
288: return null;
289: }
290:
291: public Object getObject(int columnIndex) throws SQLException {
292: checkOpen();
293: if (_data != null) {
294: return _data[_currentRow][columnIndex - 1];
295: }
296: return new Object();
297: }
298:
299: public Object getObject(String columnName) throws SQLException {
300: checkOpen();
301: return columnName;
302: }
303:
304: public int findColumn(String columnName) throws SQLException {
305: checkOpen();
306: return 1;
307: }
308:
309: public java.io.Reader getCharacterStream(int columnIndex)
310: throws SQLException {
311: checkOpen();
312: return null;
313: }
314:
315: public java.io.Reader getCharacterStream(String columnName)
316: throws SQLException {
317: checkOpen();
318: return null;
319: }
320:
321: public BigDecimal getBigDecimal(int columnIndex)
322: throws SQLException {
323: checkOpen();
324: return new BigDecimal((double) columnIndex);
325: }
326:
327: public BigDecimal getBigDecimal(String columnName)
328: throws SQLException {
329: checkOpen();
330: return new BigDecimal((double) columnName.hashCode());
331: }
332:
333: public boolean isBeforeFirst() throws SQLException {
334: checkOpen();
335: return _rowsLeft == 2;
336: }
337:
338: public boolean isAfterLast() throws SQLException {
339: checkOpen();
340: return _rowsLeft < 0;
341: }
342:
343: public boolean isFirst() throws SQLException {
344: checkOpen();
345: return _rowsLeft == 1;
346: }
347:
348: public boolean isLast() throws SQLException {
349: checkOpen();
350: return _rowsLeft == 0;
351: }
352:
353: public void beforeFirst() throws SQLException {
354: checkOpen();
355: }
356:
357: public void afterLast() throws SQLException {
358: checkOpen();
359: }
360:
361: public boolean first() throws SQLException {
362: checkOpen();
363: return false;
364: }
365:
366: public boolean last() throws SQLException {
367: checkOpen();
368: return false;
369: }
370:
371: public int getRow() throws SQLException {
372: checkOpen();
373: return 3 - _rowsLeft;
374: }
375:
376: public boolean absolute(int row) throws SQLException {
377: checkOpen();
378: return false;
379: }
380:
381: public boolean relative(int rows) throws SQLException {
382: checkOpen();
383: return false;
384: }
385:
386: public boolean previous() throws SQLException {
387: checkOpen();
388: return false;
389: }
390:
391: public void setFetchDirection(int direction) throws SQLException {
392: checkOpen();
393: }
394:
395: public int getFetchDirection() throws SQLException {
396: checkOpen();
397: return 1;
398: }
399:
400: public void setFetchSize(int rows) throws SQLException {
401: checkOpen();
402: }
403:
404: public int getFetchSize() throws SQLException {
405: checkOpen();
406: return 2;
407: }
408:
409: public int getType() throws SQLException {
410: return this ._type;
411: }
412:
413: public int getConcurrency() throws SQLException {
414: return this ._concurrency;
415: }
416:
417: public boolean rowUpdated() throws SQLException {
418: checkOpen();
419: return false;
420: }
421:
422: public boolean rowInserted() throws SQLException {
423: checkOpen();
424: return false;
425: }
426:
427: public boolean rowDeleted() throws SQLException {
428: checkOpen();
429: return false;
430: }
431:
432: public void updateNull(int columnIndex) throws SQLException {
433: checkOpen();
434: }
435:
436: public void updateBoolean(int columnIndex, boolean x)
437: throws SQLException {
438: checkOpen();
439: }
440:
441: public void updateByte(int columnIndex, byte x) throws SQLException {
442: checkOpen();
443: }
444:
445: public void updateShort(int columnIndex, short x)
446: throws SQLException {
447: checkOpen();
448: }
449:
450: public void updateInt(int columnIndex, int x) throws SQLException {
451: checkOpen();
452: }
453:
454: public void updateLong(int columnIndex, long x) throws SQLException {
455: checkOpen();
456: }
457:
458: public void updateFloat(int columnIndex, float x)
459: throws SQLException {
460: checkOpen();
461: }
462:
463: public void updateDouble(int columnIndex, double x)
464: throws SQLException {
465: checkOpen();
466: }
467:
468: public void updateBigDecimal(int columnIndex, BigDecimal x)
469: throws SQLException {
470: checkOpen();
471: }
472:
473: public void updateString(int columnIndex, String x)
474: throws SQLException {
475: checkOpen();
476: }
477:
478: public void updateBytes(int columnIndex, byte x[])
479: throws SQLException {
480: checkOpen();
481: }
482:
483: public void updateDate(int columnIndex, java.sql.Date x)
484: throws SQLException {
485: checkOpen();
486: }
487:
488: public void updateTime(int columnIndex, java.sql.Time x)
489: throws SQLException {
490: checkOpen();
491: }
492:
493: public void updateTimestamp(int columnIndex, java.sql.Timestamp x)
494: throws SQLException {
495: checkOpen();
496: }
497:
498: public void updateAsciiStream(int columnIndex,
499: java.io.InputStream x, int length) throws SQLException {
500: checkOpen();
501: }
502:
503: public void updateBinaryStream(int columnIndex,
504: java.io.InputStream x, int length) throws SQLException {
505: checkOpen();
506: }
507:
508: public void updateCharacterStream(int columnIndex,
509: java.io.Reader x, int length) throws SQLException {
510: checkOpen();
511: }
512:
513: public void updateObject(int columnIndex, Object x, int scale)
514: throws SQLException {
515: checkOpen();
516: }
517:
518: public void updateObject(int columnIndex, Object x)
519: throws SQLException {
520: checkOpen();
521: }
522:
523: public void updateNull(String columnName) throws SQLException {
524: checkOpen();
525: }
526:
527: public void updateBoolean(String columnName, boolean x)
528: throws SQLException {
529: checkOpen();
530: }
531:
532: public void updateByte(String columnName, byte x)
533: throws SQLException {
534: checkOpen();
535: }
536:
537: public void updateShort(String columnName, short x)
538: throws SQLException {
539: checkOpen();
540: }
541:
542: public void updateInt(String columnName, int x) throws SQLException {
543: checkOpen();
544: }
545:
546: public void updateLong(String columnName, long x)
547: throws SQLException {
548: checkOpen();
549: }
550:
551: public void updateFloat(String columnName, float x)
552: throws SQLException {
553: checkOpen();
554: }
555:
556: public void updateDouble(String columnName, double x)
557: throws SQLException {
558: checkOpen();
559: }
560:
561: public void updateBigDecimal(String columnName, BigDecimal x)
562: throws SQLException {
563: checkOpen();
564: }
565:
566: public void updateString(String columnName, String x)
567: throws SQLException {
568: checkOpen();
569: }
570:
571: public void updateBytes(String columnName, byte x[])
572: throws SQLException {
573: checkOpen();
574: }
575:
576: public void updateDate(String columnName, java.sql.Date x)
577: throws SQLException {
578: checkOpen();
579: }
580:
581: public void updateTime(String columnName, java.sql.Time x)
582: throws SQLException {
583: checkOpen();
584: }
585:
586: public void updateTimestamp(String columnName, java.sql.Timestamp x)
587: throws SQLException {
588: checkOpen();
589: }
590:
591: public void updateAsciiStream(String columnName,
592: java.io.InputStream x, int length) throws SQLException {
593: checkOpen();
594: }
595:
596: public void updateBinaryStream(String columnName,
597: java.io.InputStream x, int length) throws SQLException {
598: checkOpen();
599: }
600:
601: public void updateCharacterStream(String columnName,
602: java.io.Reader reader, int length) throws SQLException {
603: checkOpen();
604: }
605:
606: public void updateObject(String columnName, Object x, int scale)
607: throws SQLException {
608: checkOpen();
609: }
610:
611: public void updateObject(String columnName, Object x)
612: throws SQLException {
613: checkOpen();
614: }
615:
616: public void insertRow() throws SQLException {
617: checkOpen();
618: }
619:
620: public void updateRow() throws SQLException {
621: checkOpen();
622: }
623:
624: public void deleteRow() throws SQLException {
625: checkOpen();
626: }
627:
628: public void refreshRow() throws SQLException {
629: checkOpen();
630: }
631:
632: public void cancelRowUpdates() throws SQLException {
633: checkOpen();
634: }
635:
636: public void moveToInsertRow() throws SQLException {
637: checkOpen();
638: }
639:
640: public void moveToCurrentRow() throws SQLException {
641: checkOpen();
642: }
643:
644: public Statement getStatement() throws SQLException {
645: checkOpen();
646: return _statement;
647: }
648:
649: public Object getObject(int i, java.util.Map map)
650: throws SQLException {
651: checkOpen();
652: return new Object();
653: }
654:
655: public Ref getRef(int i) throws SQLException {
656: checkOpen();
657: return null;
658: }
659:
660: public Blob getBlob(int i) throws SQLException {
661: checkOpen();
662: return null;
663: }
664:
665: public Clob getClob(int i) throws SQLException {
666: checkOpen();
667: return null;
668: }
669:
670: public Array getArray(int i) throws SQLException {
671: checkOpen();
672: return null;
673: }
674:
675: public Object getObject(String colName, java.util.Map map)
676: throws SQLException {
677: checkOpen();
678: return colName;
679: }
680:
681: public Ref getRef(String colName) throws SQLException {
682: checkOpen();
683: return null;
684: }
685:
686: public Blob getBlob(String colName) throws SQLException {
687: checkOpen();
688: return null;
689: }
690:
691: public Clob getClob(String colName) throws SQLException {
692: checkOpen();
693: return null;
694: }
695:
696: public Array getArray(String colName) throws SQLException {
697: checkOpen();
698: return null;
699: }
700:
701: public java.sql.Date getDate(int columnIndex, Calendar cal)
702: throws SQLException {
703: checkOpen();
704: return null;
705: }
706:
707: public java.sql.Date getDate(String columnName, Calendar cal)
708: throws SQLException {
709: checkOpen();
710: return null;
711: }
712:
713: public java.sql.Time getTime(int columnIndex, Calendar cal)
714: throws SQLException {
715: checkOpen();
716: return null;
717: }
718:
719: public java.sql.Time getTime(String columnName, Calendar cal)
720: throws SQLException {
721: checkOpen();
722: return null;
723: }
724:
725: public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal)
726: throws SQLException {
727: checkOpen();
728: return null;
729: }
730:
731: public java.sql.Timestamp getTimestamp(String columnName,
732: Calendar cal) throws SQLException {
733: checkOpen();
734: return null;
735: }
736:
737: protected void checkOpen() throws SQLException {
738: if (!_open) {
739: throw new SQLException("ResultSet is closed.");
740: }
741: }
742:
743: // ------------------- JDBC 3.0 -----------------------------------------
744: // Will be commented by the build process on a JDBC 2.0 system
745:
746: /* JDBC_3_ANT_KEY_BEGIN */
747:
748: public java.net.URL getURL(int columnIndex) throws SQLException {
749: throw new SQLException("Not implemented.");
750: }
751:
752: public java.net.URL getURL(String columnName) throws SQLException {
753: throw new SQLException("Not implemented.");
754: }
755:
756: public void updateRef(int columnIndex, java.sql.Ref x)
757: throws SQLException {
758: throw new SQLException("Not implemented.");
759: }
760:
761: public void updateRef(String columnName, java.sql.Ref x)
762: throws SQLException {
763: throw new SQLException("Not implemented.");
764: }
765:
766: public void updateBlob(int columnIndex, java.sql.Blob x)
767: throws SQLException {
768: throw new SQLException("Not implemented.");
769: }
770:
771: public void updateBlob(String columnName, java.sql.Blob x)
772: throws SQLException {
773: throw new SQLException("Not implemented.");
774: }
775:
776: public void updateClob(int columnIndex, java.sql.Clob x)
777: throws SQLException {
778: throw new SQLException("Not implemented.");
779: }
780:
781: public void updateClob(String columnName, java.sql.Clob x)
782: throws SQLException {
783: throw new SQLException("Not implemented.");
784: }
785:
786: public void updateArray(int columnIndex, java.sql.Array x)
787: throws SQLException {
788: throw new SQLException("Not implemented.");
789: }
790:
791: public void updateArray(String columnName, java.sql.Array x)
792: throws SQLException {
793: throw new SQLException("Not implemented.");
794: }
795:
796: /* JDBC_3_ANT_KEY_END */
797:
798: }
|