/** * Static factory method to create a new {@code SingleColumnRowMapper} (with the required type specified only once). * * @param requiredType the type that each result object is expected to match */ public static <T> SingleColumnRowMapper<T> newInstance(Class<T> requiredType) { return new SingleColumnRowMapper<>(requiredType); } }
/** * Create a new RowMapper for reading result objects from a single column. * * @param requiredType the type that each result object is expected to match * @return the RowMapper to use * @see SingleColumnRowMapper */ protected <T> RowMapper<T> getSingleColumnRowMapper(Class<T> requiredType) { return SingleColumnRowMapper.newInstance(requiredType); }
/** * Create a new {@code SingleColumnRowMapper}. * <p> * Consider using the {@link #newInstance} factory method instead, which allows for specifying the required type once * only. * * @param requiredType the type that each result object is expected to match */ public SingleColumnRowMapper(Class<T> requiredType) { setRequiredType(requiredType); }
Object result = getColumnValue(row, 0, this.requiredType); return (T) convertValueToRequiredType(result, this.requiredType); } catch (IllegalArgumentException ex) { throw new TypeMismatchDataAccessException(
/** * Retrieve a CQL object value for the specified column. * <p> * The default implementation calls {@link RowUtils#getRowValue(Row, int, Class)}. If no required type has been * specified, this method delegates to {@code getColumnValue(rs, index)}, which basically calls * {@link Row#getObject(int)} but applies some additional default conversion to appropriate value types. * * @param row is the {@link Row} holding the data, must not be {@literal null}. * @param index is the column index * @param requiredType the type that each result object is expected to match (or {@literal null} if none specified). * @return the Object value. * @throws DriverException in case of extraction failure * @see RowUtils#getRowValue(Row, int, Class) * @see #getColumnValue(Row, int) */ @Nullable protected Object getColumnValue(Row row, int index, @Nullable Class<?> requiredType) throws DriverException { if (requiredType != null) { return RowUtils.getRowValue(row, index, requiredType); } else { // No required type specified -> perform default extraction. return getColumnValue(row, index); } }
/** * Create a new RowMapper for reading result objects from a single column. * * @param requiredType the type that each result object is expected to match * @return the RowMapper to use * @see SingleColumnRowMapper */ protected <T> RowMapper<T> newSingleColumnRowMapper(Class<T> requiredType) { return SingleColumnRowMapper.newInstance(requiredType); }