001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028: package com.caucho.db.jdbc;
029:
030: import com.caucho.db.sql.SelectResult;
031:
032: import java.io.InputStream;
033: import java.io.Reader;
034: import java.math.BigDecimal;
035: import java.sql.Blob;
036: import java.sql.Clob;
037: import java.sql.NClob;
038: import java.sql.RowId;
039: import java.sql.SQLException;
040: import java.sql.SQLXML;
041: import java.sql.Time;
042: import java.sql.Timestamp;
043:
044: /**
045: * The JDBC statement implementation.
046: */
047: public class ResultSetImpl extends AbstractResultSet {
048: private StatementImpl _stmt;
049: private SelectResult _rs;
050: private int _rowNumber;
051:
052: ResultSetImpl(StatementImpl stmt, SelectResult rs) {
053: _stmt = stmt;
054: _rs = rs;
055: }
056:
057: public int getRow() throws SQLException {
058: if (_rowNumber < 0)
059: throw new SQLException("can't call getRow() after close()");
060:
061: return _rowNumber;
062: }
063:
064: public boolean isBeforeFirst() throws SQLException {
065: return _rowNumber == 0;
066: }
067:
068: public boolean isFirst() throws SQLException {
069: return _rowNumber == 1;
070: }
071:
072: public java.sql.Statement getStatement() throws SQLException {
073: if (_rowNumber < 0)
074: throw new SQLException(
075: "can't call getStatement() after close()");
076:
077: return _stmt;
078: }
079:
080: public java.sql.ResultSetMetaData getMetaData() throws SQLException {
081: if (_rowNumber < 0)
082: throw new SQLException(
083: "can't call getMetaData() after close()");
084:
085: return new ResultSetMetaDataImpl(_rs);
086: }
087:
088: public boolean wasNull() throws SQLException {
089: return _rs.wasNull();
090: }
091:
092: /**
093: * Goes to the next row, returning true if it exists.
094: */
095: public boolean next() throws SQLException {
096: if (_rs == null)
097: return false;
098: else if (_rs.next()) {
099: _rowNumber++;
100:
101: return true;
102: } else {
103: close();
104:
105: return false;
106: }
107: }
108:
109: public int findColumn(String columnName) throws SQLException {
110: return _rs.findColumnIndex(columnName);
111: }
112:
113: /**
114: * Returns the boolean value for the column.
115: */
116: public boolean getBoolean(int columnIndex) throws SQLException {
117: String s = getString(columnIndex);
118:
119: return s != null && !s.equals("") && !s.equals("0")
120: && !s.equals("n");
121: }
122:
123: /**
124: * Returns the date value for the column.
125: */
126: public java.sql.Date getDate(int columnIndex) throws SQLException {
127: long date = _rs.getDate(columnIndex - 1);
128:
129: if (wasNull())
130: return null;
131: else
132: return new java.sql.Date(date);
133: }
134:
135: /**
136: * Returns the double value for the column.
137: */
138: public double getDouble(int columnIndex) throws SQLException {
139: return _rs.getDouble(columnIndex - 1);
140: }
141:
142: /**
143: * Returns the integer value for the column.
144: */
145: public int getInt(int columnIndex) throws SQLException {
146: return _rs.getInt(columnIndex - 1);
147: }
148:
149: /**
150: * Returns the long value for the column.
151: */
152: public long getLong(int columnIndex) throws SQLException {
153: return _rs.getLong(columnIndex - 1);
154: }
155:
156: /**
157: * Returns the string value for the column.
158: */
159: public String getString(int columnIndex) throws SQLException {
160: return _rs.getString(columnIndex - 1);
161: }
162:
163: /**
164: * Returns the time value for the column.
165: */
166: public Time getTime(int columnIndex) throws SQLException {
167: long date = _rs.getDate(columnIndex - 1);
168:
169: if (wasNull())
170: return null;
171: else
172: return new java.sql.Time(date);
173: }
174:
175: public Timestamp getTimestamp(int columnIndex) throws SQLException {
176: long date = _rs.getDate(columnIndex - 1);
177:
178: if (wasNull())
179: return null;
180: else
181: return new java.sql.Timestamp(date);
182: }
183:
184: /**
185: * Returns the big-decimal value for the column.
186: */
187: public BigDecimal getBigDecimal(int columnIndex)
188: throws SQLException {
189: return new BigDecimal(_rs.getString(columnIndex - 1));
190: }
191:
192: /**
193: * Returns the blob value for the column.
194: */
195: public Blob getBlob(int columnIndex) throws SQLException {
196: return _rs.getBlob(columnIndex - 1);
197: }
198:
199: /**
200: * Returns the clob value for the column.
201: */
202: public Clob getClob(int columnIndex) throws SQLException {
203: return _rs.getClob(columnIndex - 1);
204: }
205:
206: public void close() throws SQLException {
207: SelectResult result = _rs;
208: _rs = null;
209:
210: if (result != null)
211: result.close();
212: }
213:
214: public RowId getRowId(int columnIndex) throws SQLException {
215: throw new UnsupportedOperationException("Not supported yet.");
216: }
217:
218: public RowId getRowId(String columnLabel) throws SQLException {
219: throw new UnsupportedOperationException("Not supported yet.");
220: }
221:
222: public void updateRowId(int columnIndex, RowId x)
223: throws SQLException {
224: throw new UnsupportedOperationException("Not supported yet.");
225: }
226:
227: public void updateRowId(String columnLabel, RowId x)
228: throws SQLException {
229: throw new UnsupportedOperationException("Not supported yet.");
230: }
231:
232: public int getHoldability() throws SQLException {
233: throw new UnsupportedOperationException("Not supported yet.");
234: }
235:
236: public boolean isClosed() throws SQLException {
237: throw new UnsupportedOperationException("Not supported yet.");
238: }
239:
240: public void updateNString(int columnIndex, String nString)
241: throws SQLException {
242: throw new UnsupportedOperationException("Not supported yet.");
243: }
244:
245: public void updateNString(String columnLabel, String nString)
246: throws SQLException {
247: throw new UnsupportedOperationException("Not supported yet.");
248: }
249:
250: public void updateNClob(int columnIndex, NClob nClob)
251: throws SQLException {
252: throw new UnsupportedOperationException("Not supported yet.");
253: }
254:
255: public void updateNClob(String columnLabel, NClob nClob)
256: throws SQLException {
257: throw new UnsupportedOperationException("Not supported yet.");
258: }
259:
260: public NClob getNClob(int columnIndex) throws SQLException {
261: throw new UnsupportedOperationException("Not supported yet.");
262: }
263:
264: public NClob getNClob(String columnLabel) throws SQLException {
265: throw new UnsupportedOperationException("Not supported yet.");
266: }
267:
268: public SQLXML getSQLXML(int columnIndex) throws SQLException {
269: throw new UnsupportedOperationException("Not supported yet.");
270: }
271:
272: public SQLXML getSQLXML(String columnLabel) throws SQLException {
273: throw new UnsupportedOperationException("Not supported yet.");
274: }
275:
276: public void updateSQLXML(int columnIndex, SQLXML xmlObject)
277: throws SQLException {
278: throw new UnsupportedOperationException("Not supported yet.");
279: }
280:
281: public void updateSQLXML(String columnLabel, SQLXML xmlObject)
282: throws SQLException {
283: throw new UnsupportedOperationException("Not supported yet.");
284: }
285:
286: public String getNString(int columnIndex) throws SQLException {
287: throw new UnsupportedOperationException("Not supported yet.");
288: }
289:
290: public String getNString(String columnLabel) throws SQLException {
291: throw new UnsupportedOperationException("Not supported yet.");
292: }
293:
294: public Reader getNCharacterStream(int columnIndex)
295: throws SQLException {
296: throw new UnsupportedOperationException("Not supported yet.");
297: }
298:
299: public Reader getNCharacterStream(String columnLabel)
300: throws SQLException {
301: throw new UnsupportedOperationException("Not supported yet.");
302: }
303:
304: public void updateNCharacterStream(int columnIndex, Reader x,
305: long length) throws SQLException {
306: throw new UnsupportedOperationException("Not supported yet.");
307: }
308:
309: public void updateNCharacterStream(String columnLabel,
310: Reader reader, long length) throws SQLException {
311: throw new UnsupportedOperationException("Not supported yet.");
312: }
313:
314: public void updateAsciiStream(int columnIndex, InputStream x,
315: long length) throws SQLException {
316: throw new UnsupportedOperationException("Not supported yet.");
317: }
318:
319: public void updateBinaryStream(int columnIndex, InputStream x,
320: long length) throws SQLException {
321: throw new UnsupportedOperationException("Not supported yet.");
322: }
323:
324: public void updateCharacterStream(int columnIndex, Reader x,
325: long length) throws SQLException {
326: throw new UnsupportedOperationException("Not supported yet.");
327: }
328:
329: public void updateAsciiStream(String columnLabel, InputStream x,
330: long length) throws SQLException {
331: throw new UnsupportedOperationException("Not supported yet.");
332: }
333:
334: public void updateBinaryStream(String columnLabel, InputStream x,
335: long length) throws SQLException {
336: throw new UnsupportedOperationException("Not supported yet.");
337: }
338:
339: public void updateCharacterStream(String columnLabel,
340: Reader reader, long length) throws SQLException {
341: throw new UnsupportedOperationException("Not supported yet.");
342: }
343:
344: public void updateBlob(int columnIndex, InputStream inputStream,
345: long length) throws SQLException {
346: throw new UnsupportedOperationException("Not supported yet.");
347: }
348:
349: public void updateBlob(String columnLabel, InputStream inputStream,
350: long length) throws SQLException {
351: throw new UnsupportedOperationException("Not supported yet.");
352: }
353:
354: public void updateClob(int columnIndex, Reader reader, long length)
355: throws SQLException {
356: throw new UnsupportedOperationException("Not supported yet.");
357: }
358:
359: public void updateClob(String columnLabel, Reader reader,
360: long length) throws SQLException {
361: throw new UnsupportedOperationException("Not supported yet.");
362: }
363:
364: public void updateNClob(int columnIndex, Reader reader, long length)
365: throws SQLException {
366: throw new UnsupportedOperationException("Not supported yet.");
367: }
368:
369: public void updateNClob(String columnLabel, Reader reader,
370: long length) throws SQLException {
371: throw new UnsupportedOperationException("Not supported yet.");
372: }
373:
374: public void updateNCharacterStream(int columnIndex, Reader x)
375: throws SQLException {
376: throw new UnsupportedOperationException("Not supported yet.");
377: }
378:
379: public void updateNCharacterStream(String columnLabel, Reader reader)
380: throws SQLException {
381: throw new UnsupportedOperationException("Not supported yet.");
382: }
383:
384: public void updateAsciiStream(int columnIndex, InputStream x)
385: throws SQLException {
386: throw new UnsupportedOperationException("Not supported yet.");
387: }
388:
389: public void updateBinaryStream(int columnIndex, InputStream x)
390: throws SQLException {
391: throw new UnsupportedOperationException("Not supported yet.");
392: }
393:
394: public void updateCharacterStream(int columnIndex, Reader x)
395: throws SQLException {
396: throw new UnsupportedOperationException("Not supported yet.");
397: }
398:
399: public void updateAsciiStream(String columnLabel, InputStream x)
400: throws SQLException {
401: throw new UnsupportedOperationException("Not supported yet.");
402: }
403:
404: public void updateBinaryStream(String columnLabel, InputStream x)
405: throws SQLException {
406: throw new UnsupportedOperationException("Not supported yet.");
407: }
408:
409: public void updateCharacterStream(String columnLabel, Reader reader)
410: throws SQLException {
411: throw new UnsupportedOperationException("Not supported yet.");
412: }
413:
414: public void updateBlob(int columnIndex, InputStream inputStream)
415: throws SQLException {
416: throw new UnsupportedOperationException("Not supported yet.");
417: }
418:
419: public void updateBlob(String columnLabel, InputStream inputStream)
420: throws SQLException {
421: throw new UnsupportedOperationException("Not supported yet.");
422: }
423:
424: public void updateClob(int columnIndex, Reader reader)
425: throws SQLException {
426: throw new UnsupportedOperationException("Not supported yet.");
427: }
428:
429: public void updateClob(String columnLabel, Reader reader)
430: throws SQLException {
431: throw new UnsupportedOperationException("Not supported yet.");
432: }
433:
434: public void updateNClob(int columnIndex, Reader reader)
435: throws SQLException {
436: throw new UnsupportedOperationException("Not supported yet.");
437: }
438:
439: public void updateNClob(String columnLabel, Reader reader)
440: throws SQLException {
441: throw new UnsupportedOperationException("Not supported yet.");
442: }
443:
444: public <T> T unwrap(Class<T> iface) throws SQLException {
445: throw new UnsupportedOperationException("Not supported yet.");
446: }
447:
448: public boolean isWrapperFor(Class<?> iface) throws SQLException {
449: throw new UnsupportedOperationException("Not supported yet.");
450: }
451: }
|