mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-28 20:02:18 -05:00
Try *again* to fix exception thrown when constructor cannot be found if the constructor is not needed, and *again* add some more tests
This commit is contained in:
parent
8664d887d2
commit
117910274e
@ -120,7 +120,7 @@ public class RowToObjectMapper<T> extends RowMapper {
|
|||||||
if (!constructor.isAccessible())
|
if (!constructor.isAccessible())
|
||||||
constructor.setAccessible(true);
|
constructor.setAccessible(true);
|
||||||
} catch (Throwable e1) {
|
} 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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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));
|
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<String, String> map = new HashMap<String, String>();
|
||||||
|
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<Long, Long> map = new HashMap<Long, Long>();
|
||||||
|
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<Map<String, String>> getListMap() {
|
private List<Map<String, String>> getListMap() {
|
||||||
final List<Map<String, String>> arrayMap = new ArrayList<Map<String, String>>();
|
final List<Map<String, String>> arrayMap = new ArrayList<Map<String, String>>();
|
||||||
for (final Person person : new Person[]{fieldPerson1, fieldBoss1, fieldBoss2}) {
|
for (final Person person : new Person[]{fieldPerson1, fieldBoss1, fieldBoss2}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user