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