public class ColumnMapRowMapper extends java.lang.Object implements RowMapper
RowMapper
implementation that creates a java.util.Map
for each row, representing all columns as key-value pairs: one
entry for each column, with the column name as key.
The Map implementation to use and the key to use for each column
in the column Map can be customized through overriding
createColumnMap(int)
and getColumnKey(java.lang.String)
, respectively.
Constructor and Description |
---|
ColumnMapRowMapper() |
Modifier and Type | Method and Description |
---|---|
protected java.util.Map |
createColumnMap(int columnCount)
Create a Map instance to be used as column map.
|
protected java.lang.String |
getColumnKey(java.lang.String columnName)
Determine the key to use for the given column in the column Map.
|
protected java.lang.Object |
getColumnValue(java.sql.ResultSet rs,
int index)
Retrieve a JDBC object value for the specified column.
|
java.lang.Object |
mapRow(java.sql.ResultSet rs,
int rowNum)
Implementations must implement this method to map each row of data
in the ResultSet.
|
public java.lang.Object mapRow(java.sql.ResultSet rs, int rowNum) throws java.sql.SQLException
RowMapper
next()
on
the ResultSet; it is only supposed to map values of the current row.mapRow
in interface RowMapper
rs
- the ResultSet to map (pre-initialized for the current row)rowNum
- the number of the current rowjava.sql.SQLException
- if a SQLException is encountered getting
column values (that is, there's no need to catch SQLException)protected java.util.Map createColumnMap(int columnCount)
columnCount
- the column count, to be used as initial
capacity for the Mapprotected java.lang.String getColumnKey(java.lang.String columnName)
columnName
- the column name as returned by the ResultSetResultSetMetaData.getColumnName(int)
protected java.lang.Object getColumnValue(java.sql.ResultSet rs, int index) throws java.sql.SQLException
The default implementation uses the getObject
method.
Additionally, this implementation includes a "hack" to get around Oracle
returning a non standard object for their TIMESTAMP datatype.
rs
- is the ResultSet holding the dataindex
- is the column indexjava.sql.SQLException