From 117910274e0b0b057569f71413ff8f70d815b91a Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Thu, 19 Jun 2014 08:57:23 -0400 Subject: [PATCH] Try *again* to fix exception thrown when constructor cannot be found if the constructor is not needed, and *again* add some more tests --- .../moparisthebest/jdbc/RowToObjectMapper.java | 2 +- .../moparisthebest/jdbc/QueryMapperTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 744a34b..90d1eee 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 @@ -120,7 +120,7 @@ public class RowToObjectMapper extends RowMapper { if (!constructor.isAccessible()) constructor.setAccessible(true); } catch (Throwable e1) { - if(_columnCount != 1) // if column count is only 1, it might map directly to a type like a Long or something + if(_columnCount > 2) // if column count is 2 or less, it might map directly to a type like a Long or something, or be a map which does throw new MapperException("Exception when trying to get constructor for : "+returnTypeClass.getName() + " Must have default no-arg constructor or one that takes a single ResultSet.", e1); } } diff --git a/beehive-jdbc-mapper/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java b/beehive-jdbc-mapper/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java index 49b9fb8..5f80f85 100644 --- a/beehive-jdbc-mapper/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java +++ b/beehive-jdbc-mapper/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java @@ -205,6 +205,23 @@ public class QueryMapperTest { Assert.assertEquals(arrayMap.toArray(new Map[arrayMap.size()]), qm.toArrayMap("SELECT first_name, last_name FROM person WHERE person_no < 4", arrayMap.get(0).getClass(), String.class)); } + @Test + public void testSelectMapString() throws Throwable { + final Map map = new HashMap(); + for (final Person person : new Person[]{fieldPerson1, fieldBoss1, fieldBoss2}) + map.put(person.getFirstName(), person.getLastName()); + Assert.assertEquals(map, qm.toMap("SELECT first_name, last_name FROM person WHERE person_no < 4", String.class, String.class)); + } + + @Test + public void testSelectMapLong() throws Throwable { + final Map map = new HashMap(); + for (final Person person : new Person[]{fieldPerson1, fieldBoss1, fieldBoss2}) + map.put(person.getPersonNo(), person.getPersonNo()); + Assert.assertEquals(map, qm.toMap("SELECT person_no AS first_no, person_no AS last_no FROM person WHERE person_no < 4", Long.class, Long.class)); + } + + private List> getListMap() { final List> arrayMap = new ArrayList>(); for (final Person person : new Person[]{fieldPerson1, fieldBoss1, fieldBoss2}) {