mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-25 10:22:17 -05:00
Fix returning of primitive array types
This commit is contained in:
parent
bb40891e14
commit
79eac08efe
@ -120,7 +120,9 @@ public class RowToObjectMapper<T> extends RowMapper {
|
||||
if (!constructor.isAccessible())
|
||||
constructor.setAccessible(true);
|
||||
} catch (Throwable e1) {
|
||||
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
|
||||
// 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
|
||||
// or if componentType is non-null, then we want an array like Long[] or String[]
|
||||
if(_columnCount > 2 && componentType == null)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -239,6 +239,12 @@ public class QueryMapperTest {
|
||||
Assert.assertArrayEquals(expected, qm.toArray("SELECT person_no FROM person WHERE person_no = ?", Long.class, expected[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectPrimitiveArray() throws Throwable {
|
||||
final Long[] arr = {1L, 2L, 3L};
|
||||
Assert.assertArrayEquals(arr, qm.toObject("SELECT 1, 2, 3 FROM person WHERE person_no = ?", Long[].class, fieldPerson1.getPersonNo()));
|
||||
}
|
||||
|
||||
private List<Map<String, String>> getListMap() {
|
||||
final List<Map<String, String>> arrayMap = new ArrayList<Map<String, String>>();
|
||||
for (final Person person : new Person[]{fieldPerson1, fieldBoss1, fieldBoss2}) {
|
||||
|
@ -3,7 +3,6 @@ package com.moparisthebest.jdbc.dto;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This class is meant to test the java compiler's in-lining behavior for final variables
|
||||
@ -102,7 +101,7 @@ public class FinalDTO {
|
||||
}
|
||||
|
||||
private boolean directEqualsReflection(final Object object, final String fieldName) {
|
||||
return Objects.equals(object, getField(fieldName));
|
||||
return equals(object, getField(fieldName));
|
||||
}
|
||||
|
||||
public Object getField(final String fieldName) {
|
||||
@ -114,6 +113,10 @@ public class FinalDTO {
|
||||
return directEqualsReflection();
|
||||
}
|
||||
|
||||
public static boolean equals(Object a, Object b) {
|
||||
return (a == b) || (a != null && a.equals(b));
|
||||
}
|
||||
|
||||
private static Object getField(final Object object, final String fieldName) {
|
||||
try {
|
||||
final Field field = object.getClass().getDeclaredField(fieldName);
|
||||
|
Loading…
Reference in New Issue
Block a user