All Downloads are FREE. Search and download functionalities are using the official Maven repository.

online.sanen.cdm.template.RowExtractor2Map Maven / Gradle / Ivy

package online.sanen.cdm.template;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Map;

/**
 * 
 *
 * @author LazyToShow	
* Date: 2018年10月14日
* Time: 下午1:18:48 */ public class RowExtractor2Map implements RowExtractor> { public Map mapRow(ResultSet rs, int rowNum) throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); Map mapOfColValues = createColumnMap(columnCount); for (int i = 1; i <= columnCount; i++) { String key = getColumnKey(JdbcUtils.lookupColumnName(rsmd, i)); Object obj = getColumnValue(rs, i); mapOfColValues.put(key, obj); } return mapOfColValues; } /** * Create a Map instance to be used as column map. *

* By default, a linked case-insensitive Map will be created. * @param columnCount * @return */ protected Map createColumnMap(int columnCount) { return new LinkedCaseInsensitiveMap(columnCount); } /** * Determine the key to use for the given column in the column Map. * * @param columnName the column name as returned by the ResultSet * @return the column key to use * @see java.sql.ResultSetMetaData#getColumnName */ protected String getColumnKey(String columnName) { return columnName; } /** * Retrieve a JDBC object value for the specified column. *

* The default implementation uses the {@code getObject} method. Additionally, * this implementation includes a "hack" to get around Oracle returning a non * standard object for their TIMESTAMP datatype. * @param rs * @param index * @return * @throws SQLException */ protected Object getColumnValue(ResultSet rs, int index) throws SQLException { return JdbcUtils.getResultSetValue(rs, index); } }