Debian Codegraph @

src/main/org/h2/value/ValueToObjectConverter.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.value;
7
8 import java.io.BufferedReader;
9 import java.io.InputStream;
10 import java.io.Reader;
11 import java.math.BigDecimal;
12 import java.math.BigInteger;
13 import java.sql.Array;
14 import java.sql.Blob;
15 import java.sql.Clob;
16 import java.sql.ResultSet;
17 import java.sql.ResultSetMetaData;
18 import java.sql.SQLException;
19 import java.sql.SQLXML;
20 import java.time.Duration;
21 import java.time.Instant;
22 import java.time.LocalDate;
23 import java.time.LocalDateTime;
24 import java.time.LocalTime;
25 import java.time.OffsetDateTime;
26 import java.time.OffsetTime;
27 import java.time.Period;
28 import java.time.ZonedDateTime;
29 import java.util.Iterator;
30 import java.util.LinkedHashMap;
31 import java.util.Map.Entry;
32 import java.util.UUID;
33
34 import org.h2.api.ErrorCode;
35 import org.h2.api.Interval;
36 import org.h2.engine.Session;
37 import org.h2.jdbc.JdbcArray;
38 import org.h2.jdbc.JdbcBlob;
39 import org.h2.jdbc.JdbcClob;
40 import org.h2.jdbc.JdbcConnection;
41 import org.h2.jdbc.JdbcLob;
42 import org.h2.jdbc.JdbcResultSet;
43 import org.h2.jdbc.JdbcSQLXML;
44 import org.h2.message.DbException;
45 import org.h2.message.TraceObject;
46 import org.h2.util.JSR310Utils;
47 import org.h2.util.JdbcUtils;
48 import org.h2.util.LegacyDateTimeUtils;
49
50 /**
51 * Data type conversion methods between values and Java objects.
52 */
53 public final class ValueToObjectConverter extends TraceObject {
54
55 /**
56 * The Geometry class. This object is null if the JTS jar file is not in the
57 * classpath.
58 */
59 public static final Class<?> GEOMETRY_CLASS;
60
61 private static final String GEOMETRY_CLASS_NAME = "org.locationtech.jts.geom.Geometry";
62
63 static {
64 Class<?> g;
65 try {
66 g = JdbcUtils.loadUserClass(GEOMETRY_CLASS_NAME);
67 } catch (Exception e) {
68 g = null;
69 }
70 GEOMETRY_CLASS = g;
71 }
72
73 /**
74 * Convert a Java object to a value.
75 *
76 * @param session
77 * the session
78 * @param x
79 * the value
80 * @param type
81 * the suggested value type, or {@code Value#UNKNOWN}
82 * @return the value
83 */
84 public static Value objectToValue(Session session, Object x, int type) {
85 if (x == null) {
86 return ValueNull.INSTANCE;
87 } else if (type == Value.JAVA_OBJECT) {
88 return ValueJavaObject.getNoCopy(JdbcUtils.serialize(x, session.getJavaObjectSerializer()));
89 } else if (x instanceof Value) {
90 Value v = (Value) x;
91 if (v instanceof ValueLob) {
92 session.addTemporaryLob((ValueLob) v);
93 }
94 return v;
95 }
96 Class<?> clazz = x.getClass();
97 if (clazz == String.class) {
98 return ValueVarchar.get((String) x, session);
99 } else if (clazz == Long.class) {
100 return ValueBigint.get((Long) x);
101 } else if (clazz == Integer.class) {
102 return ValueInteger.get((Integer) x);
103 } else if (clazz == Boolean.class) {
104 return ValueBoolean.get((Boolean) x);
105 } else if (clazz == Byte.class) {
106 return ValueTinyint.get((Byte) x);
107 } else if (clazz == Short.class) {
108 return ValueSmallint.get((Short) x);
109 } else if (clazz == Float.class) {
110 return ValueReal.get((Float) x);
111 } else if (clazz == Double.class) {
112 return ValueDouble.get((Double) x);
113 } else if (clazz == byte[].class) {
114 return ValueVarbinary.get((byte[]) x);
115 } else if (clazz == UUID.class) {
116 return ValueUuid.get((UUID) x);
117 } else if (clazz == Character.class) {
118 return ValueChar.get(((Character) x).toString());
119 } else if (clazz == LocalDate.class) {
120 return JSR310Utils.localDateToValue((LocalDate) x);
121 } else if (clazz == LocalTime.class) {
122 return JSR310Utils.localTimeToValue((LocalTime) x);
123 } else if (clazz == LocalDateTime.class) {
124 return JSR310Utils.localDateTimeToValue((LocalDateTime) x);
125 } else if (clazz == Instant.class) {
126 return JSR310Utils.instantToValue((Instant) x);
127 } else if (clazz == OffsetTime.class) {
128 return JSR310Utils.offsetTimeToValue((OffsetTime) x);
129 } else if (clazz == OffsetDateTime.class) {
130 return JSR310Utils.offsetDateTimeToValue((OffsetDateTime) x);
131 } else if (clazz == ZonedDateTime.class) {
132 return JSR310Utils.zonedDateTimeToValue((ZonedDateTime) x);
133 } else if (clazz == Interval.class) {
134 Interval i = (Interval) x;
135 return ValueInterval.from(i.getQualifier(), i.isNegative(), i.getLeading(), i.getRemaining());
136 } else if (clazz == Period.class) {
137 return JSR310Utils.periodToValue((Period) x);
138 } else if (clazz == Duration.class) {
139 return JSR310Utils.durationToValue((Duration) x);
140 }
141 if (x instanceof Object[]) {
142 return arrayToValue(session, x);
143 } else if (GEOMETRY_CLASS != null && GEOMETRY_CLASS.isAssignableFrom(clazz)) {
144 return ValueGeometry.getFromGeometry(x);
145 } else if (x instanceof BigInteger) {
146 return ValueNumeric.get((BigInteger) x);
147 } else if (x instanceof BigDecimal) {
148 return ValueNumeric.getAnyScale((BigDecimal) x);
149 } else {
150 return otherToValue(session, x);
151 }
152 }
153
154 private static Value otherToValue(Session session, Object x) {
155 if (x instanceof Array) {
156 Array array = (Array) x;
157 try {
158 return arrayToValue(session, array.getArray());
159 } catch (SQLException e) {
160 throw DbException.convert(e);
161 }
162 } else if (x instanceof ResultSet) {
163 return resultSetToValue(session, (ResultSet) x);
164 }
165 ValueLob lob;
166 if (x instanceof Reader) {
167 Reader r = (Reader) x;
168 if (!(r instanceof BufferedReader)) {
169 r = new BufferedReader(r);
170 }
171 lob = session.getDataHandler().getLobStorage().createClob(r, -1);
172 } else if (x instanceof Clob) {
173 try {
174 Clob clob = (Clob) x;
175 Reader r = new BufferedReader(clob.getCharacterStream());
176 lob = session.getDataHandler().getLobStorage().createClob(r, clob.length());
177 } catch (SQLException e) {
178 throw DbException.convert(e);
179 }
180 } else if (x instanceof InputStream) {
181 lob = session.getDataHandler().getLobStorage().createBlob((InputStream) x, -1);
182 } else if (x instanceof Blob) {
183 try {
184 Blob blob = (Blob) x;
185 lob = session.getDataHandler().getLobStorage().createBlob(blob.getBinaryStream(), blob.length());
186 } catch (SQLException e) {
187 throw DbException.convert(e);
188 }
189 } else if (x instanceof SQLXML) {
190 try {
191 lob = session.getDataHandler().getLobStorage()
192 .createClob(new BufferedReader(((SQLXML) x).getCharacterStream()), -1);
193 } catch (SQLException e) {
194 throw DbException.convert(e);
195 }
196 } else {
197 Value v = LegacyDateTimeUtils.legacyObjectToValue(session, x);
198 if (v != null) {
199 return v;
200 }
201 return ValueJavaObject.getNoCopy(JdbcUtils.serialize(x, session.getJavaObjectSerializer()));
202 }
203 return session.addTemporaryLob(lob);
204 }
205
206 private static Value arrayToValue(Session session, Object x) {
207 // (a.getClass().isArray());
208 // (a.getClass().getComponentType().isPrimitive());
209 Object[] o = (Object[]) x;
210 int len = o.length;
211 Value[] v = new Value[len];
212 for (int i = 0; i < len; i++) {
213 v[i] = objectToValue(session, o[i], Value.UNKNOWN);
214 }
215 return ValueArray.get(v, session);
216 }
217
218 static Value resultSetToValue(Session session, ResultSet rs) {
219 try {
220 ResultSetMetaData meta = rs.getMetaData();
221 int columnCount = meta.getColumnCount();
222 LinkedHashMap<String, TypeInfo> columns = readResultSetMeta(session, meta, columnCount);
223 if (!rs.next()) {
224 throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, "Empty ResultSet to ROW value");
225 }
226 Value[] list = new Value[columnCount];
227 Iterator<Entry<String, TypeInfo>> iterator = columns.entrySet().iterator();
228 for (int j = 0; j < columnCount; j++) {
229 list[j] = ValueToObjectConverter.objectToValue(session, rs.getObject(j + 1),
230 iterator.next().getValue().getValueType());
231 }
232 if (rs.next()) {
233 throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, "Multi-row ResultSet to ROW value");
234 }
235 return ValueRow.get(new ExtTypeInfoRow(columns), list);
236 } catch (SQLException e) {
237 throw DbException.convert(e);
238 }
239 }
240
241 private static LinkedHashMap<String, TypeInfo> readResultSetMeta(Session session, ResultSetMetaData meta,
242 int columnCount) throws SQLException {
243 LinkedHashMap<String, TypeInfo> columns = new LinkedHashMap<>();
244 for (int i = 0; i < columnCount; i++) {
245 String alias = meta.getColumnLabel(i + 1);
246 String columnTypeName = meta.getColumnTypeName(i + 1);
247 int columnType = DataType.convertSQLTypeToValueType(meta.getColumnType(i + 1), columnTypeName);
248 int precision = meta.getPrecision(i + 1);
249 int scale = meta.getScale(i + 1);
250 TypeInfo typeInfo;
251 if (columnType == Value.ARRAY && columnTypeName.endsWith(" ARRAY")) {
252 typeInfo = TypeInfo
253 .getTypeInfo(Value.ARRAY, -1L, 0,
254 TypeInfo.getTypeInfo(DataType.getTypeByName(
255 columnTypeName.substring(0, columnTypeName.length() - 6),
256 session.getMode()).type));
257 } else {
258 typeInfo = TypeInfo.getTypeInfo(columnType, precision, scale, null);
259 }
260 columns.put(alias, typeInfo);
261 }
262 return columns;
263 }
264
265 /**
266 * Converts the specified value to an object of the specified type.
267 *
268 * @param <T>
269 * the type
270 * @param type
271 * the class
272 * @param value
273 * the value
274 * @param conn
275 * the connection
276 * @return the object of the specified class representing the specified
277 * value, or {@code null}
278 */
279 @SuppressWarnings("unchecked")
280 public static <T> T valueToObject(Class<T> type, Value value, JdbcConnection conn) {
281 if (value == ValueNull.INSTANCE) {
282 return null;
283 } else if (type == BigDecimal.class) {
284 return (T) value.getBigDecimal();
285 } else if (type == BigInteger.class) {
286 return (T) value.getBigDecimal().toBigInteger();
287 } else if (type == String.class) {
288 return (T) value.getString();
289 } else if (type == Boolean.class) {
290 return (T) (Boolean) value.getBoolean();
291 } else if (type == Byte.class) {
292 return (T) (Byte) value.getByte();
293 } else if (type == Short.class) {
294 return (T) (Short) value.getShort();
295 } else if (type == Integer.class) {
296 return (T) (Integer) value.getInt();
297 } else if (type == Long.class) {
298 return (T) (Long) value.getLong();
299 } else if (type == Float.class) {
300 return (T) (Float) value.getFloat();
301 } else if (type == Double.class) {
302 return (T) (Double) value.getDouble();
303 } else if (type == UUID.class) {
304 return (T) value.convertToUuid().getUuid();
305 } else if (type == byte[].class) {
306 return (T) value.getBytes();
307 } else if (type == Character.class) {
308 String s = value.getString();
309 return (T) (Character) (s.isEmpty() ? ' ' : s.charAt(0));
310 } else if (type == Interval.class) {
311 if (!(value instanceof ValueInterval)) {
312 value = value.convertTo(TypeInfo.TYPE_INTERVAL_DAY_TO_SECOND);
313 }
314 ValueInterval v = (ValueInterval) value;
315 return (T) new Interval(v.getQualifier(), false, v.getLeading(), v.getRemaining());
316 } else if (type == LocalDate.class) {
317 return (T) JSR310Utils.valueToLocalDate(value, conn);
318 } else if (type == LocalTime.class) {
319 return (T) JSR310Utils.valueToLocalTime(value, conn);
320 } else if (type == LocalDateTime.class) {
321 return (T) JSR310Utils.valueToLocalDateTime(value, conn);
322 } else if (type == OffsetTime.class) {
323 return (T) JSR310Utils.valueToOffsetTime(value, conn);
324 } else if (type == OffsetDateTime.class) {
325 return (T) JSR310Utils.valueToOffsetDateTime(value, conn);
326 } else if (type == ZonedDateTime.class) {
327 return (T) JSR310Utils.valueToZonedDateTime(value, conn);
328 } else if (type == Instant.class) {
329 return (T) JSR310Utils.valueToInstant(value, conn);
330 } else if (type == Period.class) {
331 return (T) JSR310Utils.valueToPeriod(value);
332 } else if (type == Duration.class) {
333 return (T) JSR310Utils.valueToDuration(value);
334 } else if (type.isArray()) {
335 return (T) valueToArray(type, value, conn);
336 } else if (GEOMETRY_CLASS != null && GEOMETRY_CLASS.isAssignableFrom(type)) {
337 return (T) value.convertToGeometry(null).getGeometry();
338 } else {
339 return (T) valueToOther(type, value, conn);
340 }
341 }
342
343 private static Object valueToArray(Class<?> type, Value value, JdbcConnection conn) {
344 Value[] array = ((ValueArray) value).getList();
345 Class<?> componentType = type.getComponentType();
346 int length = array.length;
347 Object[] objArray = (Object[]) java.lang.reflect.Array.newInstance(componentType, length);
348 for (int i = 0; i < length; i++) {
349 objArray[i] = valueToObject(componentType, array[i], conn);
350 }
351 return objArray;
352 }
353
354 private static Object valueToOther(Class<?> type, Value value, JdbcConnection conn) {
355 if (type == Object.class) {
356 return JdbcUtils.deserialize(
357 value.convertToJavaObject(TypeInfo.TYPE_JAVA_OBJECT, Value.CONVERT_TO, null).getBytesNoCopy(),
358 conn.getJavaObjectSerializer());
359 } else if (type == InputStream.class) {
360 return value.getInputStream();
361 } else if (type == Reader.class) {
362 return value.getReader();
363 } else if (type == java.sql.Array.class) {
364 return new JdbcArray(conn, value, getNextId(TraceObject.ARRAY));
365 } else if (type == Blob.class) {
366 return new JdbcBlob(conn, value, JdbcLob.State.WITH_VALUE, getNextId(TraceObject.BLOB));
367 } else if (type == Clob.class) {
368 return new JdbcClob(conn, value, JdbcLob.State.WITH_VALUE, getNextId(TraceObject.CLOB));
369 } else if (type == SQLXML.class) {
370 return new JdbcSQLXML(conn, value, JdbcLob.State.WITH_VALUE, getNextId(TraceObject.SQLXML));
371 } else if (type == ResultSet.class) {
372 return new JdbcResultSet(conn, null, null, value.convertToAnyRow().getResult(),
373 getNextId(TraceObject.RESULT_SET), true, false, false);
374 } else {
375 Object obj = LegacyDateTimeUtils.valueToLegacyType(type, value, conn);
376 if (obj != null) {
377 return obj;
378 }
379 if (value.getValueType() == Value.JAVA_OBJECT) {
380 obj = JdbcUtils.deserialize(value.getBytesNoCopy(), conn.getJavaObjectSerializer());
381 if (type.isAssignableFrom(obj.getClass())) {
382 return obj;
383 }
384 }
385 throw DbException.getUnsupportedException("converting to class " + type.getName());
386 }
387 }
388
389 /**
390 * Get the name of the Java class for the given value type.
391 *
392 * @param type
393 * the value type
394 * @param forJdbc
395 * if {@code true} get class for JDBC layer, if {@code false} get
396 * class for Java functions API
397 * @return the class
398 */
399 public static Class<?> getDefaultClass(int type, boolean forJdbc) {
400 switch (type) {
401 case Value.NULL:
402 return Void.class;
403 case Value.CHAR:
404 case Value.VARCHAR:
405 case Value.VARCHAR_IGNORECASE:
406 case Value.ENUM:
407 return String.class;
408 case Value.CLOB:
409 return Clob.class;
410 case Value.BINARY:
411 case Value.VARBINARY:
412 case Value.JSON:
413 return byte[].class;
414 case Value.BLOB:
415 return Blob.class;
416 case Value.BOOLEAN:
417 return Boolean.class;
418 case Value.TINYINT:
419 if (forJdbc) {
420 return Integer.class;
421 }
422 return Byte.class;
423 case Value.SMALLINT:
424 if (forJdbc) {
425 return Integer.class;
426 }
427 return Short.class;
428 case Value.INTEGER:
429 return Integer.class;
430 case Value.BIGINT:
431 return Long.class;
432 case Value.NUMERIC:
433 case Value.DECFLOAT:
434 return BigDecimal.class;
435 case Value.REAL:
436 return Float.class;
437 case Value.DOUBLE:
438 return Double.class;
439 case Value.DATE:
440 return forJdbc ? java.sql.Date.class : LocalDate.class;
441 case Value.TIME:
442 return forJdbc ? java.sql.Time.class : LocalTime.class;
443 case Value.TIME_TZ:
444 return OffsetTime.class;
445 case Value.TIMESTAMP:
446 return forJdbc ? java.sql.Timestamp.class : LocalDateTime.class;
447 case Value.TIMESTAMP_TZ:
448 return OffsetDateTime.class;
449 case Value.INTERVAL_YEAR:
450 case Value.INTERVAL_MONTH:
451 case Value.INTERVAL_DAY:
452 case Value.INTERVAL_HOUR:
453 case Value.INTERVAL_MINUTE:
454 case Value.INTERVAL_SECOND:
455 case Value.INTERVAL_YEAR_TO_MONTH:
456 case Value.INTERVAL_DAY_TO_HOUR:
457 case Value.INTERVAL_DAY_TO_MINUTE:
458 case Value.INTERVAL_DAY_TO_SECOND:
459 case Value.INTERVAL_HOUR_TO_MINUTE:
460 case Value.INTERVAL_HOUR_TO_SECOND:
461 case Value.INTERVAL_MINUTE_TO_SECOND:
462 return Interval.class;
463 case Value.JAVA_OBJECT:
464 return forJdbc ? Object.class : byte[].class;
465 case Value.GEOMETRY: {
466 Class<?> clazz = GEOMETRY_CLASS;
467 return clazz != null ? clazz : String.class;
468 }
469 case Value.UUID:
470 return UUID.class;
471 case Value.ARRAY:
472 if (forJdbc) {
473 return Array.class;
474 }
475 return Object[].class;
476 case Value.ROW:
477 if (forJdbc) {
478 return ResultSet.class;
479 }
480 return Object[].class;
481 default:
482 throw DbException.getUnsupportedException("data type " + type);
483 }
484 }
485
486 /**
487 * Converts the specified value to the default Java object for its type.
488 *
489 * @param value
490 * the value
491 * @param conn
492 * the connection
493 * @param forJdbc
494 * if {@code true} perform conversion for JDBC layer, if
495 * {@code false} perform conversion for Java functions API
496 * @return the object
497 */
498 public static Object valueToDefaultObject(Value value, JdbcConnection conn, boolean forJdbc) {
499 switch (value.getValueType()) {
500 case Value.NULL:
501 return null;
502 case Value.CHAR:
503 case Value.VARCHAR:
504 case Value.VARCHAR_IGNORECASE:
505 case Value.ENUM:
506 return value.getString();
507 case Value.CLOB:
508 return new JdbcClob(conn, value, JdbcLob.State.WITH_VALUE, getNextId(TraceObject.CLOB));
509 case Value.BINARY:
510 case Value.VARBINARY:
511 case Value.JSON:
512 return value.getBytes();
513 case Value.BLOB:
514 return new JdbcBlob(conn, value, JdbcLob.State.WITH_VALUE, getNextId(TraceObject.BLOB));
515 case Value.BOOLEAN:
516 return value.getBoolean();
517 case Value.TINYINT:
518 if (forJdbc) {
519 return value.getInt();
520 }
521 return value.getByte();
522 case Value.SMALLINT:
523 if (forJdbc) {
524 return value.getInt();
525 }
526 return value.getShort();
527 case Value.INTEGER:
528 return value.getInt();
529 case Value.BIGINT:
530 return value.getLong();
531 case Value.NUMERIC:
532 case Value.DECFLOAT:
533 return value.getBigDecimal();
534 case Value.REAL:
535 return value.getFloat();
536 case Value.DOUBLE:
537 return value.getDouble();
538 case Value.DATE:
539 return forJdbc ? LegacyDateTimeUtils.toDate(conn, null, value) : JSR310Utils.valueToLocalDate(value, null);
540 case Value.TIME:
541 return forJdbc ? LegacyDateTimeUtils.toTime(conn, null, value) : JSR310Utils.valueToLocalTime(value, null);
542 case Value.TIME_TZ:
543 return JSR310Utils.valueToOffsetTime(value, null);
544 case Value.TIMESTAMP:
545 return forJdbc ? LegacyDateTimeUtils.toTimestamp(conn, null, value)
546 : JSR310Utils.valueToLocalDateTime(value, null);
547 case Value.TIMESTAMP_TZ:
548 return JSR310Utils.valueToOffsetDateTime(value, null);
549 case Value.INTERVAL_YEAR:
550 case Value.INTERVAL_MONTH:
551 case Value.INTERVAL_DAY:
552 case Value.INTERVAL_HOUR:
553 case Value.INTERVAL_MINUTE:
554 case Value.INTERVAL_SECOND:
555 case Value.INTERVAL_YEAR_TO_MONTH:
556 case Value.INTERVAL_DAY_TO_HOUR:
557 case Value.INTERVAL_DAY_TO_MINUTE:
558 case Value.INTERVAL_DAY_TO_SECOND:
559 case Value.INTERVAL_HOUR_TO_MINUTE:
560 case Value.INTERVAL_HOUR_TO_SECOND:
561 case Value.INTERVAL_MINUTE_TO_SECOND:
562 return ((ValueInterval) value).getInterval();
563 case Value.JAVA_OBJECT:
564 return forJdbc ? JdbcUtils.deserialize(value.getBytesNoCopy(), conn.getJavaObjectSerializer())
565 : value.getBytes();
566 case Value.GEOMETRY:
567 return GEOMETRY_CLASS != null ? ((ValueGeometry) value).getGeometry() : value.getString();
568 case Value.UUID:
569 return ((ValueUuid) value).getUuid();
570 case Value.ARRAY:
571 if (forJdbc) {
572 return new JdbcArray(conn, value, getNextId(TraceObject.ARRAY));
573 }
574 return valueToDefaultArray(value, conn, forJdbc);
575 case Value.ROW:
576 if (forJdbc) {
577 return new JdbcResultSet(conn, null, null, ((ValueRow) value).getResult(),
578 getNextId(TraceObject.RESULT_SET), true, false, false);
579 }
580 return valueToDefaultArray(value, conn, forJdbc);
581 default:
582 throw DbException.getUnsupportedException("data type " + value.getValueType());
583 }
584 }
585
586 /**
587 * Converts the specified array value to array of default Java objects for
588 * its type.
589 *
590 * @param value
591 * the array value
592 * @param conn
593 * the connection
594 * @param forJdbc
595 * if {@code true} perform conversion for JDBC layer, if
596 * {@code false} perform conversion for Java functions API
597 * @return the object
598 */
599 public static Object valueToDefaultArray(Value value, JdbcConnection conn, boolean forJdbc) {
600 Value[] values = ((ValueCollectionBase) value).getList();
601 int len = values.length;
602 Object[] list = new Object[len];
603 for (int i = 0; i < len; i++) {
604 list[i] = valueToDefaultObject(values[i], conn, forJdbc);
605 }
606 return list;
607 }
608
609 /**
610 * Read a value from the given result set.
611 *
612 * @param session
613 * the session
614 * @param rs
615 * the result set
616 * @param columnIndex
617 * the column index (1-based)
618 * @return the value
619 */
620 public static Value readValue(Session session, JdbcResultSet rs, int columnIndex) {
621 Value value = rs.getInternal(columnIndex);
622 switch (value.getValueType()) {
623 case Value.CLOB:
624 value = session.addTemporaryLob(
625 session.getDataHandler().getLobStorage().createClob(new BufferedReader(value.getReader()), -1));
626 break;
627 case Value.BLOB:
628 value = session
629 .addTemporaryLob(session.getDataHandler().getLobStorage().createBlob(value.getInputStream(), -1));
630 }
631 return value;
632 }
633
634 private ValueToObjectConverter() {
635 }
636
637 }