use of java.sql.Struct in project calcite-avatica by apache.
the class JdbcResultSet method getValue.
private static Object getValue(ResultSet resultSet, int type, int j, Calendar calendar) throws SQLException {
switch(type) {
case Types.BIGINT:
final long aLong = resultSet.getLong(j + 1);
return aLong == 0 && resultSet.wasNull() ? null : aLong;
case Types.INTEGER:
final int anInt = resultSet.getInt(j + 1);
return anInt == 0 && resultSet.wasNull() ? null : anInt;
case Types.SMALLINT:
final short aShort = resultSet.getShort(j + 1);
return aShort == 0 && resultSet.wasNull() ? null : aShort;
case Types.TINYINT:
final byte aByte = resultSet.getByte(j + 1);
return aByte == 0 && resultSet.wasNull() ? null : aByte;
case Types.DOUBLE:
case Types.FLOAT:
final double aDouble = resultSet.getDouble(j + 1);
return aDouble == 0D && resultSet.wasNull() ? null : aDouble;
case Types.REAL:
final float aFloat = resultSet.getFloat(j + 1);
return aFloat == 0D && resultSet.wasNull() ? null : aFloat;
case Types.DATE:
final Date aDate = resultSet.getDate(j + 1, calendar);
return aDate == null ? null : (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY);
case Types.TIME:
final Time aTime = resultSet.getTime(j + 1, calendar);
return aTime == null ? null : (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY);
case Types.TIMESTAMP:
final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar);
return aTimestamp == null ? null : aTimestamp.getTime();
case Types.ARRAY:
final Array array = resultSet.getArray(j + 1);
if (null == array) {
return null;
}
try {
// Recursively extracts an Array using its ResultSet-representation
return extractUsingResultSet(array, calendar);
} catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
// assumes a non-nested array (depends on the db if that's a valid assumption)
return extractUsingArray(array, calendar);
}
case Types.STRUCT:
Struct struct = resultSet.getObject(j + 1, Struct.class);
Object[] attrs = struct.getAttributes();
List<Object> list = new ArrayList<>(attrs.length);
for (Object o : attrs) {
list.add(o);
}
return list;
default:
return resultSet.getObject(j + 1);
}
}
Aggregations