001: package org.geotools.data.sql;
002:
003: import java.math.BigDecimal;
004: import java.sql.Array;
005: import java.sql.Blob;
006: import java.sql.Clob;
007: import java.sql.DatabaseMetaData;
008: import java.sql.Ref;
009: import java.sql.ResultSet;
010: import java.sql.ResultSetMetaData;
011: import java.sql.SQLException;
012: import java.sql.SQLWarning;
013: import java.sql.Statement;
014: import java.util.Calendar;
015: import java.util.Iterator;
016: import java.util.LinkedList;
017: import java.util.List;
018:
019: public class RsMd2DbMdResultSet implements ResultSet {
020: private static final int TABLE_CAT = 1; //String => table catalog (may be null)
021: private static final int TABLE_SCHEM = 2; // String => table schema (may be null)
022: private static final int TABLE_NAME = 3; // String => table name
023: private static final int COLUMN_NAME = 4; // String => column name
024: private static final int DATA_TYPE = 5; // int => SQL type from java.sql.Types
025: private static final int TYPE_NAME = 6; // String => Data source dependent type name, for a UDT the type name is fully qualified
026: private static final int COLUMN_SIZE = 7; // int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
027: private static final int BUFFER_LENGTH = 8; // is not used.
028: private static final int DECIMAL_DIGITS = 9; // int => the number of fractional digits
029: private static final int NUM_PREC_RADIX = 10; // int => Radix (typically either 10 or 2)
030: private static final int NULLABLE = 11; // int => is NULL allowed.
031: //columnNoNulls - might not allow NULL values
032: //columnNullable - definitely allows NULL values
033: //columnNullableUnknown - nullability unknown
034: private static final int REMARKS = 12; //String => comment describing column (may be null)
035: private static final int COLUMN_DEF = 13; //String => default value (may be null)
036: private static final int SQL_DATA_TYPE = 14; //int => unused
037: private static final int SQL_DATETIME_SUB = 15; //int => unused
038: private static final int CHAR_OCTET_LENGTH = 16; //int => for char types the maximum number of bytes in the column
039: private static final int ORDINAL_POSITION = 17; //int => index of column in table (starting at 1)
040: private static final int IS_NULLABLE = 18; //String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
041: private static final int SCOPE_CATLOG = 19; //String => catalog of table that is the scope of a reference attribute (null if DATA_TYPE isn't REF)
042: private static final int SCOPE_SCHEMA = 20; //String => schema of table that is the scope of a reference attribute (null if the DATA_TYPE isn't REF)
043: private static final int SCOPE_TABLE = 21; //String => table name that this the scope of a reference attribure (null if the DATA_TYPE isn't REF)
044: private static final int SOURCE_DATA_TYPE = 22; //short => source type of a distinct type or user-generated Ref type, SQL type from java.sql.Types (null if DATA_TYPE isn't DISTINCT or user-generated REF)
045:
046: private List contents;
047: private Object[] currentRow;
048: private Iterator iterator;
049:
050: public RsMd2DbMdResultSet(ResultSetMetaData rsmd)
051: throws SQLException {
052: contents = new LinkedList();
053: final int colCount = rsmd.getColumnCount();
054: for (int i = 1; i <= colCount; i++) {
055: Object[] row = new Object[23]; //index 0 not used
056: row[TABLE_CAT] = rsmd.getCatalogName(i);
057: row[TABLE_SCHEM] = rsmd.getSchemaName(i);
058: row[TABLE_NAME] = rsmd.getTableName(i);
059: row[COLUMN_NAME] = rsmd.getColumnName(i);
060: row[DATA_TYPE] = new Integer(rsmd.getColumnType(i));
061: row[TYPE_NAME] = rsmd.getColumnTypeName(i);
062: row[COLUMN_SIZE] = new Integer(rsmd.getColumnDisplaySize(i));
063: row[DECIMAL_DIGITS] = new Integer(rsmd.getScale(i));
064: row[NULLABLE] = new Integer(rsmd.isNullable(i));
065: row[REMARKS] = rsmd.getColumnLabel(i);
066:
067: contents.add(row);
068: }
069: this .iterator = contents.iterator();
070: }
071:
072: public String getString(int columnIndex) throws SQLException {
073: Object val = this .currentRow[columnIndex];
074: String retVal = val == null ? null : String.valueOf(val);
075: return retVal;
076: }
077:
078: public int getInt(int columnIndex) throws SQLException {
079: Object val = this .currentRow[columnIndex];
080: int intVal = ((Number) val).intValue();
081: return intVal;
082: }
083:
084: public boolean next() throws SQLException {
085: boolean hasNext = this .iterator.hasNext();
086: if (hasNext) {
087: this .currentRow = (Object[]) this .iterator.next();
088: }
089: return hasNext;
090: }
091:
092: /**
093: * Releases this <code>ResultSet</code> object's database and
094: * JDBC resources immediately instead of waiting for
095: * this to happen when it is automatically closed.
096: *
097: * <P><B>Note:</B> A <code>ResultSet</code> object
098: * is automatically closed by the
099: * <code>Statement</code> object that generated it when
100: * that <code>Statement</code> object is closed,
101: * re-executed, or is used to retrieve the next result from a
102: * sequence of multiple results. A <code>ResultSet</code> object
103: * is also automatically closed when it is garbage collected.
104: *
105: * @exception SQLException if a database access error occurs
106: */
107: public void close() throws SQLException {
108: this .currentRow = null;
109: this .iterator = null;
110: this .contents = null;
111: }
112:
113: ////////////////////////////////////////////////////////////////
114: // the rest of methods throw unsupported operation exception //
115: ////////////////////////////////////////////////////////////////
116: public boolean wasNull() throws SQLException {
117: throw new UnsupportedOperationException();
118: }
119:
120: public boolean getBoolean(int columnIndex) throws SQLException {
121: throw new UnsupportedOperationException();
122: }
123:
124: public byte getByte(int columnIndex) throws SQLException {
125: throw new UnsupportedOperationException();
126: }
127:
128: public short getShort(int columnIndex) throws SQLException {
129: throw new UnsupportedOperationException();
130: }
131:
132: public long getLong(int columnIndex) throws SQLException {
133: throw new UnsupportedOperationException();
134: }
135:
136: public float getFloat(int columnIndex) throws SQLException {
137: throw new UnsupportedOperationException();
138: }
139:
140: public double getDouble(int columnIndex) throws SQLException {
141: throw new UnsupportedOperationException();
142: }
143:
144: public BigDecimal getBigDecimal(int columnIndex, int scale)
145: throws SQLException {
146: throw new UnsupportedOperationException();
147: }
148:
149: public byte[] getBytes(int columnIndex) throws SQLException {
150: throw new UnsupportedOperationException();
151: }
152:
153: public java.sql.Date getDate(int columnIndex) throws SQLException {
154: throw new UnsupportedOperationException();
155: }
156:
157: public java.sql.Time getTime(int columnIndex) throws SQLException {
158: throw new UnsupportedOperationException();
159: }
160:
161: public java.sql.Timestamp getTimestamp(int columnIndex)
162: throws SQLException {
163: throw new UnsupportedOperationException();
164: }
165:
166: public java.io.InputStream getAsciiStream(int columnIndex)
167: throws SQLException {
168: throw new UnsupportedOperationException();
169: }
170:
171: public java.io.InputStream getUnicodeStream(int columnIndex)
172: throws SQLException {
173: throw new UnsupportedOperationException();
174: }
175:
176: public java.io.InputStream getBinaryStream(int columnIndex)
177: throws SQLException {
178: throw new UnsupportedOperationException();
179: }
180:
181: public String getString(String columnName) throws SQLException {
182: throw new UnsupportedOperationException();
183: }
184:
185: public boolean getBoolean(String columnName) throws SQLException {
186: throw new UnsupportedOperationException();
187: }
188:
189: public byte getByte(String columnName) throws SQLException {
190: throw new UnsupportedOperationException();
191: }
192:
193: public short getShort(String columnName) throws SQLException {
194: throw new UnsupportedOperationException();
195: }
196:
197: public int getInt(String columnName) throws SQLException {
198: throw new UnsupportedOperationException();
199: }
200:
201: public long getLong(String columnName) throws SQLException {
202: throw new UnsupportedOperationException();
203: }
204:
205: public float getFloat(String columnName) throws SQLException {
206: throw new UnsupportedOperationException();
207: }
208:
209: public double getDouble(String columnName) throws SQLException {
210: throw new UnsupportedOperationException();
211: }
212:
213: public BigDecimal getBigDecimal(String columnName, int scale)
214: throws SQLException {
215: throw new UnsupportedOperationException();
216: }
217:
218: public byte[] getBytes(String columnName) throws SQLException {
219: throw new UnsupportedOperationException();
220: }
221:
222: public java.sql.Date getDate(String columnName) throws SQLException {
223: throw new UnsupportedOperationException();
224: }
225:
226: public java.sql.Time getTime(String columnName) throws SQLException {
227: throw new UnsupportedOperationException();
228: }
229:
230: public java.sql.Timestamp getTimestamp(String columnName)
231: throws SQLException {
232: throw new UnsupportedOperationException();
233: }
234:
235: public java.io.InputStream getAsciiStream(String columnName)
236: throws SQLException {
237: throw new UnsupportedOperationException();
238: }
239:
240: public java.io.InputStream getUnicodeStream(String columnName)
241: throws SQLException {
242: throw new UnsupportedOperationException();
243: }
244:
245: public java.io.InputStream getBinaryStream(String columnName)
246: throws SQLException {
247: throw new UnsupportedOperationException();
248: }
249:
250: public SQLWarning getWarnings() throws SQLException {
251: throw new UnsupportedOperationException();
252: }
253:
254: public void clearWarnings() throws SQLException {
255: throw new UnsupportedOperationException();
256: }
257:
258: public String getCursorName() throws SQLException {
259: throw new UnsupportedOperationException();
260: }
261:
262: public ResultSetMetaData getMetaData() throws SQLException {
263: throw new UnsupportedOperationException();
264: }
265:
266: public Object getObject(int columnIndex) throws SQLException {
267: throw new UnsupportedOperationException();
268: }
269:
270: public Object getObject(String columnName) throws SQLException {
271: throw new UnsupportedOperationException();
272: }
273:
274: public int findColumn(String columnName) throws SQLException {
275: throw new UnsupportedOperationException();
276: }
277:
278: public java.io.Reader getCharacterStream(int columnIndex)
279: throws SQLException {
280: throw new UnsupportedOperationException();
281: }
282:
283: public java.io.Reader getCharacterStream(String columnName)
284: throws SQLException {
285: throw new UnsupportedOperationException();
286: }
287:
288: public BigDecimal getBigDecimal(int columnIndex)
289: throws SQLException {
290: throw new UnsupportedOperationException();
291: }
292:
293: public BigDecimal getBigDecimal(String columnName)
294: throws SQLException {
295: throw new UnsupportedOperationException();
296: }
297:
298: public boolean isBeforeFirst() throws SQLException {
299: throw new UnsupportedOperationException();
300: }
301:
302: public boolean isAfterLast() throws SQLException {
303: throw new UnsupportedOperationException();
304: }
305:
306: public boolean isFirst() throws SQLException {
307: throw new UnsupportedOperationException();
308: }
309:
310: public boolean isLast() throws SQLException {
311: throw new UnsupportedOperationException();
312: }
313:
314: public void beforeFirst() throws SQLException {
315: throw new UnsupportedOperationException();
316: }
317:
318: public void afterLast() throws SQLException {
319: throw new UnsupportedOperationException();
320: }
321:
322: public boolean first() throws SQLException {
323: throw new UnsupportedOperationException();
324: }
325:
326: public boolean last() throws SQLException {
327: throw new UnsupportedOperationException();
328: }
329:
330: public int getRow() throws SQLException {
331: throw new UnsupportedOperationException();
332: }
333:
334: public boolean absolute(int row) throws SQLException {
335: throw new UnsupportedOperationException();
336: }
337:
338: public boolean relative(int rows) throws SQLException {
339: throw new UnsupportedOperationException();
340: }
341:
342: public boolean previous() throws SQLException {
343: throw new UnsupportedOperationException();
344: }
345:
346: public void setFetchDirection(int direction) throws SQLException {
347: throw new UnsupportedOperationException();
348: }
349:
350: public int getFetchDirection() throws SQLException {
351: throw new UnsupportedOperationException();
352: }
353:
354: public void setFetchSize(int rows) throws SQLException {
355: throw new UnsupportedOperationException();
356: }
357:
358: public int getFetchSize() throws SQLException {
359: throw new UnsupportedOperationException();
360: }
361:
362: public int getType() throws SQLException {
363: throw new UnsupportedOperationException();
364: }
365:
366: public int getConcurrency() throws SQLException {
367: throw new UnsupportedOperationException();
368: }
369:
370: public boolean rowUpdated() throws SQLException {
371: throw new UnsupportedOperationException();
372: }
373:
374: public boolean rowInserted() throws SQLException {
375: throw new UnsupportedOperationException();
376: }
377:
378: public boolean rowDeleted() throws SQLException {
379: throw new UnsupportedOperationException();
380: }
381:
382: public void updateNull(int columnIndex) throws SQLException {
383: throw new UnsupportedOperationException();
384: }
385:
386: public void updateBoolean(int columnIndex, boolean x)
387: throws SQLException {
388: throw new UnsupportedOperationException();
389: }
390:
391: public void updateByte(int columnIndex, byte x) throws SQLException {
392: throw new UnsupportedOperationException();
393: }
394:
395: public void updateShort(int columnIndex, short x)
396: throws SQLException {
397: throw new UnsupportedOperationException();
398: }
399:
400: public void updateInt(int columnIndex, int x) throws SQLException {
401: throw new UnsupportedOperationException();
402: }
403:
404: public void updateLong(int columnIndex, long x) throws SQLException {
405: throw new UnsupportedOperationException();
406: }
407:
408: public void updateFloat(int columnIndex, float x)
409: throws SQLException {
410: throw new UnsupportedOperationException();
411: }
412:
413: public void updateDouble(int columnIndex, double x)
414: throws SQLException {
415: throw new UnsupportedOperationException();
416: }
417:
418: public void updateBigDecimal(int columnIndex, BigDecimal x)
419: throws SQLException {
420: throw new UnsupportedOperationException();
421: }
422:
423: public void updateString(int columnIndex, String x)
424: throws SQLException {
425: throw new UnsupportedOperationException();
426: }
427:
428: public void updateBytes(int columnIndex, byte x[])
429: throws SQLException {
430: throw new UnsupportedOperationException();
431: }
432:
433: public void updateDate(int columnIndex, java.sql.Date x)
434: throws SQLException {
435: throw new UnsupportedOperationException();
436: }
437:
438: public void updateTime(int columnIndex, java.sql.Time x)
439: throws SQLException {
440: throw new UnsupportedOperationException();
441: }
442:
443: public void updateTimestamp(int columnIndex, java.sql.Timestamp x)
444: throws SQLException {
445: throw new UnsupportedOperationException();
446: }
447:
448: public void updateAsciiStream(int columnIndex,
449: java.io.InputStream x, int length) throws SQLException {
450: throw new UnsupportedOperationException();
451: }
452:
453: public void updateBinaryStream(int columnIndex,
454: java.io.InputStream x, int length) throws SQLException {
455: throw new UnsupportedOperationException();
456: }
457:
458: public void updateCharacterStream(int columnIndex,
459: java.io.Reader x, int length) throws SQLException {
460: throw new UnsupportedOperationException();
461: }
462:
463: public void updateObject(int columnIndex, Object x, int scale)
464: throws SQLException {
465: throw new UnsupportedOperationException();
466: }
467:
468: public void updateObject(int columnIndex, Object x)
469: throws SQLException {
470: throw new UnsupportedOperationException();
471: }
472:
473: public void updateNull(String columnName) throws SQLException {
474: throw new UnsupportedOperationException();
475: }
476:
477: public void updateBoolean(String columnName, boolean x)
478: throws SQLException {
479: throw new UnsupportedOperationException();
480: }
481:
482: public void updateByte(String columnName, byte x)
483: throws SQLException {
484: throw new UnsupportedOperationException();
485: }
486:
487: public void updateShort(String columnName, short x)
488: throws SQLException {
489: throw new UnsupportedOperationException();
490: }
491:
492: public void updateInt(String columnName, int x) throws SQLException {
493: throw new UnsupportedOperationException();
494: }
495:
496: public void updateLong(String columnName, long x)
497: throws SQLException {
498: throw new UnsupportedOperationException();
499: }
500:
501: public void updateFloat(String columnName, float x)
502: throws SQLException {
503: throw new UnsupportedOperationException();
504: }
505:
506: public void updateDouble(String columnName, double x)
507: throws SQLException {
508: throw new UnsupportedOperationException();
509: }
510:
511: public void updateBigDecimal(String columnName, BigDecimal x)
512: throws SQLException {
513: throw new UnsupportedOperationException();
514: }
515:
516: public void updateString(String columnName, String x)
517: throws SQLException {
518: throw new UnsupportedOperationException();
519: }
520:
521: public void updateBytes(String columnName, byte x[])
522: throws SQLException {
523: throw new UnsupportedOperationException();
524: }
525:
526: public void updateDate(String columnName, java.sql.Date x)
527: throws SQLException {
528: throw new UnsupportedOperationException();
529: }
530:
531: public void updateTime(String columnName, java.sql.Time x)
532: throws SQLException {
533: throw new UnsupportedOperationException();
534: }
535:
536: public void updateTimestamp(String columnName, java.sql.Timestamp x)
537: throws SQLException {
538: throw new UnsupportedOperationException();
539: }
540:
541: public void updateAsciiStream(String columnName,
542: java.io.InputStream x, int length) throws SQLException {
543: throw new UnsupportedOperationException();
544: }
545:
546: public void updateBinaryStream(String columnName,
547: java.io.InputStream x, int length) throws SQLException {
548: throw new UnsupportedOperationException();
549: }
550:
551: public void updateCharacterStream(String columnName,
552: java.io.Reader reader, int length) throws SQLException {
553: throw new UnsupportedOperationException();
554: }
555:
556: public void updateObject(String columnName, Object x, int scale)
557: throws SQLException {
558: throw new UnsupportedOperationException();
559: }
560:
561: public void updateObject(String columnName, Object x)
562: throws SQLException {
563: throw new UnsupportedOperationException();
564: }
565:
566: public void insertRow() throws SQLException {
567: throw new UnsupportedOperationException();
568: }
569:
570: public void updateRow() throws SQLException {
571: throw new UnsupportedOperationException();
572: }
573:
574: public void deleteRow() throws SQLException {
575: throw new UnsupportedOperationException();
576: }
577:
578: public void refreshRow() throws SQLException {
579: throw new UnsupportedOperationException();
580: }
581:
582: public void cancelRowUpdates() throws SQLException {
583: throw new UnsupportedOperationException();
584: }
585:
586: public void moveToInsertRow() throws SQLException {
587: throw new UnsupportedOperationException();
588: }
589:
590: public void moveToCurrentRow() throws SQLException {
591: throw new UnsupportedOperationException();
592: }
593:
594: public Statement getStatement() throws SQLException {
595: throw new UnsupportedOperationException();
596: }
597:
598: public Object getObject(int i, java.util.Map map)
599: throws SQLException {
600: throw new UnsupportedOperationException();
601: }
602:
603: public Ref getRef(int i) throws SQLException {
604: throw new UnsupportedOperationException();
605: }
606:
607: public Blob getBlob(int i) throws SQLException {
608: throw new UnsupportedOperationException();
609: }
610:
611: public Clob getClob(int i) throws SQLException {
612: throw new UnsupportedOperationException();
613: }
614:
615: public Array getArray(int i) throws SQLException {
616: throw new UnsupportedOperationException();
617: }
618:
619: public Object getObject(String colName, java.util.Map map)
620: throws SQLException {
621: throw new UnsupportedOperationException();
622: }
623:
624: public Ref getRef(String colName) throws SQLException {
625: throw new UnsupportedOperationException();
626: }
627:
628: public Blob getBlob(String colName) throws SQLException {
629: throw new UnsupportedOperationException();
630: }
631:
632: public Clob getClob(String colName) throws SQLException {
633: throw new UnsupportedOperationException();
634: }
635:
636: public Array getArray(String colName) throws SQLException {
637: throw new UnsupportedOperationException();
638: }
639:
640: public java.sql.Date getDate(int columnIndex, Calendar cal)
641: throws SQLException {
642: throw new UnsupportedOperationException();
643: }
644:
645: public java.sql.Date getDate(String columnName, Calendar cal)
646: throws SQLException {
647: throw new UnsupportedOperationException();
648: }
649:
650: public java.sql.Time getTime(int columnIndex, Calendar cal)
651: throws SQLException {
652: throw new UnsupportedOperationException();
653: }
654:
655: public java.sql.Time getTime(String columnName, Calendar cal)
656: throws SQLException {
657: throw new UnsupportedOperationException();
658: }
659:
660: public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal)
661: throws SQLException {
662: throw new UnsupportedOperationException();
663: }
664:
665: public java.sql.Timestamp getTimestamp(String columnName,
666: Calendar cal) throws SQLException {
667: throw new UnsupportedOperationException();
668: }
669:
670: public java.net.URL getURL(int columnIndex) throws SQLException {
671: throw new UnsupportedOperationException();
672: }
673:
674: public java.net.URL getURL(String columnName) throws SQLException {
675: throw new UnsupportedOperationException();
676: }
677:
678: public void updateRef(int columnIndex, java.sql.Ref x)
679: throws SQLException {
680: throw new UnsupportedOperationException();
681: }
682:
683: public void updateRef(String columnName, java.sql.Ref x)
684: throws SQLException {
685: throw new UnsupportedOperationException();
686: }
687:
688: public void updateBlob(int columnIndex, java.sql.Blob x)
689: throws SQLException {
690: throw new UnsupportedOperationException();
691: }
692:
693: public void updateBlob(String columnName, java.sql.Blob x)
694: throws SQLException {
695: throw new UnsupportedOperationException();
696: }
697:
698: public void updateClob(int columnIndex, java.sql.Clob x)
699: throws SQLException {
700: throw new UnsupportedOperationException();
701: }
702:
703: public void updateClob(String columnName, java.sql.Clob x)
704: throws SQLException {
705: throw new UnsupportedOperationException();
706: }
707:
708: public void updateArray(int columnIndex, java.sql.Array x)
709: throws SQLException {
710: throw new UnsupportedOperationException();
711: }
712:
713: public void updateArray(String columnName, java.sql.Array x)
714: throws SQLException {
715: throw new UnsupportedOperationException();
716: }
717: }
|