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