The original ResultSetMapper returned a case-insensitive HashMap for each row, add support for that again...
This commit is contained in:
parent
ff7c5d08a4
commit
2694436119
@ -11,7 +11,7 @@ import java.util.*;
|
||||
/**
|
||||
* Refer to org.apache.beehive.controls.system.jdbc.ResultSetMapper for how this class operates
|
||||
*/
|
||||
public class NewDefaultObjectResultSetMapper extends com.moparisthebest.jdbc.ResultSetMapper implements org.apache.beehive.controls.system.jdbc.ResultSetMapper {
|
||||
public class NewDefaultObjectResultSetMapper extends com.moparisthebest.jdbc.CaseInsensitiveMapResultSetMapper implements org.apache.beehive.controls.system.jdbc.ResultSetMapper {
|
||||
/**
|
||||
* Map the ResultSet to the method's return type. The object type returned is defined by the return type of the method.
|
||||
*
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.moparisthebest.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* Created by mopar on 5/15/14.
|
||||
*/
|
||||
public class CaseInsensitiveMapResultSetMapper extends ResultSetMapper {
|
||||
@Override
|
||||
protected <T> RowToObjectMapper<T> getRowMapper(ResultSet resultSet, Class<T> returnTypeClass, Calendar cal, Class<?> mapValType) {
|
||||
return new CaseInsensitiveMapRowToObjectMapper<T>(resultSet, returnTypeClass, cal, mapValType);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.moparisthebest.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by mopar on 5/15/14.
|
||||
*/
|
||||
public class CaseInsensitiveMapRowToObjectMapper<T> extends RowToObjectMapper<T> {
|
||||
public CaseInsensitiveMapRowToObjectMapper(ResultSet resultSet, Class<T> returnTypeClass) {
|
||||
super(resultSet, returnTypeClass);
|
||||
}
|
||||
|
||||
public CaseInsensitiveMapRowToObjectMapper(ResultSet resultSet, Class<T> returnTypeClass, Class<?> mapValType) {
|
||||
super(resultSet, returnTypeClass, mapValType);
|
||||
}
|
||||
|
||||
public CaseInsensitiveMapRowToObjectMapper(ResultSet resultSet, Class<T> returnTypeClass, Calendar cal) {
|
||||
super(resultSet, returnTypeClass, cal);
|
||||
}
|
||||
|
||||
public CaseInsensitiveMapRowToObjectMapper(ResultSet resultSet, Class<T> returnTypeClass, Calendar cal, Class<?> mapValType) {
|
||||
super(resultSet, returnTypeClass, cal, mapValType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getMapImplementation() throws IllegalAccessException, InstantiationException {
|
||||
if(HashMap.class.equals(_returnTypeClass))
|
||||
return new HashMap<String, Object>(){
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
return super.get(key instanceof String ? ((String)key).toLowerCase() : key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return super.containsKey(key instanceof String ? ((String)key).toLowerCase() : key);
|
||||
}
|
||||
};
|
||||
return super.getMapImplementation();
|
||||
}
|
||||
}
|
@ -116,12 +116,21 @@ public class RowToObjectMapper<T> extends RowMapper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns a new instance of the Map class required by Map<String, Object>[]
|
||||
* It lives in it's own method to minimize suppressed warnings and allow subclasses to override methods,
|
||||
* like perhaps to implement the original beehive behavior of case-insensitive strings
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
protected Map<String, Object> getMapImplementation() throws IllegalAccessException, InstantiationException {
|
||||
return (Map<String, Object>)_returnTypeClass.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the mapping.
|
||||
*
|
||||
* @return An object instance.
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public T mapRowToReturnType() {
|
||||
|
||||
if (resultSetConstructor != null)
|
||||
@ -134,7 +143,7 @@ public class RowToObjectMapper<T> extends RowMapper {
|
||||
|
||||
if(returnMap) // we want a map
|
||||
try {
|
||||
final Map<String, Object> ret = (Map<String, Object>)_returnTypeClass.newInstance();
|
||||
final Map<String, Object> ret = getMapImplementation();
|
||||
final ResultSetMetaData md = _resultSet.getMetaData();
|
||||
final int columnLength = _columnCount+1;
|
||||
if(componentType != null && componentType != Object.class){ // we want a specific value type
|
||||
|
Loading…
Reference in New Issue
Block a user