From fe1ab6def8d81c30d3033655273534fd6d7b6e94 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Fri, 16 May 2014 15:36:34 -0400 Subject: [PATCH] Improve exception message in RowToObjectMapper and don't look for extra methods with underscores stripped if an exact match is found --- .../moparisthebest/jdbc/RowToObjectMapper.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 cd0b4ad..3cb4a69 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 @@ -331,18 +331,19 @@ public class RowToObjectMapper extends RowMapper { if (isSetterMethod(m)) { String fieldName = m.getName().substring(3).toUpperCase(); //System.out.println("METHOD-fieldName: "+fieldName); - if (!mapFields.containsKey(fieldName)) { + AccessibleObject field = mapFields.get(fieldName); + if (field == null) { fieldName = strippedKeys.get(fieldName); if (fieldName == null) continue; + field = mapFields.get(fieldName); } // check for overloads - Object field = mapFields.get(fieldName); if (field == null) { mapFields.put(fieldName, m); } else { - throw new MapperException("Unable to choose between overloaded methods " + m.getName() - + " on the " + _returnTypeClass.getName() + " class. Mapping is done using " + throw new MapperException("Unable to choose between overloaded methods '" + m.getName() + + "' and '"+((Method)field).getName()+"' for field '"+fieldName+"' on the " + _returnTypeClass.getName() + " class. Mapping is done using " + "a case insensitive comparison of SQL ResultSet columns to field " + "names and public setter methods on the return class. Columns are also " + "stripped of '_' and compared if no match is found with them."); @@ -379,9 +380,9 @@ public class RowToObjectMapper extends RowMapper { for (int i = 1; i < _fields.length; i++) { AccessibleObject f = mapFields.get(keys[i]); if (f == null) { - throw new MapperException("Unable to map the SQL column " + keys[i] - + " to a field on the " + _returnTypeClass.getName() + - " class. Mapping is done using a case insensitive comparision of SQL ResultSet " + throw new MapperException("Unable to map the SQL column '" + keys[i] + + "' to a field on the '" + _returnTypeClass.getName() + + "' class. Mapping is done using a case insensitive comparison of SQL ResultSet " + "columns to field " + "names and public setter methods on the return class. Columns are also " + "stripped of '_' and compared if no match is found with them.");