1 16 17 package org.springframework.jdbc.core; 18 19 import java.sql.ResultSet ; 20 import java.sql.ResultSetMetaData ; 21 import java.sql.SQLException ; 22 import java.util.Map ; 23 24 import org.springframework.core.CollectionFactory; 25 import org.springframework.jdbc.support.JdbcUtils; 26 27 48 public class ColumnMapRowMapper implements RowMapper { 49 50 public Object mapRow(ResultSet rs, int rowNum) throws SQLException { 51 ResultSetMetaData rsmd = rs.getMetaData(); 52 int columnCount = rsmd.getColumnCount(); 53 Map mapOfColValues = createColumnMap(columnCount); 54 for (int i = 1; i <= columnCount; i++) { 55 String key = getColumnKey(rsmd.getColumnName(i)); 56 Object obj = getColumnValue(rs, i); 57 mapOfColValues.put(key, obj); 58 } 59 return mapOfColValues; 60 } 61 62 71 protected Map createColumnMap(int columnCount) { 72 return CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(columnCount); 73 } 74 75 81 protected String getColumnKey(String columnName) { 82 return columnName; 83 } 84 85 95 protected Object getColumnValue(ResultSet rs, int index) throws SQLException { 96 return JdbcUtils.getResultSetValue(rs, index); 97 } 98 99 } 100 | Popular Tags |