From 2580de8f42cac26ddb637bf61a11eb2d18ecd4ea Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Mon, 15 Jan 2018 11:56:06 -0500 Subject: [PATCH] Fix rest of Enum issues --- .../jdbc/CompilingRowToObjectMapper.java | 6 +----- .../moparisthebest/jdbc/RowToObjectMapper.java | 16 +++++++++------- .../com/moparisthebest/jdbc/dto/EnumPerson.java | 8 ++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/CompilingRowToObjectMapper.java b/querymapper/src/main/java/com/moparisthebest/jdbc/CompilingRowToObjectMapper.java index e3aa3e5..a0370e3 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/CompilingRowToObjectMapper.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/CompilingRowToObjectMapper.java @@ -327,11 +327,7 @@ public class CompilingRowToObjectMapper extends RowToObjectMapper { return _returnTypeClass.cast(val); } */ - // we could actually pull from first row like above and test it first and fail now, but maybe just failing during compilation is enough? - java.append("final ").append(tType).append(" ret = (").append(tType).append(") "); - extractColumnValueString(java, 1, typeId, _returnTypeClass.getCanonicalName()); - java.append(";\n"); - return; + // todo: we could actually pull from first row like above and test it first, but for now we will fall-through to field mappings... } } catch (Exception e) { throw new MapperException(e.getMessage(), e); diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java b/querymapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java index 243c91a..02c8df5 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java @@ -524,17 +524,19 @@ public class RowToObjectMapper extends AbstractRowMapper { + "stripped of '_' and compared if no match is found with them."); } _fields[i] = f; + final Class type; if (f instanceof Field) { final Field field = (Field) f; _fields[i] = modField(field, i); - _fieldTypes[i] = _tmf.getTypeId(field.getType()); - if(_fieldTypes[i] == TypeMappingsFactory.TYPE_ENUM) { - @SuppressWarnings("unchecked") - final Class noWarnings = (Class) field.getType(); - _fieldClasses[i] = noWarnings; - } + type = field.getType(); } else { - _fieldTypes[i] = _tmf.getTypeId(((Method) f).getParameterTypes()[0]); + type = ((Method) f).getParameterTypes()[0]; + } + _fieldTypes[i] = _tmf.getTypeId(type); + if(_fieldTypes[i] == TypeMappingsFactory.TYPE_ENUM) { + @SuppressWarnings("unchecked") + final Class noWarnings = (Class) type; + _fieldClasses[i] = noWarnings; } } } diff --git a/querymapper/src/test/java/com/moparisthebest/jdbc/dto/EnumPerson.java b/querymapper/src/test/java/com/moparisthebest/jdbc/dto/EnumPerson.java index 839639d..43a6370 100644 --- a/querymapper/src/test/java/com/moparisthebest/jdbc/dto/EnumPerson.java +++ b/querymapper/src/test/java/com/moparisthebest/jdbc/dto/EnumPerson.java @@ -37,6 +37,14 @@ public class EnumPerson implements Person { return lastName; } + public void setFirstName(final FirstName firstName) { + this.firstName = firstName; + } + + public void setLastName(final String lastName) { + this.lastName = lastName; + } + @Override public boolean equals(final Object o) { if (this == o) return true;