T - the generic typepublic class SingleColumnRowMapper<T>
extends java.lang.Object
implements org.springframework.jdbc.core.RowMapper<T>, cn.featherfly.common.repository.mapping.RowMapper<T>
| 构造器和说明 |
|---|
SingleColumnRowMapper(java.lang.Class<T> requiredType,
cn.featherfly.common.db.mapping.SqlTypeMappingManager manager)
Create a new
SingleColumnRowMapper. |
| 限定符和类型 | 方法和说明 |
|---|---|
protected java.lang.Object |
convertValueToRequiredType(java.lang.Object value,
java.lang.Class<?> requiredType)
Convert the given column value to the specified required type.
|
protected java.lang.Object |
getColumnValue(java.sql.ResultSet rs,
int index)
Retrieve a JDBC object value for the specified column, using the most
appropriate value type.
|
protected java.lang.Object |
getColumnValue(java.sql.ResultSet rs,
int index,
java.lang.Class<?> requiredType)
Retrieve a JDBC object value for the specified column.
|
T |
mapRow(cn.featherfly.common.repository.mapping.ResultSet res,
int rowNum) |
T |
mapRow(java.sql.ResultSet rs,
int rowNum)
Extract a value for the single column in the current row.
|
void |
setConversionService(org.springframework.core.convert.ConversionService conversionService)
Set a
ConversionService for converting a fetched value. |
void |
setRequiredType(java.lang.Class<T> requiredType)
Set the type that each result object is expected to match.
|
public SingleColumnRowMapper(java.lang.Class<T> requiredType, cn.featherfly.common.db.mapping.SqlTypeMappingManager manager)
SingleColumnRowMapper.requiredType - the type that each result object is expected to matchmanager - the managerpublic void setRequiredType(java.lang.Class<T> requiredType)
If not specified, the column value will be exposed as returned by the JDBC driver.
requiredType - the new required typepublic void setConversionService(@Nullable
org.springframework.core.convert.ConversionService conversionService)
ConversionService for converting a fetched value.
Default is the DefaultConversionService.
conversionService - the new conversion serviceDefaultConversionService.getSharedInstance()public T mapRow(cn.featherfly.common.repository.mapping.ResultSet res, int rowNum)
mapRow 在接口中 cn.featherfly.common.repository.mapping.RowMapper<T>@Nullable public T mapRow(java.sql.ResultSet rs, int rowNum) throws java.sql.SQLException
Validates that there is only one column selected, then delegates to
getColumnValue() and also convertValueToRequiredType, if
necessary.
rs - the rsrowNum - the row numjava.sql.SQLException - the SQL exceptionResultSetMetaData.getColumnCount(),
getColumnValue(java.sql.ResultSet, int, Class),
convertValueToRequiredType(Object, Class)@Nullable
protected java.lang.Object getColumnValue(java.sql.ResultSet rs,
int index,
@Nullable
java.lang.Class<?> requiredType)
throws java.sql.SQLException
The default implementation calls
JdbcUtils.getResultSetValue(java.sql.ResultSet, int, Class). If
no required type has been specified, this method delegates to
getColumnValue(rs, index), which basically calls
ResultSet.getObject(index) but applies some additional default
conversion to appropriate value types.
rs - is the ResultSet holding the dataindex - is the column indexrequiredType - the type that each result object is expected to match
(or null if none specified)java.sql.SQLException - in case of extraction failureJdbcUtils.getResultSetValue(java.sql.ResultSet,
int, Class),
getColumnValue(java.sql.ResultSet, int)@Nullable
protected java.lang.Object getColumnValue(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
The default implementation delegates to
JdbcUtils.getResultSetValue(), which uses the
ResultSet.getObject(index) method. Additionally, it includes a
"hack" to get around Oracle returning a non-standard object for their
TIMESTAMP datatype. See the JdbcUtils#getResultSetValue() javadoc
for details.
rs - is the ResultSet holding the dataindex - is the column indexjava.sql.SQLException - in case of extraction failureJdbcUtils.getResultSetValue(java.sql.ResultSet,
int)@Nullable
protected java.lang.Object convertValueToRequiredType(java.lang.Object value,
java.lang.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). Otherwise, the value will be converted to
a required type using the ConversionService.
value - the column value as extracted from
getColumnValue() (never null)requiredType - the type that each result object is expected to match
(never null)getColumnValue(java.sql.ResultSet, int, Class)