Debian Codegraph @

src/main/org/h2/tools/SimpleResultSet.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.tools;
7
8 import java.io.InputStream;
9 import java.io.Reader;
10 import java.math.BigDecimal;
11 import java.math.BigInteger;
12 import java.net.URL;
13 import java.sql.Array;
14 import java.sql.Blob;
15 import java.sql.Clob;
16 import java.sql.Date;
17 import java.sql.NClob;
18 import java.sql.Ref;
19 import java.sql.ResultSet;
20 import java.sql.ResultSetMetaData;
21 import java.sql.RowId;
22 import java.sql.SQLException;
23 import java.sql.SQLWarning;
24 import java.sql.SQLXML;
25 import java.sql.Statement;
26 import java.sql.Time;
27 import java.sql.Timestamp;
28 import java.sql.Types;
29 import java.util.ArrayList;
30 import java.util.Calendar;
31 import java.util.Map;
32 import java.util.UUID;
33 import org.h2.api.ErrorCode;
34 import org.h2.message.DbException;
35 import org.h2.util.Bits;
36 import org.h2.util.JdbcUtils;
37 import org.h2.util.MathUtils;
38 import org.h2.util.SimpleColumnInfo;
39 import org.h2.util.Utils;
40 import org.h2.value.DataType;
41 import org.h2.value.Value;
42 import org.h2.value.ValueToObjectConverter;
43
44 /**
45 * This class is a simple result set and meta data implementation.
46 * It can be used in Java functions that return a result set.
47 * Only the most basic methods are implemented, the others throw an exception.
48 * This implementation is standalone, and only relies on standard classes.
49 * It can be extended easily if required.
50 *
51 * An application can create a result set using the following code:
52 *
53 * <pre>
54 * SimpleResultSet rs = new SimpleResultSet();
55 * rs.addColumn(&quot;ID&quot;, Types.INTEGER, 10, 0);
56 * rs.addColumn(&quot;NAME&quot;, Types.VARCHAR, 255, 0);
57 * rs.addRow(0, &quot;Hello&quot; });
58 * rs.addRow(1, &quot;World&quot; });
59 * </pre>
60 *
61 */
62 public class SimpleResultSet implements ResultSet, ResultSetMetaData {
63
64 private ArrayList<Object[]> rows;
65 private Object[] currentRow;
66 private int rowId = -1;
67 private boolean wasNull;
68 private SimpleRowSource source;
69 private ArrayList<SimpleColumnInfo> columns = Utils.newSmallArrayList();
70 private boolean autoClose = true;
71
72 /**
73 * This constructor is used if the result set is later populated with
74 * addRow.
75 */
76 public SimpleResultSet() {
77 rows = Utils.newSmallArrayList();
78 }
79
80 /**
81 * This constructor is used if the result set should retrieve the rows using
82 * the specified row source object.
83 *
84 * @param source the row source
85 */
86 public SimpleResultSet(SimpleRowSource source) {
87 this.source = source;
88 }
89
90 /**
91 * Adds a column to the result set.
92 * All columns must be added before adding rows.
93 * This method uses the default SQL type names.
94 *
95 * @param name null is replaced with C1, C2,...
96 * @param sqlType the value returned in getColumnType(..)
97 * @param precision the precision
98 * @param scale the scale
99 */
100 public void addColumn(String name, int sqlType, int precision, int scale) {
101 int valueType = DataType.convertSQLTypeToValueType(sqlType);
102 addColumn(name, sqlType, Value.getTypeName(valueType), precision, scale);
103 }
104
105 /**
106 * Adds a column to the result set.
107 * All columns must be added before adding rows.
108 *
109 * @param name null is replaced with C1, C2,...
110 * @param sqlType the value returned in getColumnType(..)
111 * @param sqlTypeName the type name return in getColumnTypeName(..)
112 * @param precision the precision
113 * @param scale the scale
114 */
115 public void addColumn(String name, int sqlType, String sqlTypeName,
116 int precision, int scale) {
117 if (rows != null && !rows.isEmpty()) {
118 throw new IllegalStateException(
119 "Cannot add a column after adding rows");
120 }
121 if (name == null) {
122 name = "C" + (columns.size() + 1);
123 }
124 columns.add(new SimpleColumnInfo(name, sqlType, sqlTypeName, precision, scale));
125 }
126
127 /**
128 * Add a new row to the result set.
129 * Do not use this method when using a RowSource.
130 *
131 * @param row the row as an array of objects
132 */
133 public void addRow(Object... row) {
134 if (rows == null) {
135 throw new IllegalStateException(
136 "Cannot add a row when using RowSource");
137 }
138 rows.add(row);
139 }
140
141 /**
142 * Returns ResultSet.CONCUR_READ_ONLY.
143 *
144 * @return CONCUR_READ_ONLY
145 */
146 @Override
147 public int getConcurrency() {
148 return ResultSet.CONCUR_READ_ONLY;
149 }
150
151 /**
152 * Returns ResultSet.FETCH_FORWARD.
153 *
154 * @return FETCH_FORWARD
155 */
156 @Override
157 public int getFetchDirection() {
158 return ResultSet.FETCH_FORWARD;
159 }
160
161 /**
162 * Returns 0.
163 *
164 * @return 0
165 */
166 @Override
167 public int getFetchSize() {
168 return 0;
169 }
170
171 /**
172 * Returns the row number (1, 2,...) or 0 for no row.
173 *
174 * @return 0
175 */
176 @Override
177 public int getRow() {
178 return currentRow == null ? 0 : rowId + 1;
179 }
180
181 /**
182 * Returns the result set type. This is ResultSet.TYPE_FORWARD_ONLY for
183 * auto-close result sets, and ResultSet.TYPE_SCROLL_INSENSITIVE for others.
184 *
185 * @return TYPE_FORWARD_ONLY or TYPE_SCROLL_INSENSITIVE
186 */
187 @Override
188 public int getType() {
189 if (autoClose) {
190 return ResultSet.TYPE_FORWARD_ONLY;
191 }
192 return ResultSet.TYPE_SCROLL_INSENSITIVE;
193 }
194
195 /**
196 * Closes the result set and releases the resources.
197 */
198 @Override
199 public void close() {
200 currentRow = null;
201 rows = null;
202 columns = null;
203 rowId = -1;
204 if (source != null) {
205 source.close();
206 source = null;
207 }
208 }
209
210 /**
211 * Moves the cursor to the next row of the result set.
212 *
213 * @return true if successful, false if there are no more rows
214 */
215 @Override
216 public boolean next() throws SQLException {
217 if (source != null) {
218 rowId++;
219 currentRow = source.readRow();
220 if (currentRow != null) {
221 return true;
222 }
223 } else if (rows != null && rowId < rows.size()) {
224 rowId++;
225 if (rowId < rows.size()) {
226 currentRow = rows.get(rowId);
227 return true;
228 }
229 currentRow = null;
230 }
231 if (autoClose) {
232 close();
233 }
234 return false;
235 }
236
237 /**
238 * Moves the current position to before the first row, that means the result
239 * set is reset.
240 */
241 @Override
242 public void beforeFirst() throws SQLException {
243 if (autoClose) {
244 throw DbException.getJdbcSQLException(ErrorCode.RESULT_SET_NOT_SCROLLABLE);
245 }
246 rowId = -1;
247 if (source != null) {
248 source.reset();
249 }
250 }
251
252 /**
253 * Returns whether the last column accessed was null.
254 *
255 * @return true if the last column accessed was null
256 */
257 @Override
258 public boolean wasNull() {
259 return wasNull;
260 }
261
262 /**
263 * Searches for a specific column in the result set. A case-insensitive
264 * search is made.
265 *
266 * @param columnLabel the column label
267 * @return the column index (1,2,...)
268 * @throws SQLException if the column is not found or if the result set is
269 * closed
270 */
271 @Override
272 public int findColumn(String columnLabel) throws SQLException {
273 if (columnLabel != null && columns != null) {
274 for (int i = 0, size = columns.size(); i < size; i++) {
275 if (columnLabel.equalsIgnoreCase(getColumn(i).name)) {
276 return i + 1;
277 }
278 }
279 }
280 throw DbException.getJdbcSQLException(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel);
281 }
282
283 /**
284 * Returns a reference to itself.
285 *
286 * @return this
287 */
288 @Override
289 public ResultSetMetaData getMetaData() {
290 return this;
291 }
292
293 /**
294 * Returns null.
295 *
296 * @return null
297 */
298 @Override
299 public SQLWarning getWarnings() {
300 return null;
301 }
302
303 /**
304 * Returns null.
305 *
306 * @return null
307 */
308 @Override
309 public Statement getStatement() {
310 return null;
311 }
312
313 /**
314 * INTERNAL
315 */
316 @Override
317 public void clearWarnings() {
318 // nothing to do
319 }
320
321 // ---- get ---------------------------------------------
322
323 /**
324 * Returns the value as a java.sql.Array.
325 *
326 * @param columnIndex (1,2,...)
327 * @return the value
328 */
329 @Override
330 public Array getArray(int columnIndex) throws SQLException {
331 Object[] o = (Object[]) get(columnIndex);
332 return o == null ? null : new SimpleArray(o);
333 }
334
335 /**
336 * Returns the value as a java.sql.Array.
337 *
338 * @param columnLabel the column label
339 * @return the value
340 */
341 @Override
342 public Array getArray(String columnLabel) throws SQLException {
343 return getArray(findColumn(columnLabel));
344 }
345
346 /**
347 * INTERNAL
348 */
349 @Override
350 public InputStream getAsciiStream(int columnIndex) throws SQLException {
351 throw getUnsupportedException();
352 }
353
354 /**
355 * INTERNAL
356 */
357 @Override
358 public InputStream getAsciiStream(String columnLabel) throws SQLException {
359 throw getUnsupportedException();
360 }
361
362 /**
363 * Returns the value as a java.math.BigDecimal.
364 *
365 * @param columnIndex (1,2,...)
366 * @return the value
367 */
368 @Override
369 public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
370 Object o = get(columnIndex);
371 if (o != null && !(o instanceof BigDecimal)) {
372 o = new BigDecimal(o.toString());
373 }
374 return (BigDecimal) o;
375 }
376
377 /**
378 * Returns the value as a java.math.BigDecimal.
379 *
380 * @param columnLabel the column label
381 * @return the value
382 */
383 @Override
384 public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
385 return getBigDecimal(findColumn(columnLabel));
386 }
387
388 /**
389 * @deprecated INTERNAL
390 */
391 @Deprecated
392 @Override
393 public BigDecimal getBigDecimal(int columnIndex, int scale)
394 throws SQLException {
395 throw getUnsupportedException();
396 }
397
398 /**
399 * @deprecated INTERNAL
400 */
401 @Deprecated
402 @Override
403 public BigDecimal getBigDecimal(String columnLabel, int scale)
404 throws SQLException {
405 throw getUnsupportedException();
406 }
407
408 /**
409 * Returns the value as a java.io.InputStream.
410 *
411 * @param columnIndex (1,2,...)
412 * @return the value
413 */
414 @Override
415 public InputStream getBinaryStream(int columnIndex) throws SQLException {
416 return asInputStream(get(columnIndex));
417 }
418
419 private static InputStream asInputStream(Object o) throws SQLException {
420 if (o == null) {
421 return null;
422 } else if (o instanceof Blob) {
423 return ((Blob) o).getBinaryStream();
424 }
425 return (InputStream) o;
426 }
427
428 /**
429 * Returns the value as a java.io.InputStream.
430 *
431 * @param columnLabel the column label
432 * @return the value
433 */
434 @Override
435 public InputStream getBinaryStream(String columnLabel) throws SQLException {
436 return getBinaryStream(findColumn(columnLabel));
437 }
438
439 /**
440 * Returns the value as a java.sql.Blob.
441 * This is only supported if the
442 * result set was created using a Blob object.
443 *
444 * @param columnIndex (1,2,...)
445 * @return the value
446 */
447 @Override
448 public Blob getBlob(int columnIndex) throws SQLException {
449 return (Blob) get(columnIndex);
450 }
451
452 /**
453 * Returns the value as a java.sql.Blob.
454 * This is only supported if the
455 * result set was created using a Blob object.
456 *
457 * @param columnLabel the column label
458 * @return the value
459 */
460 @Override
461 public Blob getBlob(String columnLabel) throws SQLException {
462 return getBlob(findColumn(columnLabel));
463 }
464
465 /**
466 * Returns the value as a boolean.
467 *
468 * @param columnIndex (1,2,...)
469 * @return the value
470 */
471 @Override
472 public boolean getBoolean(int columnIndex) throws SQLException {
473 Object o = get(columnIndex);
474 if (o == null) {
475 return false;
476 }
477 if (o instanceof Boolean) {
478 return (Boolean) o;
479 }
480 if (o instanceof Number) {
481 Number n = (Number) o;
482 if (n instanceof Double || n instanceof Float) {
483 return n.doubleValue() != 0;
484 }
485 if (n instanceof BigDecimal) {
486 return ((BigDecimal) n).signum() != 0;
487 }
488 if (n instanceof BigInteger) {
489 return ((BigInteger) n).signum() != 0;
490 }
491 return n.longValue() != 0;
492 }
493 return Utils.parseBoolean(o.toString(), false, true);
494 }
495
496 /**
497 * Returns the value as a boolean.
498 *
499 * @param columnLabel the column label
500 * @return the value
501 */
502 @Override
503 public boolean getBoolean(String columnLabel) throws SQLException {
504 return getBoolean(findColumn(columnLabel));
505 }
506
507 /**
508 * Returns the value as a byte.
509 *
510 * @param columnIndex (1,2,...)
511 * @return the value
512 */
513 @Override
514 public byte getByte(int columnIndex) throws SQLException {
515 Object o = get(columnIndex);
516 if (o != null && !(o instanceof Number)) {
517 o = Byte.decode(o.toString());
518 }
519 return o == null ? 0 : ((Number) o).byteValue();
520 }
521
522 /**
523 * Returns the value as a byte.
524 *
525 * @param columnLabel the column label
526 * @return the value
527 */
528 @Override
529 public byte getByte(String columnLabel) throws SQLException {
530 return getByte(findColumn(columnLabel));
531 }
532
533 /**
534 * Returns the value as a byte array.
535 *
536 * @param columnIndex (1,2,...)
537 * @return the value
538 */
539 @Override
540 public byte[] getBytes(int columnIndex) throws SQLException {
541 Object o = get(columnIndex);
542 if (o == null || o instanceof byte[]) {
543 return (byte[]) o;
544 }
545 if (o instanceof UUID) {
546 return Bits.uuidToBytes((UUID) o);
547 }
548 return JdbcUtils.serialize(o, null);
549 }
550
551 /**
552 * Returns the value as a byte array.
553 *
554 * @param columnLabel the column label
555 * @return the value
556 */
557 @Override
558 public byte[] getBytes(String columnLabel) throws SQLException {
559 return getBytes(findColumn(columnLabel));
560 }
561
562 /**
563 * Returns the value as a java.io.Reader.
564 * This is only supported if the
565 * result set was created using a Clob or Reader object.
566 *
567 * @param columnIndex (1,2,...)
568 * @return the value
569 */
570 @Override
571 public Reader getCharacterStream(int columnIndex) throws SQLException {
572 return asReader(get(columnIndex));
573 }
574
575 private static Reader asReader(Object o) throws SQLException {
576 if (o == null) {
577 return null;
578 } else if (o instanceof Clob) {
579 return ((Clob) o).getCharacterStream();
580 }
581 return (Reader) o;
582 }
583
584 /**
585 * Returns the value as a java.io.Reader.
586 * This is only supported if the
587 * result set was created using a Clob or Reader object.
588 *
589 * @param columnLabel the column label
590 * @return the value
591 */
592 @Override
593 public Reader getCharacterStream(String columnLabel) throws SQLException {
594 return getCharacterStream(findColumn(columnLabel));
595 }
596
597 /**
598 * Returns the value as a java.sql.Clob.
599 * This is only supported if the
600 * result set was created using a Clob object.
601 *
602 * @param columnIndex (1,2,...)
603 * @return the value
604 */
605 @Override
606 public Clob getClob(int columnIndex) throws SQLException {
607 return (Clob) get(columnIndex);
608 }
609
610 /**
611 * Returns the value as a java.sql.Clob.
612 * This is only supported if the
613 * result set was created using a Clob object.
614 *
615 * @param columnLabel the column label
616 * @return the value
617 */
618 @Override
619 public Clob getClob(String columnLabel) throws SQLException {
620 return getClob(findColumn(columnLabel));
621 }
622
623 /**
624 * Returns the value as an java.sql.Date.
625 *
626 * @param columnIndex (1,2,...)
627 * @return the value
628 */
629 @Override
630 public Date getDate(int columnIndex) throws SQLException {
631 return (Date) get(columnIndex);
632 }
633
634 /**
635 * Returns the value as a java.sql.Date.
636 *
637 * @param columnLabel the column label
638 * @return the value
639 */
640 @Override
641 public Date getDate(String columnLabel) throws SQLException {
642 return getDate(findColumn(columnLabel));
643 }
644
645 /**
646 * INTERNAL
647 */
648 @Override
649 public Date getDate(int columnIndex, Calendar cal) throws SQLException {
650 throw getUnsupportedException();
651 }
652
653 /**
654 * INTERNAL
655 */
656 @Override
657 public Date getDate(String columnLabel, Calendar cal) throws SQLException {
658 throw getUnsupportedException();
659 }
660
661 /**
662 * Returns the value as an double.
663 *
664 * @param columnIndex (1,2,...)
665 * @return the value
666 */
667 @Override
668 public double getDouble(int columnIndex) throws SQLException {
669 Object o = get(columnIndex);
670 if (o != null && !(o instanceof Number)) {
671 return Double.parseDouble(o.toString());
672 }
673 return o == null ? 0 : ((Number) o).doubleValue();
674 }
675
676 /**
677 * Returns the value as a double.
678 *
679 * @param columnLabel the column label
680 * @return the value
681 */
682 @Override
683 public double getDouble(String columnLabel) throws SQLException {
684 return getDouble(findColumn(columnLabel));
685 }
686
687 /**
688 * Returns the value as a float.
689 *
690 * @param columnIndex (1,2,...)
691 * @return the value
692 */
693 @Override
694 public float getFloat(int columnIndex) throws SQLException {
695 Object o = get(columnIndex);
696 if (o != null && !(o instanceof Number)) {
697 return Float.parseFloat(o.toString());
698 }
699 return o == null ? 0 : ((Number) o).floatValue();
700 }
701
702 /**
703 * Returns the value as a float.
704 *
705 * @param columnLabel the column label
706 * @return the value
707 */
708 @Override
709 public float getFloat(String columnLabel) throws SQLException {
710 return getFloat(findColumn(columnLabel));
711 }
712
713 /**
714 * Returns the value as an int.
715 *
716 * @param columnIndex (1,2,...)
717 * @return the value
718 */
719 @Override
720 public int getInt(int columnIndex) throws SQLException {
721 Object o = get(columnIndex);
722 if (o != null && !(o instanceof Number)) {
723 o = Integer.decode(o.toString());
724 }
725 return o == null ? 0 : ((Number) o).intValue();
726 }
727
728 /**
729 * Returns the value as an int.
730 *
731 * @param columnLabel the column label
732 * @return the value
733 */
734 @Override
735 public int getInt(String columnLabel) throws SQLException {
736 return getInt(findColumn(columnLabel));
737 }
738
739 /**
740 * Returns the value as a long.
741 *
742 * @param columnIndex (1,2,...)
743 * @return the value
744 */
745 @Override
746 public long getLong(int columnIndex) throws SQLException {
747 Object o = get(columnIndex);
748 if (o != null && !(o instanceof Number)) {
749 o = Long.decode(o.toString());
750 }
751 return o == null ? 0 : ((Number) o).longValue();
752 }
753
754 /**
755 * Returns the value as a long.
756 *
757 * @param columnLabel the column label
758 * @return the value
759 */
760 @Override
761 public long getLong(String columnLabel) throws SQLException {
762 return getLong(findColumn(columnLabel));
763 }
764
765 /**
766 * INTERNAL
767 */
768 @Override
769 public Reader getNCharacterStream(int columnIndex) throws SQLException {
770 throw getUnsupportedException();
771 }
772
773 /**
774 * INTERNAL
775 */
776 @Override
777 public Reader getNCharacterStream(String columnLabel) throws SQLException {
778 throw getUnsupportedException();
779 }
780
781 /**
782 * INTERNAL
783 */
784 @Override
785 public NClob getNClob(int columnIndex) throws SQLException {
786 throw getUnsupportedException();
787 }
788
789 /**
790 * INTERNAL
791 */
792 @Override
793 public NClob getNClob(String columnLabel) throws SQLException {
794 throw getUnsupportedException();
795 }
796
797 /**
798 * INTERNAL
799 */
800 @Override
801 public String getNString(int columnIndex) throws SQLException {
802 return getString(columnIndex);
803 }
804
805 /**
806 * INTERNAL
807 */
808 @Override
809 public String getNString(String columnLabel) throws SQLException {
810 return getString(columnLabel);
811 }
812
813 /**
814 * Returns the value as an Object.
815 *
816 * @param columnIndex (1,2,...)
817 * @return the value
818 */
819 @Override
820 public Object getObject(int columnIndex) throws SQLException {
821 return get(columnIndex);
822 }
823
824 /**
825 * Returns the value as an Object.
826 *
827 * @param columnLabel the column label
828 * @return the value
829 */
830 @Override
831 public Object getObject(String columnLabel) throws SQLException {
832 return getObject(findColumn(columnLabel));
833 }
834
835 /**
836 * Returns the value as an Object of the specified type.
837 *
838 * @param columnIndex the column index (1, 2, ...)
839 * @param type the class of the returned value
840 * @return the value
841 */
842 @SuppressWarnings("unchecked")
843 @Override
844 public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
845 if (get(columnIndex) == null) {
846 return null;
847 }
848 if (type == BigDecimal.class) {
849 return (T) getBigDecimal(columnIndex);
850 } else if (type == BigInteger.class) {
851 return (T) getBigDecimal(columnIndex).toBigInteger();
852 } else if (type == String.class) {
853 return (T) getString(columnIndex);
854 } else if (type == Boolean.class) {
855 return (T) (Boolean) getBoolean(columnIndex);
856 } else if (type == Byte.class) {
857 return (T) (Byte) getByte(columnIndex);
858 } else if (type == Short.class) {
859 return (T) (Short) getShort(columnIndex);
860 } else if (type == Integer.class) {
861 return (T) (Integer) getInt(columnIndex);
862 } else if (type == Long.class) {
863 return (T) (Long) getLong(columnIndex);
864 } else if (type == Float.class) {
865 return (T) (Float) getFloat(columnIndex);
866 } else if (type == Double.class) {
867 return (T) (Double) getDouble(columnIndex);
868 } else if (type == Date.class) {
869 return (T) getDate(columnIndex);
870 } else if (type == Time.class) {
871 return (T) getTime(columnIndex);
872 } else if (type == Timestamp.class) {
873 return (T) getTimestamp(columnIndex);
874 } else if (type == UUID.class) {
875 return (T) getObject(columnIndex);
876 } else if (type == byte[].class) {
877 return (T) getBytes(columnIndex);
878 } else if (type == java.sql.Array.class) {
879 return (T) getArray(columnIndex);
880 } else if (type == Blob.class) {
881 return (T) getBlob(columnIndex);
882 } else if (type == Clob.class) {
883 return (T) getClob(columnIndex);
884 } else {
885 throw getUnsupportedException();
886 }
887 }
888
889 /**
890 * Returns the value as an Object of the specified type.
891 *
892 * @param columnName the column name
893 * @param type the class of the returned value
894 * @return the value
895 */
896 @Override
897 public <T> T getObject(String columnName, Class<T> type) throws SQLException {
898 return getObject(findColumn(columnName), type);
899 }
900
901 /**
902 * INTERNAL
903 */
904 @Override
905 public Object getObject(int columnIndex, Map<String, Class<?>> map)
906 throws SQLException {
907 throw getUnsupportedException();
908 }
909
910 /**
911 * INTERNAL
912 */
913 @Override
914 public Object getObject(String columnLabel, Map<String, Class<?>> map)
915 throws SQLException {
916 throw getUnsupportedException();
917 }
918
919 /**
920 * INTERNAL
921 */
922 @Override
923 public Ref getRef(int columnIndex) throws SQLException {
924 throw getUnsupportedException();
925 }
926
927 /**
928 * INTERNAL
929 */
930 @Override
931 public Ref getRef(String columnLabel) throws SQLException {
932 throw getUnsupportedException();
933 }
934
935 /**
936 * INTERNAL
937 */
938 @Override
939 public RowId getRowId(int columnIndex) throws SQLException {
940 throw getUnsupportedException();
941 }
942
943 /**
944 * INTERNAL
945 */
946 @Override
947 public RowId getRowId(String columnLabel) throws SQLException {
948 throw getUnsupportedException();
949 }
950
951 /**
952 * Returns the value as a short.
953 *
954 * @param columnIndex (1,2,...)
955 * @return the value
956 */
957 @Override
958 public short getShort(int columnIndex) throws SQLException {
959 Object o = get(columnIndex);
960 if (o != null && !(o instanceof Number)) {
961 o = Short.decode(o.toString());
962 }
963 return o == null ? 0 : ((Number) o).shortValue();
964 }
965
966 /**
967 * Returns the value as a short.
968 *
969 * @param columnLabel the column label
970 * @return the value
971 */
972 @Override
973 public short getShort(String columnLabel) throws SQLException {
974 return getShort(findColumn(columnLabel));
975 }
976
977 /**
978 * INTERNAL
979 */
980 @Override
981 public SQLXML getSQLXML(int columnIndex) throws SQLException {
982 throw getUnsupportedException();
983 }
984
985 /**
986 * INTERNAL
987 */
988 @Override
989 public SQLXML getSQLXML(String columnLabel) throws SQLException {
990 throw getUnsupportedException();
991 }
992
993 /**
994 * Returns the value as a String.
995 *
996 * @param columnIndex (1,2,...)
997 * @return the value
998 */
999 @Override
1000 public String getString(int columnIndex) throws SQLException {
1001 Object o = get(columnIndex);
1002 if (o == null) {
1003 return null;
1004 }
1005 switch (columns.get(columnIndex - 1).type) {
1006 case Types.CLOB:
1007 Clob c = (Clob) o;
1008 return c.getSubString(1, MathUtils.convertLongToInt(c.length()));
1009 }
1010 return o.toString();
1011 }
1012
1013 /**
1014 * Returns the value as a String.
1015 *
1016 * @param columnLabel the column label
1017 * @return the value
1018 */
1019 @Override
1020 public String getString(String columnLabel) throws SQLException {
1021 return getString(findColumn(columnLabel));
1022 }
1023
1024 /**
1025 * Returns the value as an java.sql.Time.
1026 *
1027 * @param columnIndex (1,2,...)
1028 * @return the value
1029 */
1030 @Override
1031 public Time getTime(int columnIndex) throws SQLException {
1032 return (Time) get(columnIndex);
1033 }
1034
1035 /**
1036 * Returns the value as a java.sql.Time.
1037 *
1038 * @param columnLabel the column label
1039 * @return the value
1040 */
1041 @Override
1042 public Time getTime(String columnLabel) throws SQLException {
1043 return getTime(findColumn(columnLabel));
1044 }
1045
1046 /**
1047 * INTERNAL
1048 */
1049 @Override
1050 public Time getTime(int columnIndex, Calendar cal) throws SQLException {
1051 throw getUnsupportedException();
1052 }
1053
1054 /**
1055 * INTERNAL
1056 */
1057 @Override
1058 public Time getTime(String columnLabel, Calendar cal) throws SQLException {
1059 throw getUnsupportedException();
1060 }
1061
1062 /**
1063 * Returns the value as an java.sql.Timestamp.
1064 *
1065 * @param columnIndex (1,2,...)
1066 * @return the value
1067 */
1068 @Override
1069 public Timestamp getTimestamp(int columnIndex) throws SQLException {
1070 return (Timestamp) get(columnIndex);
1071 }
1072
1073 /**
1074 * Returns the value as a java.sql.Timestamp.
1075 *
1076 * @param columnLabel the column label
1077 * @return the value
1078 */
1079 @Override
1080 public Timestamp getTimestamp(String columnLabel) throws SQLException {
1081 return getTimestamp(findColumn(columnLabel));
1082 }
1083
1084 /**
1085 * INTERNAL
1086 */
1087 @Override
1088 public Timestamp getTimestamp(int columnIndex, Calendar cal)
1089 throws SQLException {
1090 throw getUnsupportedException();
1091 }
1092
1093 /**
1094 * INTERNAL
1095 */
1096 @Override
1097 public Timestamp getTimestamp(String columnLabel, Calendar cal)
1098 throws SQLException {
1099 throw getUnsupportedException();
1100 }
1101
1102 /**
1103 * @deprecated INTERNAL
1104 */
1105 @Deprecated
1106 @Override
1107 public InputStream getUnicodeStream(int columnIndex) throws SQLException {
1108 throw getUnsupportedException();
1109 }
1110
1111 /**
1112 * @deprecated INTERNAL
1113 */
1114 @Deprecated
1115 @Override
1116 public InputStream getUnicodeStream(String columnLabel) throws SQLException {
1117 throw getUnsupportedException();
1118 }
1119
1120 /**
1121 * INTERNAL
1122 */
1123 @Override
1124 public URL getURL(int columnIndex) throws SQLException {
1125 throw getUnsupportedException();
1126 }
1127
1128 /**
1129 * INTERNAL
1130 */
1131 @Override
1132 public URL getURL(String columnLabel) throws SQLException {
1133 throw getUnsupportedException();
1134 }
1135
1136 // ---- update ---------------------------------------------
1137
1138 /**
1139 * INTERNAL
1140 */
1141 @Override
1142 public void updateArray(int columnIndex, Array x) throws SQLException {
1143 update(columnIndex, x);
1144 }
1145
1146 /**
1147 * INTERNAL
1148 */
1149 @Override
1150 public void updateArray(String columnLabel, Array x) throws SQLException {
1151 update(columnLabel, x);
1152 }
1153
1154 /**
1155 * INTERNAL
1156 */
1157 @Override
1158 public void updateAsciiStream(int columnIndex, InputStream x)
1159 throws SQLException {
1160 update(columnIndex, x);
1161 }
1162
1163 /**
1164 * INTERNAL
1165 */
1166 @Override
1167 public void updateAsciiStream(String columnLabel, InputStream x)
1168 throws SQLException {
1169 update(columnLabel, x);
1170 }
1171
1172 /**
1173 * INTERNAL
1174 */
1175 @Override
1176 public void updateAsciiStream(int columnIndex, InputStream x, int length)
1177 throws SQLException {
1178 update(columnIndex, x);
1179 }
1180
1181 /**
1182 * INTERNAL
1183 */
1184 @Override
1185 public void updateAsciiStream(String columnLabel, InputStream x, int length)
1186 throws SQLException {
1187 update(columnLabel, x);
1188 }
1189
1190 /**
1191 * INTERNAL
1192 */
1193 @Override
1194 public void updateAsciiStream(int columnIndex, InputStream x, long length)
1195 throws SQLException {
1196 update(columnIndex, x);
1197 }
1198
1199 /**
1200 * INTERNAL
1201 */
1202 @Override
1203 public void updateAsciiStream(String columnLabel, InputStream x, long length)
1204 throws SQLException {
1205 update(columnLabel, x);
1206 }
1207
1208 /**
1209 * INTERNAL
1210 */
1211 @Override
1212 public void updateBigDecimal(int columnIndex, BigDecimal x)
1213 throws SQLException {
1214 update(columnIndex, x);
1215 }
1216
1217 /**
1218 * INTERNAL
1219 */
1220 @Override
1221 public void updateBigDecimal(String columnLabel, BigDecimal x)
1222 throws SQLException {
1223 update(columnLabel, x);
1224 }
1225
1226 /**
1227 * INTERNAL
1228 */
1229 @Override
1230 public void updateBinaryStream(int columnIndex, InputStream x)
1231 throws SQLException {
1232 update(columnIndex, x);
1233 }
1234
1235 /**
1236 * INTERNAL
1237 */
1238 @Override
1239 public void updateBinaryStream(String columnLabel, InputStream x)
1240 throws SQLException {
1241 update(columnLabel, x);
1242 }
1243
1244 /**
1245 * INTERNAL
1246 */
1247 @Override
1248 public void updateBinaryStream(int columnIndex, InputStream x, int length)
1249 throws SQLException {
1250 update(columnIndex, x);
1251 }
1252
1253 /**
1254 * INTERNAL
1255 */
1256 @Override
1257 public void updateBinaryStream(String columnLabel, InputStream x, int length)
1258 throws SQLException {
1259 update(columnLabel, x);
1260 }
1261
1262 /**
1263 * INTERNAL
1264 */
1265 @Override
1266 public void updateBinaryStream(int columnIndex, InputStream x, long length)
1267 throws SQLException {
1268 update(columnIndex, x);
1269 }
1270
1271 /**
1272 * INTERNAL
1273 */
1274 @Override
1275 public void updateBinaryStream(String columnLabel, InputStream x, long length)
1276 throws SQLException {
1277 update(columnLabel, x);
1278 }
1279
1280 /**
1281 * INTERNAL
1282 */
1283 @Override
1284 public void updateBlob(int columnIndex, Blob x) throws SQLException {
1285 update(columnIndex, x);
1286 }
1287
1288 /**
1289 * INTERNAL
1290 */
1291 @Override
1292 public void updateBlob(String columnLabel, Blob x) throws SQLException {
1293 update(columnLabel, x);
1294 }
1295
1296 /**
1297 * INTERNAL
1298 */
1299 @Override
1300 public void updateBlob(int columnIndex, InputStream x) throws SQLException {
1301 update(columnIndex, x);
1302 }
1303
1304 /**
1305 * INTERNAL
1306 */
1307 @Override
1308 public void updateBlob(String columnLabel, InputStream x)
1309 throws SQLException {
1310 update(columnLabel, x);
1311 }
1312
1313 /**
1314 * INTERNAL
1315 */
1316 @Override
1317 public void updateBlob(int columnIndex, InputStream x, long length)
1318 throws SQLException {
1319 update(columnIndex, x);
1320 }
1321
1322 /**
1323 * INTERNAL
1324 */
1325 @Override
1326 public void updateBlob(String columnLabel, InputStream x, long length)
1327 throws SQLException {
1328 update(columnLabel, x);
1329 }
1330
1331 /**
1332 * INTERNAL
1333 */
1334 @Override
1335 public void updateBoolean(int columnIndex, boolean x) throws SQLException {
1336 update(columnIndex, x);
1337 }
1338
1339 /**
1340 * INTERNAL
1341 */
1342 @Override
1343 public void updateBoolean(String columnLabel, boolean x)
1344 throws SQLException {
1345 update(columnLabel, x);
1346 }
1347
1348 /**
1349 * INTERNAL
1350 */
1351 @Override
1352 public void updateByte(int columnIndex, byte x) throws SQLException {
1353 update(columnIndex, x);
1354 }
1355
1356 /**
1357 * INTERNAL
1358 */
1359 @Override
1360 public void updateByte(String columnLabel, byte x) throws SQLException {
1361 update(columnLabel, x);
1362 }
1363
1364 /**
1365 * INTERNAL
1366 */
1367 @Override
1368 public void updateBytes(int columnIndex, byte[] x) throws SQLException {
1369 update(columnIndex, x);
1370 }
1371
1372 /**
1373 * INTERNAL
1374 */
1375 @Override
1376 public void updateBytes(String columnLabel, byte[] x) throws SQLException {
1377 update(columnLabel, x);
1378 }
1379
1380 /**
1381 * INTERNAL
1382 */
1383 @Override
1384 public void updateCharacterStream(int columnIndex, Reader x)
1385 throws SQLException {
1386 update(columnIndex, x);
1387 }
1388
1389 /**
1390 * INTERNAL
1391 */
1392 @Override
1393 public void updateCharacterStream(String columnLabel, Reader x)
1394 throws SQLException {
1395 update(columnLabel, x);
1396 }
1397
1398 /**
1399 * INTERNAL
1400 */
1401 @Override
1402 public void updateCharacterStream(int columnIndex, Reader x, int length)
1403 throws SQLException {
1404 update(columnIndex, x);
1405 }
1406
1407 /**
1408 * INTERNAL
1409 */
1410 @Override
1411 public void updateCharacterStream(String columnLabel, Reader x, int length)
1412 throws SQLException {
1413 update(columnLabel, x);
1414 }
1415
1416 /**
1417 * INTERNAL
1418 */
1419 @Override
1420 public void updateCharacterStream(int columnIndex, Reader x, long length)
1421 throws SQLException {
1422 update(columnIndex, x);
1423 }
1424
1425 /**
1426 * INTERNAL
1427 */
1428 @Override
1429 public void updateCharacterStream(String columnLabel, Reader x, long length)
1430 throws SQLException {
1431 update(columnLabel, x);
1432 }
1433
1434 /**
1435 * INTERNAL
1436 */
1437 @Override
1438 public void updateClob(int columnIndex, Clob x) throws SQLException {
1439 update(columnIndex, x);
1440 }
1441
1442 /**
1443 * INTERNAL
1444 */
1445 @Override
1446 public void updateClob(String columnLabel, Clob x) throws SQLException {
1447 update(columnLabel, x);
1448 }
1449
1450 /**
1451 * INTERNAL
1452 */
1453 @Override
1454 public void updateClob(int columnIndex, Reader x) throws SQLException {
1455 update(columnIndex, x);
1456 }
1457
1458 /**
1459 * INTERNAL
1460 */
1461 @Override
1462 public void updateClob(String columnLabel, Reader x) throws SQLException {
1463 update(columnLabel, x);
1464 }
1465
1466 /**
1467 * INTERNAL
1468 */
1469 @Override
1470 public void updateClob(int columnIndex, Reader x, long length)
1471 throws SQLException {
1472 update(columnIndex, x);
1473 }
1474
1475 /**
1476 * INTERNAL
1477 */
1478 @Override
1479 public void updateClob(String columnLabel, Reader x, long length)
1480 throws SQLException {
1481 update(columnLabel, x);
1482 }
1483
1484 /**
1485 * INTERNAL
1486 */
1487 @Override
1488 public void updateDate(int columnIndex, Date x) throws SQLException {
1489 update(columnIndex, x);
1490 }
1491
1492 /**
1493 * INTERNAL
1494 */
1495 @Override
1496 public void updateDate(String columnLabel, Date x) throws SQLException {
1497 update(columnLabel, x);
1498 }
1499
1500 /**
1501 * INTERNAL
1502 */
1503 @Override
1504 public void updateDouble(int columnIndex, double x) throws SQLException {
1505 update(columnIndex, x);
1506 }
1507
1508 /**
1509 * INTERNAL
1510 */
1511 @Override
1512 public void updateDouble(String columnLabel, double x) throws SQLException {
1513 update(columnLabel, x);
1514 }
1515
1516 /**
1517 * INTERNAL
1518 */
1519 @Override
1520 public void updateFloat(int columnIndex, float x) throws SQLException {
1521 update(columnIndex, x);
1522 }
1523
1524 /**
1525 * INTERNAL
1526 */
1527 @Override
1528 public void updateFloat(String columnLabel, float x) throws SQLException {
1529 update(columnLabel, x);
1530 }
1531
1532 /**
1533 * INTERNAL
1534 */
1535 @Override
1536 public void updateInt(int columnIndex, int x) throws SQLException {
1537 update(columnIndex, x);
1538 }
1539
1540 /**
1541 * INTERNAL
1542 */
1543 @Override
1544 public void updateInt(String columnLabel, int x) throws SQLException {
1545 update(columnLabel, x);
1546 }
1547
1548 /**
1549 * INTERNAL
1550 */
1551 @Override
1552 public void updateLong(int columnIndex, long x) throws SQLException {
1553 update(columnIndex, x);
1554 }
1555
1556 /**
1557 * INTERNAL
1558 */
1559 @Override
1560 public void updateLong(String columnLabel, long x) throws SQLException {
1561 update(columnLabel, x);
1562 }
1563
1564 /**
1565 * INTERNAL
1566 */
1567 @Override
1568 public void updateNCharacterStream(int columnIndex, Reader x)
1569 throws SQLException {
1570 update(columnIndex, x);
1571 }
1572
1573 /**
1574 * INTERNAL
1575 */
1576 @Override
1577 public void updateNCharacterStream(String columnLabel, Reader x)
1578 throws SQLException {
1579 update(columnLabel, x);
1580 }
1581
1582 /**
1583 * INTERNAL
1584 */
1585 @Override
1586 public void updateNCharacterStream(int columnIndex, Reader x, long length)
1587 throws SQLException {
1588 update(columnIndex, x);
1589 }
1590
1591 /**
1592 * INTERNAL
1593 */
1594 @Override
1595 public void updateNCharacterStream(String columnLabel, Reader x, long length)
1596 throws SQLException {
1597 update(columnLabel, x);
1598 }
1599
1600 /**
1601 * INTERNAL
1602 */
1603 @Override
1604 public void updateNClob(int columnIndex, NClob x) throws SQLException {
1605 update(columnIndex, x);
1606 }
1607
1608 /**
1609 * INTERNAL
1610 */
1611 @Override
1612 public void updateNClob(String columnLabel, NClob x) throws SQLException {
1613 update(columnLabel, x);
1614 }
1615
1616 /**
1617 * INTERNAL
1618 */
1619 @Override
1620 public void updateNClob(int columnIndex, Reader x) throws SQLException {
1621 update(columnIndex, x);
1622 }
1623
1624 /**
1625 * INTERNAL
1626 */
1627 @Override
1628 public void updateNClob(String columnLabel, Reader x) throws SQLException {
1629 update(columnLabel, x);
1630 }
1631
1632 /**
1633 * INTERNAL
1634 */
1635 @Override
1636 public void updateNClob(int columnIndex, Reader x, long length)
1637 throws SQLException {
1638 update(columnIndex, x);
1639 }
1640
1641 /**
1642 * INTERNAL
1643 */
1644 @Override
1645 public void updateNClob(String columnLabel, Reader x, long length)
1646 throws SQLException {
1647 update(columnLabel, x);
1648 }
1649
1650 /**
1651 * INTERNAL
1652 */
1653 @Override
1654 public void updateNString(int columnIndex, String x) throws SQLException {
1655 update(columnIndex, x);
1656 }
1657
1658 /**
1659 * INTERNAL
1660 */
1661 @Override
1662 public void updateNString(String columnLabel, String x) throws SQLException {
1663 update(columnLabel, x);
1664 }
1665
1666 /**
1667 * INTERNAL
1668 */
1669 @Override
1670 public void updateNull(int columnIndex) throws SQLException {
1671 update(columnIndex, null);
1672 }
1673
1674 /**
1675 * INTERNAL
1676 */
1677 @Override
1678 public void updateNull(String columnLabel) throws SQLException {
1679 update(columnLabel, null);
1680 }
1681
1682 /**
1683 * INTERNAL
1684 */
1685 @Override
1686 public void updateObject(int columnIndex, Object x) throws SQLException {
1687 update(columnIndex, x);
1688 }
1689
1690 /**
1691 * INTERNAL
1692 */
1693 @Override
1694 public void updateObject(String columnLabel, Object x) throws SQLException {
1695 update(columnLabel, x);
1696 }
1697
1698 /**
1699 * INTERNAL
1700 */
1701 @Override
1702 public void updateObject(int columnIndex, Object x, int scale)
1703 throws SQLException {
1704 update(columnIndex, x);
1705 }
1706
1707 /**
1708 * INTERNAL
1709 */
1710 @Override
1711 public void updateObject(String columnLabel, Object x, int scale)
1712 throws SQLException {
1713 update(columnLabel, x);
1714 }
1715
1716 /**
1717 * INTERNAL
1718 */
1719 @Override
1720 public void updateRef(int columnIndex, Ref x) throws SQLException {
1721 update(columnIndex, x);
1722 }
1723
1724 /**
1725 * INTERNAL
1726 */
1727 @Override
1728 public void updateRef(String columnLabel, Ref x) throws SQLException {
1729 update(columnLabel, x);
1730 }
1731
1732 /**
1733 * INTERNAL
1734 */
1735 @Override
1736 public void updateRowId(int columnIndex, RowId x) throws SQLException {
1737 update(columnIndex, x);
1738 }
1739
1740 /**
1741 * INTERNAL
1742 */
1743 @Override
1744 public void updateRowId(String columnLabel, RowId x) throws SQLException {
1745 update(columnLabel, x);
1746 }
1747
1748 /**
1749 * INTERNAL
1750 */
1751 @Override
1752 public void updateShort(int columnIndex, short x) throws SQLException {
1753 update(columnIndex, x);
1754 }
1755
1756 /**
1757 * INTERNAL
1758 */
1759 @Override
1760 public void updateShort(String columnLabel, short x) throws SQLException {
1761 update(columnLabel, x);
1762 }
1763
1764 /**
1765 * INTERNAL
1766 */
1767 @Override
1768 public void updateSQLXML(int columnIndex, SQLXML x) throws SQLException {
1769 update(columnIndex, x);
1770 }
1771
1772 /**
1773 * INTERNAL
1774 */
1775 @Override
1776 public void updateSQLXML(String columnLabel, SQLXML x) throws SQLException {
1777 update(columnLabel, x);
1778 }
1779
1780 /**
1781 * INTERNAL
1782 */
1783 @Override
1784 public void updateString(int columnIndex, String x) throws SQLException {
1785 update(columnIndex, x);
1786 }
1787
1788 /**
1789 * INTERNAL
1790 */
1791 @Override
1792 public void updateString(String columnLabel, String x) throws SQLException {
1793 update(columnLabel, x);
1794 }
1795
1796 /**
1797 * INTERNAL
1798 */
1799 @Override
1800 public void updateTime(int columnIndex, Time x) throws SQLException {
1801 update(columnIndex, x);
1802 }
1803
1804 /**
1805 * INTERNAL
1806 */
1807 @Override
1808 public void updateTime(String columnLabel, Time x) throws SQLException {
1809 update(columnLabel, x);
1810 }
1811
1812 /**
1813 * INTERNAL
1814 */
1815 @Override
1816 public void updateTimestamp(int columnIndex, Timestamp x)
1817 throws SQLException {
1818 update(columnIndex, x);
1819 }
1820
1821 /**
1822 * INTERNAL
1823 */
1824 @Override
1825 public void updateTimestamp(String columnLabel, Timestamp x)
1826 throws SQLException {
1827 update(columnLabel, x);
1828 }
1829
1830 // ---- result set meta data ---------------------------------------------
1831
1832 /**
1833 * Returns the column count.
1834 *
1835 * @return the column count
1836 */
1837 @Override
1838 public int getColumnCount() {
1839 return columns.size();
1840 }
1841
1842 /**
1843 * Returns 15.
1844 *
1845 * @param columnIndex (1,2,...)
1846 * @return 15
1847 */
1848 @Override
1849 public int getColumnDisplaySize(int columnIndex) {
1850 return 15;
1851 }
1852
1853 /**
1854 * Returns the SQL type.
1855 *
1856 * @param columnIndex (1,2,...)
1857 * @return the SQL type
1858 */
1859 @Override
1860 public int getColumnType(int columnIndex) throws SQLException {
1861 return getColumn(columnIndex - 1).type;
1862 }
1863
1864 /**
1865 * Returns the precision.
1866 *
1867 * @param columnIndex (1,2,...)
1868 * @return the precision
1869 */
1870 @Override
1871 public int getPrecision(int columnIndex) throws SQLException {
1872 return getColumn(columnIndex - 1).precision;
1873 }
1874
1875 /**
1876 * Returns the scale.
1877 *
1878 * @param columnIndex (1,2,...)
1879 * @return the scale
1880 */
1881 @Override
1882 public int getScale(int columnIndex) throws SQLException {
1883 return getColumn(columnIndex - 1).scale;
1884 }
1885
1886 /**
1887 * Returns ResultSetMetaData.columnNullableUnknown.
1888 *
1889 * @param columnIndex (1,2,...)
1890 * @return columnNullableUnknown
1891 */
1892 @Override
1893 public int isNullable(int columnIndex) {
1894 return ResultSetMetaData.columnNullableUnknown;
1895 }
1896
1897 /**
1898 * Returns false.
1899 *
1900 * @param columnIndex (1,2,...)
1901 * @return false
1902 */
1903 @Override
1904 public boolean isAutoIncrement(int columnIndex) {
1905 return false;
1906 }
1907
1908 /**
1909 * Returns true.
1910 *
1911 * @param columnIndex (1,2,...)
1912 * @return true
1913 */
1914 @Override
1915 public boolean isCaseSensitive(int columnIndex) {
1916 return true;
1917 }
1918
1919 /**
1920 * Returns false.
1921 *
1922 * @param columnIndex (1,2,...)
1923 * @return false
1924 */
1925 @Override
1926 public boolean isCurrency(int columnIndex) {
1927 return false;
1928 }
1929
1930 /**
1931 * Returns false.
1932 *
1933 * @param columnIndex (1,2,...)
1934 * @return false
1935 */
1936 @Override
1937 public boolean isDefinitelyWritable(int columnIndex) {
1938 return false;
1939 }
1940
1941 /**
1942 * Returns true.
1943 *
1944 * @param columnIndex (1,2,...)
1945 * @return true
1946 */
1947 @Override
1948 public boolean isReadOnly(int columnIndex) {
1949 return true;
1950 }
1951
1952 /**
1953 * Returns true.
1954 *
1955 * @param columnIndex (1,2,...)
1956 * @return true
1957 */
1958 @Override
1959 public boolean isSearchable(int columnIndex) {
1960 return true;
1961 }
1962
1963 /**
1964 * Returns true.
1965 *
1966 * @param columnIndex (1,2,...)
1967 * @return true
1968 */
1969 @Override
1970 public boolean isSigned(int columnIndex) {
1971 return true;
1972 }
1973
1974 /**
1975 * Returns false.
1976 *
1977 * @param columnIndex (1,2,...)
1978 * @return false
1979 */
1980 @Override
1981 public boolean isWritable(int columnIndex) {
1982 return false;
1983 }
1984
1985 /**
1986 * Returns empty string.
1987 *
1988 * @param columnIndex (1,2,...)
1989 * @return empty string
1990 */
1991 @Override
1992 public String getCatalogName(int columnIndex) {
1993 return "";
1994 }
1995
1996 /**
1997 * Returns the Java class name if this column.
1998 *
1999 * @param columnIndex (1,2,...)
2000 * @return the class name
2001 */
2002 @Override
2003 public String getColumnClassName(int columnIndex) throws SQLException {
2004 int type = DataType.getValueTypeFromResultSet(this, columnIndex);
2005 return ValueToObjectConverter.getDefaultClass(type, true).getName();
2006 }
2007
2008 /**
2009 * Returns the column label.
2010 *
2011 * @param columnIndex (1,2,...)
2012 * @return the column label
2013 */
2014 @Override
2015 public String getColumnLabel(int columnIndex) throws SQLException {
2016 return getColumn(columnIndex - 1).name;
2017 }
2018
2019 /**
2020 * Returns the column name.
2021 *
2022 * @param columnIndex (1,2,...)
2023 * @return the column name
2024 */
2025 @Override
2026 public String getColumnName(int columnIndex) throws SQLException {
2027 return getColumnLabel(columnIndex);
2028 }
2029
2030 /**
2031 * Returns the data type name of a column.
2032 *
2033 * @param columnIndex (1,2,...)
2034 * @return the type name
2035 */
2036 @Override
2037 public String getColumnTypeName(int columnIndex) throws SQLException {
2038 return getColumn(columnIndex - 1).typeName;
2039 }
2040
2041 /**
2042 * Returns empty string.
2043 *
2044 * @param columnIndex (1,2,...)
2045 * @return empty string
2046 */
2047 @Override
2048 public String getSchemaName(int columnIndex) {
2049 return "";
2050 }
2051
2052 /**
2053 * Returns empty string.
2054 *
2055 * @param columnIndex (1,2,...)
2056 * @return empty string
2057 */
2058 @Override
2059 public String getTableName(int columnIndex) {
2060 return "";
2061 }
2062
2063 // ---- unsupported / result set -----------------------------------
2064
2065 /**
2066 * INTERNAL
2067 */
2068 @Override
2069 public void afterLast() throws SQLException {
2070 throw getUnsupportedException();
2071 }
2072
2073 /**
2074 * INTERNAL
2075 */
2076 @Override
2077 public void cancelRowUpdates() throws SQLException {
2078 throw getUnsupportedException();
2079 }
2080
2081 /**
2082 * INTERNAL
2083 */
2084 @Override
2085 public void deleteRow() throws SQLException {
2086 throw getUnsupportedException();
2087 }
2088
2089 /**
2090 * INTERNAL
2091 */
2092 @Override
2093 public void insertRow() throws SQLException {
2094 throw getUnsupportedException();
2095 }
2096
2097 /**
2098 * INTERNAL
2099 */
2100 @Override
2101 public void moveToCurrentRow() throws SQLException {
2102 throw getUnsupportedException();
2103 }
2104
2105 /**
2106 * INTERNAL
2107 */
2108 @Override
2109 public void moveToInsertRow() throws SQLException {
2110 throw getUnsupportedException();
2111 }
2112
2113 /**
2114 * INTERNAL
2115 */
2116 @Override
2117 public void refreshRow() throws SQLException {
2118 throw getUnsupportedException();
2119 }
2120
2121 /**
2122 * INTERNAL
2123 */
2124 @Override
2125 public void updateRow() throws SQLException {
2126 throw getUnsupportedException();
2127 }
2128
2129 /**
2130 * INTERNAL
2131 */
2132 @Override
2133 public boolean first() throws SQLException {
2134 throw getUnsupportedException();
2135 }
2136
2137 /**
2138 * INTERNAL
2139 */
2140 @Override
2141 public boolean isAfterLast() throws SQLException {
2142 throw getUnsupportedException();
2143 }
2144
2145 /**
2146 * INTERNAL
2147 */
2148 @Override
2149 public boolean isBeforeFirst() throws SQLException {
2150 throw getUnsupportedException();
2151 }
2152
2153 /**
2154 * INTERNAL
2155 */
2156 @Override
2157 public boolean isFirst() throws SQLException {
2158 throw getUnsupportedException();
2159 }
2160
2161 /**
2162 * INTERNAL
2163 */
2164 @Override
2165 public boolean isLast() throws SQLException {
2166 throw getUnsupportedException();
2167 }
2168
2169 /**
2170 * INTERNAL
2171 */
2172 @Override
2173 public boolean last() throws SQLException {
2174 throw getUnsupportedException();
2175 }
2176
2177 /**
2178 * INTERNAL
2179 */
2180 @Override
2181 public boolean previous() throws SQLException {
2182 throw getUnsupportedException();
2183 }
2184
2185 /**
2186 * INTERNAL
2187 */
2188 @Override
2189 public boolean rowDeleted() throws SQLException {
2190 throw getUnsupportedException();
2191 }
2192
2193 /**
2194 * INTERNAL
2195 */
2196 @Override
2197 public boolean rowInserted() throws SQLException {
2198 throw getUnsupportedException();
2199 }
2200
2201 /**
2202 * INTERNAL
2203 */
2204 @Override
2205 public boolean rowUpdated() throws SQLException {
2206 return true;
2207 }
2208
2209 /**
2210 * INTERNAL
2211 */
2212 @Override
2213 public void setFetchDirection(int direction) throws SQLException {
2214 throw getUnsupportedException();
2215 }
2216
2217 /**
2218 * INTERNAL
2219 */
2220 @Override
2221 public void setFetchSize(int rows) throws SQLException {
2222 throw getUnsupportedException();
2223 }
2224
2225 /**
2226 * INTERNAL
2227 */
2228 @Override
2229 public boolean absolute(int row) throws SQLException {
2230 throw getUnsupportedException();
2231 }
2232
2233 /**
2234 * INTERNAL
2235 */
2236 @Override
2237 public boolean relative(int offset) throws SQLException {
2238 throw getUnsupportedException();
2239 }
2240
2241 /**
2242 * INTERNAL
2243 */
2244 @Override
2245 public String getCursorName() throws SQLException {
2246 throw getUnsupportedException();
2247 }
2248
2249 // --- private -----------------------------
2250
2251 private void update(int columnIndex, Object obj) throws SQLException {
2252 checkClosed();
2253 checkColumnIndex(columnIndex);
2254 this.currentRow[columnIndex - 1] = obj;
2255 }
2256
2257 private void update(String columnLabel, Object obj) throws SQLException {
2258 this.currentRow[findColumn(columnLabel) - 1] = obj;
2259 }
2260
2261 /**
2262 * INTERNAL
2263 */
2264 static SQLException getUnsupportedException() {
2265 return DbException.getJdbcSQLException(ErrorCode.FEATURE_NOT_SUPPORTED_1);
2266 }
2267
2268 private void checkClosed() throws SQLException {
2269 if (columns == null) {
2270 throw DbException.getJdbcSQLException(ErrorCode.OBJECT_CLOSED);
2271 }
2272 }
2273
2274 private void checkColumnIndex(int columnIndex) throws SQLException {
2275 if (columnIndex < 1 || columnIndex > columns.size()) {
2276 throw DbException.getInvalidValueException(
2277 "columnIndex", columnIndex).getSQLException();
2278 }
2279 }
2280
2281 private Object get(int columnIndex) throws SQLException {
2282 if (currentRow == null) {
2283 throw DbException.getJdbcSQLException(ErrorCode.NO_DATA_AVAILABLE);
2284 }
2285 checkColumnIndex(columnIndex);
2286 columnIndex--;
2287 Object o = columnIndex < currentRow.length ?
2288 currentRow[columnIndex] : null;
2289 wasNull = o == null;
2290 return o;
2291 }
2292
2293 private SimpleColumnInfo getColumn(int i) throws SQLException {
2294 checkColumnIndex(i + 1);
2295 return columns.get(i);
2296 }
2297
2298 /**
2299 * Returns the current result set holdability.
2300 *
2301 * @return the holdability
2302 */
2303 @Override
2304 public int getHoldability() {
2305 return ResultSet.HOLD_CURSORS_OVER_COMMIT;
2306 }
2307
2308 /**
2309 * Returns whether this result set has been closed.
2310 *
2311 * @return true if the result set was closed
2312 */
2313 @Override
2314 public boolean isClosed() {
2315 return rows == null && source == null;
2316 }
2317
2318 /**
2319 * Return an object of this class if possible.
2320 *
2321 * @param iface the class
2322 * @return this
2323 */
2324 @Override
2325 @SuppressWarnings("unchecked")
2326 public <T> T unwrap(Class<T> iface) throws SQLException {
2327 try {
2328 if (isWrapperFor(iface)) {
2329 return (T) this;
2330 }
2331 throw DbException.getInvalidValueException("iface", iface);
2332 } catch (Exception e) {
2333 throw DbException.toSQLException(e);
2334 }
2335 }
2336
2337 /**
2338 * Checks if unwrap can return an object of this class.
2339 *
2340 * @param iface the class
2341 * @return whether or not the interface is assignable from this class
2342 */
2343 @Override
2344 public boolean isWrapperFor(Class<?> iface) throws SQLException {
2345 return iface != null && iface.isAssignableFrom(getClass());
2346 }
2347
2348 /**
2349 * Set the auto-close behavior. If enabled (the default), the result set is
2350 * closed after reading the last row.
2351 *
2352 * @param autoClose the new value
2353 */
2354 public void setAutoClose(boolean autoClose) {
2355 this.autoClose = autoClose;
2356 }
2357
2358 /**
2359 * Get the current auto-close behavior.
2360 *
2361 * @return the auto-close value
2362 */
2363 public boolean getAutoClose() {
2364 return autoClose;
2365 }
2366
2367 /**
2368 * A simple array implementation,
2369 * backed by an object array
2370 */
2371 public static class SimpleArray implements Array {
2372
2373 private final Object[] value;
2374
2375 SimpleArray(Object[] value) {
2376 this.value = value;
2377 }
2378
2379 /**
2380 * Get the object array.
2381 *
2382 * @return the object array
2383 */
2384 @Override
2385 public Object getArray() {
2386 return value;
2387 }
2388
2389 /**
2390 * INTERNAL
2391 */
2392 @Override
2393 public Object getArray(Map<String, Class<?>> map) throws SQLException {
2394 throw getUnsupportedException();
2395 }
2396
2397 /**
2398 * INTERNAL
2399 */
2400 @Override
2401 public Object getArray(long index, int count) throws SQLException {
2402 throw getUnsupportedException();
2403 }
2404
2405 /**
2406 * INTERNAL
2407 */
2408 @Override
2409 public Object getArray(long index, int count, Map<String, Class<?>> map)
2410 throws SQLException {
2411 throw getUnsupportedException();
2412 }
2413
2414 /**
2415 * Get the base type of this array.
2416 *
2417 * @return Types.NULL
2418 */
2419 @Override
2420 public int getBaseType() {
2421 return Types.NULL;
2422 }
2423
2424 /**
2425 * Get the base type name of this array.
2426 *
2427 * @return "NULL"
2428 */
2429 @Override
2430 public String getBaseTypeName() {
2431 return "NULL";
2432 }
2433
2434 /**
2435 * INTERNAL
2436 */
2437 @Override
2438 public ResultSet getResultSet() throws SQLException {
2439 throw getUnsupportedException();
2440 }
2441
2442 /**
2443 * INTERNAL
2444 */
2445 @Override
2446 public ResultSet getResultSet(Map<String, Class<?>> map)
2447 throws SQLException {
2448 throw getUnsupportedException();
2449 }
2450
2451 /**
2452 * INTERNAL
2453 */
2454 @Override
2455 public ResultSet getResultSet(long index, int count)
2456 throws SQLException {
2457 throw getUnsupportedException();
2458 }
2459
2460 /**
2461 * INTERNAL
2462 */
2463 @Override
2464 public ResultSet getResultSet(long index, int count,
2465 Map<String, Class<?>> map) throws SQLException {
2466 throw getUnsupportedException();
2467 }
2468
2469 /**
2470 * INTERNAL
2471 */
2472 @Override
2473 public void free() {
2474 // nothing to do
2475 }
2476
2477 }
2478
2479 }