more convenient mapper
This commit is contained in:
parent
c6ef047835
commit
b558c89e24
2 changed files with 8 additions and 4 deletions
|
|
@ -41,7 +41,13 @@ public class JdbcResults {
|
|||
String fieldName = next.getFieldName();
|
||||
Object fieldValue;
|
||||
if (fieldName != null) {
|
||||
fieldValue = result.getObject(fieldNameMapper.apply(fieldName));
|
||||
String columnName = fieldNameMapper.apply(fieldName);
|
||||
if (columnName == null) {
|
||||
columnName = fieldName;
|
||||
} // would it be usefull if we could add this to the state (convert Function<> to Map<>)?
|
||||
// so that next time the entry would be in the map...
|
||||
// -> more branch predicability for the `if`
|
||||
fieldValue = result.getObject(columnName);
|
||||
} else {
|
||||
// assume single Primitive as Contiguous<String>, so just 1 column in the record
|
||||
fieldValue = result.getObject(1);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class JdbcResultsTest {
|
|||
when(mockResults.getObject("name")).thenReturn("Trillian");
|
||||
when(mockResults.getObject("realName")).thenReturn("Tricia MacMillan");
|
||||
|
||||
Map<String, String> nameMapping = Map.of("name", "name", "earthName", "realName");
|
||||
Map<String, String> nameMapping = Map.of("earthName", "realName");
|
||||
List<Scientist> scientists = JdbcResults.toList(mockResults, Scientist.class, nameMapping::get);
|
||||
|
||||
assertFalse(scientists.isEmpty());
|
||||
|
|
@ -66,6 +66,4 @@ class JdbcResultsTest {
|
|||
assertEquals("Trillian", scientist.getName());
|
||||
assertEquals("Tricia MacMillan", scientist.getEarthName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue