diff --git a/beehive-jdbc-control/src/main/java/org/apache/beehive/controls/system/jdbc/NewDefaultObjectResultSetMapper.java b/beehive-jdbc-control/src/main/java/org/apache/beehive/controls/system/jdbc/NewDefaultObjectResultSetMapper.java index 807449d..9d02ee0 100644 --- a/beehive-jdbc-control/src/main/java/org/apache/beehive/controls/system/jdbc/NewDefaultObjectResultSetMapper.java +++ b/beehive-jdbc-control/src/main/java/org/apache/beehive/controls/system/jdbc/NewDefaultObjectResultSetMapper.java @@ -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. * diff --git a/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/CaseInsensitiveMapResultSetMapper.java b/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/CaseInsensitiveMapResultSetMapper.java new file mode 100644 index 0000000..4b2f36d --- /dev/null +++ b/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/CaseInsensitiveMapResultSetMapper.java @@ -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 RowToObjectMapper getRowMapper(ResultSet resultSet, Class returnTypeClass, Calendar cal, Class mapValType) { + return new CaseInsensitiveMapRowToObjectMapper(resultSet, returnTypeClass, cal, mapValType); + } +} diff --git a/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/CaseInsensitiveMapRowToObjectMapper.java b/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/CaseInsensitiveMapRowToObjectMapper.java new file mode 100644 index 0000000..3ac31b9 --- /dev/null +++ b/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/CaseInsensitiveMapRowToObjectMapper.java @@ -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 extends RowToObjectMapper { + public CaseInsensitiveMapRowToObjectMapper(ResultSet resultSet, Class returnTypeClass) { + super(resultSet, returnTypeClass); + } + + public CaseInsensitiveMapRowToObjectMapper(ResultSet resultSet, Class returnTypeClass, Class mapValType) { + super(resultSet, returnTypeClass, mapValType); + } + + public CaseInsensitiveMapRowToObjectMapper(ResultSet resultSet, Class returnTypeClass, Calendar cal) { + super(resultSet, returnTypeClass, cal); + } + + public CaseInsensitiveMapRowToObjectMapper(ResultSet resultSet, Class returnTypeClass, Calendar cal, Class mapValType) { + super(resultSet, returnTypeClass, cal, mapValType); + } + + @Override + protected Map getMapImplementation() throws IllegalAccessException, InstantiationException { + if(HashMap.class.equals(_returnTypeClass)) + return new HashMap(){ + @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(); + } +} diff --git a/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java b/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java index b2fbe14..cd0b4ad 100644 --- a/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java +++ b/beehive-jdbc-mapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java @@ -116,12 +116,21 @@ public class RowToObjectMapper extends RowMapper { } } + /** + * This returns a new instance of the Map class required by Map[] + * 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 getMapImplementation() throws IllegalAccessException, InstantiationException { + return (Map)_returnTypeClass.newInstance(); + } + /** * Do the mapping. * * @return An object instance. */ - @SuppressWarnings({"unchecked"}) public T mapRowToReturnType() { if (resultSetConstructor != null) @@ -134,7 +143,7 @@ public class RowToObjectMapper extends RowMapper { if(returnMap) // we want a map try { - final Map ret = (Map)_returnTypeClass.newInstance(); + final Map ret = getMapImplementation(); final ResultSetMetaData md = _resultSet.getMetaData(); final int columnLength = _columnCount+1; if(componentType != null && componentType != Object.class){ // we want a specific value type