RowMapper implementation that converts a single column into a single
result value per row. Expects to operate on a java.sql.ResultSet
that just contains a single column.
The type of the result value for each row can be specified. The value
for the single column will be extracted from the ResultSet
and converted into the specified target type.
JdbcTemplate#queryForList(String, Class), JdbcTemplate#queryForObject(String, Class)
| Modifier and Type | Field and Description |
|---|---|
| private ConversionService | |
| private Class |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SingleColumnRowMapper(Class<T>
the type that each result object is expected to match requiredType)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| protected Object | Returns: the converted valuethe column value as extracted from value, Class<?> getColumnValue()
(never null)the type that each result object is expected to match
(never requiredType)null)Convert the given column value to the specified required type. |
| protected Object | Returns: the Object valueis the ResultSet holding the data rs, int is the column index index, Class<?> the type that each result object is expected to match
(or requiredType)null if none specified)Retrieve a JDBC object value for the specified column. |
| protected Object | Returns: the Object valueis the ResultSet holding the data rs, int is the column index index)Retrieve a JDBC object value for the specified column, using the most appropriate value type. |
| public T | mapRow(ResultSet
the rs, int ResultSet to map (pre-initialized for the current row)the number of the current row rowNum)Implements org. |
| public static <T> SingleColumnRowMapper | newInstance(Class<T>
the type that each result object is expected to match requiredType)Static factory method to create a new |
| public static <T> SingleColumnRowMapper | newInstance(Class<T>
the type that each result object is expected to match requiredType, ConversionService the conversionService)ConversionService for converting a
fetched value, or null for noneStatic factory method to create a new |
| public void | setConversionService(ConversionService conversionService)
Set a |
| public void |
| conversionService | back to summary |
|---|---|
| private ConversionService conversionService
| |
| requiredType | back to summary |
|---|---|
| private Class<?> requiredType
| |
| SingleColumnRowMapper | back to summary |
|---|---|
| public SingleColumnRowMapper() Create a new
| |
| SingleColumnRowMapper | back to summary |
|---|---|
| public SingleColumnRowMapper(Class<T> requiredType) Create a new
| |
| convertValueToRequiredType | back to summary |
|---|---|
| protected Object convertValueToRequiredType(Object value, Class<?> requiredType) Convert the given column value to the specified required type. Only called if the extracted column value does not match already. If the required type is String, the value will simply get stringified
via
| |
| getColumnValue | back to summary |
|---|---|
| protected Object getColumnValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException Retrieve a JDBC object value for the specified column. The default implementation calls
| |
| getColumnValue | back to summary |
|---|---|
| protected Object getColumnValue(ResultSet rs, int index) throws SQLException Retrieve a JDBC object value for the specified column, using the most appropriate value type. Called if no required type has been specified. The default implementation delegates to
| |
| mapRow | back to summary |
|---|---|
| public T mapRow(ResultSet rs, int rowNum) throws SQLException Implements org. Extract a value for the single column in the current row. Validates that there is only one column selected,
then delegates to
| |
| newInstance | back to summary |
|---|---|
| public static <T> SingleColumnRowMapper Static factory method to create a new
| |
| newInstance | back to summary |
|---|---|
| public static <T> SingleColumnRowMapper Static factory method to create a new
| |
| setConversionService | back to summary |
|---|---|
| public void setConversionService(ConversionService conversionService) Set a Default is the
| |
| setRequiredType | back to summary |
|---|---|
| public void setRequiredType(Class<T> requiredType) Set the type that each result object is expected to match. If not specified, the column value will be exposed as returned by the JDBC driver. | |