comparison src/main/java/org/monetdb/jdbc/MonetResultSet.java @ 774:e029af7551b7

Implemented ResultSet methods: <T> T getObject(int columnIndex, Class<T> type) <T> T getObject(String columnLabel, Class<T> type) They used to throw an SQLFeatureNotSupportedException.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 09 Aug 2023 22:13:52 +0200 (21 months ago)
parents 2bd1983f1c11
children 4c35009cd59c
comparison
equal deleted inserted replaced
773:2bd1983f1c11 774:e029af7551b7
3188 * @return an instance of type holding the column value 3188 * @return an instance of type holding the column value
3189 * @throws SQLException if conversion is not supported, type is 3189 * @throws SQLException if conversion is not supported, type is
3190 * null or another error occurs. The getCause() method of 3190 * null or another error occurs. The getCause() method of
3191 * the exception may provide a more detailed exception, for 3191 * the exception may provide a more detailed exception, for
3192 * example, if a conversion error occurs 3192 * example, if a conversion error occurs
3193 * @throws SQLFeatureNotSupportedException the JDBC driver does
3194 * not support this method
3195 */ 3193 */
3196 @Override 3194 @Override
3197 public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException { 3195 public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException {
3198 checkNotClosed(); 3196 checkNotClosed();
3199 if (type == null) 3197 if (type == null)
3200 throw new SQLException("type is null", "M1M05"); 3198 throw new SQLException("type is null", "M1M05");
3201 3199
3202 throw newSQLFeatureNotSupportedException("getObject(column, Class<T> type)"); 3200 final String val;
3201 try {
3202 val = tlp.values[columnIndex - 1];
3203 if (val == null) {
3204 lastReadWasNull = true;
3205 return null;
3206 }
3207 lastReadWasNull = false;
3208 } catch (IndexOutOfBoundsException e) {
3209 throw newSQLInvalidColumnIndexException(columnIndex);
3210 }
3211
3212 if (type == String.class) {
3213 return type.cast(val);
3214 }
3215 if (type == Integer.class) {
3216 return type.cast(Integer.valueOf(getInt(columnIndex)));
3217 }
3218 if (type == Long.class) {
3219 return type.cast(Long.valueOf(getLong(columnIndex)));
3220 }
3221 if (type == Short.class) {
3222 return type.cast(Short.valueOf(getShort(columnIndex)));
3223 }
3224 if (type == Double.class) {
3225 return type.cast(Double.valueOf(getDouble(columnIndex)));
3226 }
3227 if (type == Float.class) {
3228 return type.cast(Float.valueOf(getFloat(columnIndex)));
3229 }
3230 if (type == BigDecimal.class) {
3231 return type.cast(getBigDecimal(columnIndex));
3232 }
3233 if (type == Boolean.class) {
3234 return type.cast(Boolean.valueOf(getBoolean(columnIndex)));
3235 }
3236 if (type == byte[].class) {
3237 return type.cast(getBytes(columnIndex));
3238 }
3239 if (type == Blob.class || type == MonetBlob.class) {
3240 return type.cast(getBlob(columnIndex));
3241 }
3242 if (type == Clob.class || type == MonetClob.class) {
3243 return type.cast(getClob(columnIndex));
3244 }
3245 if (type == URL.class) {
3246 return type.cast(getURL(columnIndex));
3247 }
3248 if (type == Date.class) {
3249 return type.cast(getDate(columnIndex, null));
3250 }
3251 if (type == Time.class) {
3252 return type.cast(getTime(columnIndex, null));
3253 }
3254 if (type == Timestamp.class) {
3255 return type.cast(getTimestamp(columnIndex, null));
3256 }
3257 if (type == java.util.Date.class) {
3258 final Timestamp timestamp = getTimestamp(columnIndex, null);
3259 return type.cast(new java.util.Date(timestamp.getTime()));
3260 }
3261 if (type == Calendar.class) {
3262 final Calendar cal = Calendar.getInstance();
3263 getJavaDate(cal, columnIndex, Types.TIMESTAMP);
3264 return type.cast(cal);
3265 }
3266 if (type == java.util.UUID.class) {
3267 try {
3268 return type.cast(java.util.UUID.fromString(val));
3269 } catch (IllegalArgumentException exc) {
3270 throw new SQLException("conversion to java.util.UUID object failed: " + exc.getMessage(), "M1M05");
3271 }
3272 }
3273 if (type == java.net.InetAddress.class) {
3274 final int slash = val.indexOf('/');
3275 try {
3276 return type.cast(java.net.InetAddress.getByName(slash < 0 ? val : val.substring(0, slash)));
3277 } catch (java.net.UnknownHostException exc) {
3278 throw new SQLException("conversion to java.net.InetAddress object failed: " + exc.getMessage(), "M1M05");
3279 }
3280 }
3281
3282 throw new SQLException("conversion to '" + type.getName() + "' is not supported", "M1M05");
3203 } 3283 }
3204 3284
3205 /** 3285 /**
3206 * Retrieves the value of the designated column in the current row 3286 * Retrieves the value of the designated column in the current row
3207 * of this ResultSet object and will convert from the SQL type of 3287 * of this ResultSet object and will convert from the SQL type of
3217 * @return an instance of type holding the column value 3297 * @return an instance of type holding the column value
3218 * @throws SQLException if conversion is not supported, type is 3298 * @throws SQLException if conversion is not supported, type is
3219 * null or another error occurs. The getCause() method of 3299 * null or another error occurs. The getCause() method of
3220 * the exception may provide a more detailed exception, for 3300 * the exception may provide a more detailed exception, for
3221 * example, if a conversion error occurs 3301 * example, if a conversion error occurs
3222 * @throws SQLFeatureNotSupportedException the JDBC driver does
3223 * not support this method
3224 */ 3302 */
3225 @Override 3303 @Override
3226 public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException { 3304 public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException {
3227 return getObject(findColumn(columnLabel), type); 3305 return getObject(findColumn(columnLabel), type);
3228 } 3306 }