Top Description Fields Constructors Methods
liquibase.executor.jvm

pack-priv Class SingleColumnRowMapper

extends Object
implements RowMapper
Class Inheritance
All Implemented Interfaces
liquibase.executor.jvm.RowMapper
Imports
liquibase.util.JdbcUtil, .NumberUtil, .ObjectUtil, java.math.BigDecimal, java.sql.*

RowMapper implementation that converts a single column into a single result value per row. Expects to work on a 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.

Author
Spring Framework

Field Summary

Modifier and TypeField and Description
private Class<T>

Constructor Summary

AccessConstructor and Description
public
SingleColumnRowMapper()

Create a new SingleColumnRowMapper.

public
SingleColumnRowMapper(Class<T>
the type that each result object is expected to match
requiredType
)

Create a new SingleColumnRowMapper.

Method Summary

Modifier and TypeMethod and Description
protected Object

Returns:

the converted value
convertValueToRequiredType
(Object
the column value as extracted from getColumnValue() (never null)
value
,
Class<T>
the type that each result object is expected to match (never null)
requiredType
)

Convert the given column value to the specified required type.

protected Object

Returns:

the Object value
getColumnValue
(ResultSet
is the ResultSet holding the data
rs
,
int
is the column index
index
,
Class<T>
the type that each result object is expected to match (or null if none specified)
requiredType
)

Retrieve a JDBC object value for the specified column.

protected Object

Returns:

the Object value
getColumnValue
(ResultSet
is 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 Object
mapRow(ResultSet
the ResultSet to map (pre-initialized for the current row)
rs
,
int
the number of the current row
rowNum
)

Implements liquibase.executor.jvm.RowMapper.mapRow.

Extract a value for the single column in the current row.

public void
setRequiredType(Class<T> requiredType)

Set the type that each result object is expected to match.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

requiredTypeback to summary
private Class<T> requiredType

Constructor Detail

SingleColumnRowMapperback to summary
public SingleColumnRowMapper()

Create a new SingleColumnRowMapper.

See Also
setRequiredType
SingleColumnRowMapperback to summary
public SingleColumnRowMapper(Class<T> requiredType)

Create a new SingleColumnRowMapper.

Parameters
requiredType:Class<T>

the type that each result object is expected to match

Method Detail

convertValueToRequiredTypeback to summary
protected Object convertValueToRequiredType(Object value, Class<T> 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 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).

Parameters
value:Object

the column value as extracted from getColumnValue() (never null)

requiredType:Class<T>

the type that each result object is expected to match (never null)

Returns:Object

the converted value

See Also
getColumnValue(java.sql.ResultSet, int, Class)
getColumnValueback to summary
protected Object getColumnValue(ResultSet rs, int index, Class<T> requiredType) throws SQLException

Retrieve a JDBC object value for the specified column.

The default implementation calls ResultSet.getString(index) etc for all standard value types (String, Boolean, number types, date types, etc). It calls ResultSet.getObject(index) else.

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.

Explicit extraction of a String is necessary to properly extract an Oracle RAW value as a String, for example. For the other given types, it is also recommendable to extract the desired types explicitly, to let the JDBC driver perform appropriate (potentially database-specific) conversion.

Parameters
rs:ResultSet

is the ResultSet holding the data

index:int

is the column index

requiredType:Class<T>

the type that each result object is expected to match (or null if none specified)

Returns:Object

the Object value

See Also
java.sql.ResultSet#getString(int), java.sql.ResultSet#getObject(int), getColumnValue(java.sql.ResultSet, int)
getColumnValueback 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 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.

Parameters
rs:ResultSet

is the ResultSet holding the data

index:int

is the column index

Returns:Object

the Object value

mapRowback to summary
public Object mapRow(ResultSet rs, int rowNum) throws SQLException

Implements liquibase.executor.jvm.RowMapper.mapRow.

Extract a value for the single column in the current row.

Validates that there is only one column selected, then delegates to getColumnValue() and also convertValueToRequiredType, if necessary.

Parameters
rs:ResultSet

Doc from liquibase.executor.jvm.RowMapper.mapRow.

the ResultSet to map (pre-initialized for the current row)

rowNum:int

Doc from liquibase.executor.jvm.RowMapper.mapRow.

the number of the current row

Returns:Object

Doc from liquibase.executor.jvm.RowMapper.mapRow.

the result object for the current row

Annotations
@Override
Exceptions
SQLException:

Doc from liquibase.executor.jvm.RowMapper.mapRow.

if a SQLException is encountered getting column values (that is, there's no need to catch SQLException)

See Also
java.sql.ResultSetMetaData#getColumnCount(), getColumnValue(java.sql.ResultSet, int, Class), convertValueToRequiredType(Object, Class)
setRequiredTypeback 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.