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:
029: package com.caucho.db.jdbc;
030:
031: import java.io.InputStream;
032: import java.io.Reader;
033: import java.sql.NClob;
034: import java.sql.ResultSetMetaData;
035: import java.sql.RowId;
036: import java.sql.SQLException;
037: import java.sql.SQLXML;
038: import java.sql.Statement;
039: import java.util.ArrayList;
040: import java.util.regex.Pattern;
041:
042: class DummyResultSet extends AbstractResultSet {
043: private static Pattern _csvRegexp;
044:
045: private ArrayList<DummyColumn> _dummyColumns = new ArrayList<DummyColumn>();
046: private ArrayList<DummyRow> _dummyRows = new ArrayList<DummyRow>();
047: private int i;
048:
049: static {
050: try {
051: _csvRegexp = Pattern.compile(":");
052: } catch (Exception e) {
053: }
054: }
055:
056: public void addColumn(String name, int type) {
057: _dummyColumns.add(new DummyColumn(name, type));
058: }
059:
060: public int getColumnCount() {
061: return _dummyColumns.size();
062: }
063:
064: public void startRow() {
065: DummyRow row = new DummyRow();
066:
067: _dummyRows.add(row);
068: }
069:
070: public DummyResultSet add(String data) {
071: DummyRow row = _dummyRows.get(_dummyRows.size() - 1);
072:
073: row.add(data);
074:
075: return this ;
076: }
077:
078: public DummyResultSet add(int data) {
079: DummyRow row = _dummyRows.get(_dummyRows.size() - 1);
080:
081: row.add(String.valueOf(data));
082:
083: return this ;
084: }
085:
086: public DummyResultSet add() {
087: DummyRow row = _dummyRows.get(_dummyRows.size() - 1);
088:
089: row.add("");
090:
091: return this ;
092: }
093:
094: public void addRow(String csv) {
095: startRow();
096: String[] values;
097: synchronized (_csvRegexp) {
098: values = _csvRegexp.split(csv);
099: }
100:
101: for (int i = 0; i < values.length; i++)
102: add(values[i]);
103: }
104:
105: protected InputStream getInputStream(int columnIndex) {
106: throw new UnsupportedOperationException();
107: }
108:
109: protected long getDateAsLong(int columnIndex) {
110: return 0;
111: }
112:
113: public int findColumn(String name) {
114: for (int i = 0; i < _dummyColumns.size(); i++) {
115: DummyColumn column = _dummyColumns.get(i);
116:
117: if (column.getColumnName().equals(name))
118: return i;
119: }
120:
121: return -1;
122: }
123:
124: public boolean wasNull() {
125: return false;
126: }
127:
128: public String getString(int column) {
129: DummyRow row = _dummyRows.get(i);
130:
131: return row.getString(column);
132: }
133:
134: public ResultSetMetaData getMetaData() {
135: return null;
136: }
137:
138: public Statement getStatement() {
139: return null;
140: }
141:
142: public boolean next() throws SQLException {
143: if (_dummyRows.size() <= i)
144: return false;
145:
146: i++;
147:
148: return true;
149: }
150:
151: static class DummyColumn {
152: String _name;
153: int _type;
154:
155: DummyColumn(String name, int type) {
156: _name = name;
157: _type = type;
158: }
159:
160: public String getColumnName() {
161: return _name;
162: }
163:
164: public int getColumnType() {
165: return _type;
166: }
167:
168: public String getColumnTypeName() {
169: return "VARCHAR";
170: }
171: }
172:
173: static class DummyRow {
174: private ArrayList<String> _values = new ArrayList<String>();
175:
176: DummyRow() {
177: }
178:
179: void add(String data) {
180: _values.add(data);
181: }
182:
183: protected String getString(int columnIndex) {
184: return _values.get(columnIndex);
185: }
186: }
187:
188: public RowId getRowId(int columnIndex) throws SQLException {
189: throw new UnsupportedOperationException("Not supported yet.");
190: }
191:
192: public RowId getRowId(String columnLabel) throws SQLException {
193: throw new UnsupportedOperationException("Not supported yet.");
194: }
195:
196: public void updateRowId(int columnIndex, RowId x)
197: throws SQLException {
198: throw new UnsupportedOperationException("Not supported yet.");
199: }
200:
201: public void updateRowId(String columnLabel, RowId x)
202: throws SQLException {
203: throw new UnsupportedOperationException("Not supported yet.");
204: }
205:
206: public int getHoldability() throws SQLException {
207: throw new UnsupportedOperationException("Not supported yet.");
208: }
209:
210: public boolean isClosed() throws SQLException {
211: throw new UnsupportedOperationException("Not supported yet.");
212: }
213:
214: public void updateNString(int columnIndex, String nString)
215: throws SQLException {
216: throw new UnsupportedOperationException("Not supported yet.");
217: }
218:
219: public void updateNString(String columnLabel, String nString)
220: throws SQLException {
221: throw new UnsupportedOperationException("Not supported yet.");
222: }
223:
224: public void updateNClob(int columnIndex, NClob nClob)
225: throws SQLException {
226: throw new UnsupportedOperationException("Not supported yet.");
227: }
228:
229: public void updateNClob(String columnLabel, NClob nClob)
230: throws SQLException {
231: throw new UnsupportedOperationException("Not supported yet.");
232: }
233:
234: public NClob getNClob(int columnIndex) throws SQLException {
235: throw new UnsupportedOperationException("Not supported yet.");
236: }
237:
238: public NClob getNClob(String columnLabel) throws SQLException {
239: throw new UnsupportedOperationException("Not supported yet.");
240: }
241:
242: public SQLXML getSQLXML(int columnIndex) throws SQLException {
243: throw new UnsupportedOperationException("Not supported yet.");
244: }
245:
246: public SQLXML getSQLXML(String columnLabel) throws SQLException {
247: throw new UnsupportedOperationException("Not supported yet.");
248: }
249:
250: public void updateSQLXML(int columnIndex, SQLXML xmlObject)
251: throws SQLException {
252: throw new UnsupportedOperationException("Not supported yet.");
253: }
254:
255: public void updateSQLXML(String columnLabel, SQLXML xmlObject)
256: throws SQLException {
257: throw new UnsupportedOperationException("Not supported yet.");
258: }
259:
260: public String getNString(int columnIndex) throws SQLException {
261: throw new UnsupportedOperationException("Not supported yet.");
262: }
263:
264: public String getNString(String columnLabel) throws SQLException {
265: throw new UnsupportedOperationException("Not supported yet.");
266: }
267:
268: public Reader getNCharacterStream(int columnIndex)
269: throws SQLException {
270: throw new UnsupportedOperationException("Not supported yet.");
271: }
272:
273: public Reader getNCharacterStream(String columnLabel)
274: throws SQLException {
275: throw new UnsupportedOperationException("Not supported yet.");
276: }
277:
278: public void updateNCharacterStream(int columnIndex, Reader x,
279: long length) throws SQLException {
280: throw new UnsupportedOperationException("Not supported yet.");
281: }
282:
283: public void updateNCharacterStream(String columnLabel,
284: Reader reader, long length) throws SQLException {
285: throw new UnsupportedOperationException("Not supported yet.");
286: }
287:
288: public void updateAsciiStream(int columnIndex, InputStream x,
289: long length) throws SQLException {
290: throw new UnsupportedOperationException("Not supported yet.");
291: }
292:
293: public void updateBinaryStream(int columnIndex, InputStream x,
294: long length) throws SQLException {
295: throw new UnsupportedOperationException("Not supported yet.");
296: }
297:
298: public void updateCharacterStream(int columnIndex, Reader x,
299: long length) throws SQLException {
300: throw new UnsupportedOperationException("Not supported yet.");
301: }
302:
303: public void updateAsciiStream(String columnLabel, InputStream x,
304: long length) throws SQLException {
305: throw new UnsupportedOperationException("Not supported yet.");
306: }
307:
308: public void updateBinaryStream(String columnLabel, InputStream x,
309: long length) throws SQLException {
310: throw new UnsupportedOperationException("Not supported yet.");
311: }
312:
313: public void updateCharacterStream(String columnLabel,
314: Reader reader, long length) throws SQLException {
315: throw new UnsupportedOperationException("Not supported yet.");
316: }
317:
318: public void updateBlob(int columnIndex, InputStream inputStream,
319: long length) throws SQLException {
320: throw new UnsupportedOperationException("Not supported yet.");
321: }
322:
323: public void updateBlob(String columnLabel, InputStream inputStream,
324: long length) throws SQLException {
325: throw new UnsupportedOperationException("Not supported yet.");
326: }
327:
328: public void updateClob(int columnIndex, Reader reader, long length)
329: throws SQLException {
330: throw new UnsupportedOperationException("Not supported yet.");
331: }
332:
333: public void updateClob(String columnLabel, Reader reader,
334: long length) throws SQLException {
335: throw new UnsupportedOperationException("Not supported yet.");
336: }
337:
338: public void updateNClob(int columnIndex, Reader reader, long length)
339: throws SQLException {
340: throw new UnsupportedOperationException("Not supported yet.");
341: }
342:
343: public void updateNClob(String columnLabel, Reader reader,
344: long length) throws SQLException {
345: throw new UnsupportedOperationException("Not supported yet.");
346: }
347:
348: public void updateNCharacterStream(int columnIndex, Reader x)
349: throws SQLException {
350: throw new UnsupportedOperationException("Not supported yet.");
351: }
352:
353: public void updateNCharacterStream(String columnLabel, Reader reader)
354: throws SQLException {
355: throw new UnsupportedOperationException("Not supported yet.");
356: }
357:
358: public void updateAsciiStream(int columnIndex, InputStream x)
359: throws SQLException {
360: throw new UnsupportedOperationException("Not supported yet.");
361: }
362:
363: public void updateBinaryStream(int columnIndex, InputStream x)
364: throws SQLException {
365: throw new UnsupportedOperationException("Not supported yet.");
366: }
367:
368: public void updateCharacterStream(int columnIndex, Reader x)
369: throws SQLException {
370: throw new UnsupportedOperationException("Not supported yet.");
371: }
372:
373: public void updateAsciiStream(String columnLabel, InputStream x)
374: throws SQLException {
375: throw new UnsupportedOperationException("Not supported yet.");
376: }
377:
378: public void updateBinaryStream(String columnLabel, InputStream x)
379: throws SQLException {
380: throw new UnsupportedOperationException("Not supported yet.");
381: }
382:
383: public void updateCharacterStream(String columnLabel, Reader reader)
384: throws SQLException {
385: throw new UnsupportedOperationException("Not supported yet.");
386: }
387:
388: public void updateBlob(int columnIndex, InputStream inputStream)
389: throws SQLException {
390: throw new UnsupportedOperationException("Not supported yet.");
391: }
392:
393: public void updateBlob(String columnLabel, InputStream inputStream)
394: throws SQLException {
395: throw new UnsupportedOperationException("Not supported yet.");
396: }
397:
398: public void updateClob(int columnIndex, Reader reader)
399: throws SQLException {
400: throw new UnsupportedOperationException("Not supported yet.");
401: }
402:
403: public void updateClob(String columnLabel, Reader reader)
404: throws SQLException {
405: throw new UnsupportedOperationException("Not supported yet.");
406: }
407:
408: public void updateNClob(int columnIndex, Reader reader)
409: throws SQLException {
410: throw new UnsupportedOperationException("Not supported yet.");
411: }
412:
413: public void updateNClob(String columnLabel, Reader reader)
414: throws SQLException {
415: throw new UnsupportedOperationException("Not supported yet.");
416: }
417:
418: public <T> T unwrap(Class<T> iface) throws SQLException {
419: throw new UnsupportedOperationException("Not supported yet.");
420: }
421:
422: public boolean isWrapperFor(Class<?> iface) throws SQLException {
423: throw new UnsupportedOperationException("Not supported yet.");
424: }
425: }
|