public class SingleColumnRowMapper<T> extends Object implements RowMapper<T>
RowMapper implementation that converts a single column into a single result value per row. Expects to operate
on a Row 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 a
Row and converted into the specified target type.
AsyncCqlTemplate.queryForList(String, Class),
AsyncCqlTemplate.queryForObject(String, Class),
CqlTemplate.queryForList(String, Class),
CqlTemplate.queryForObject(String, Class),
ReactiveCqlTemplate.queryForFlux(String, Class),
ReactiveCqlTemplate.queryForObject(String, Class)| Constructor and Description |
|---|
SingleColumnRowMapper()
Create a new
SingleColumnRowMapper for bean-style configuration. |
SingleColumnRowMapper(Class<T> requiredType)
Create a new
SingleColumnRowMapper. |
| Modifier and Type | Method and Description |
|---|---|
protected Object |
convertValueToRequiredType(Object value,
Class<?> requiredType)
Convert the given column value to the specified required type.
|
protected Object |
getColumnValue(com.datastax.driver.core.Row row,
int index)
Retrieve a object value for the specified column, using the most appropriate value type.
|
protected Object |
getColumnValue(com.datastax.driver.core.Row row,
int index,
Class<?> requiredType)
Retrieve a CQL object value for the specified column.
|
T |
mapRow(com.datastax.driver.core.Row row,
int rowNum)
Extract a value for the single column in the current row.
|
static <T> SingleColumnRowMapper<T> |
newInstance(Class<T> requiredType)
Static factory method to create a new
SingleColumnRowMapper (with the required type specified only once). |
void |
setRequiredType(Class<T> requiredType)
Set the type that each result object is expected to match.
|
public SingleColumnRowMapper()
SingleColumnRowMapper for bean-style configuration.setRequiredType(java.lang.Class<T>)public SingleColumnRowMapper(Class<T> requiredType)
SingleColumnRowMapper.
Consider using the newInstance(java.lang.Class<T>) factory method instead, which allows for specifying the required type once
only.
requiredType - the type that each result object is expected to matchpublic void setRequiredType(Class<T> requiredType)
If not specified, the column value will be exposed as returned by the Row.
public T mapRow(com.datastax.driver.core.Row row, int rowNum) throws com.datastax.driver.core.exceptions.DriverException
Validates that there is only one column selected, then delegates to getColumnValue() and also
convertValueToRequiredType, if necessary.
mapRow in interface RowMapper<T>row - the Row to map, must not be null.rowNum - the number of the current row.com.datastax.driver.core.exceptions.DriverException - if a DriverException is encountered getting column values (that is, there's no need
to catch DriverException)ColumnDefinitions.size(),
getColumnValue(Row, int, Class),
convertValueToRequiredType(Object, Class)@Nullable protected Object getColumnValue(com.datastax.driver.core.Row row, int index, @Nullable Class<?> requiredType) throws com.datastax.driver.core.exceptions.DriverException
The default implementation calls RowUtils.getRowValue(Row, int, Class). If no required type has been
specified, this method delegates to getColumnValue(rs, index), which basically calls
GettableByIndexData.getObject(int) but applies some additional default conversion to appropriate value types.
row - is the Row holding the data, must not be null.index - is the column indexrequiredType - the type that each result object is expected to match (or null if none specified).com.datastax.driver.core.exceptions.DriverException - in case of extraction failureRowUtils.getRowValue(Row, int, Class),
getColumnValue(Row, int)@Nullable protected Object getColumnValue(com.datastax.driver.core.Row row, int index)
The default implementation delegates to RowUtils.getRowValue(Row, int, Class), which uses the
GettableByIndexData.getObject(int) method.
row - is the Row holding the data, must not be null.index - is the column indexcom.datastax.driver.core.exceptions.DriverException - in case of extraction failure.RowUtils.getRowValue(Row, int, Class)protected Object convertValueToRequiredType(Object value, Class<?> requiredType)
If the required type is String, the value will simply get stringified via toString(). In case of a Number,
the value will be converted into a Number, either through number conversion or through String parsing (depending on
the value type).
value - the column value as extracted from getColumnValue() (never null)requiredType - the type that each result object is expected to match (never null)getColumnValue(Row, int, Class)public static <T> SingleColumnRowMapper<T> newInstance(Class<T> requiredType)
SingleColumnRowMapper (with the required type specified only once).requiredType - the type that each result object is expected to matchCopyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.