Fix generic array creation error in JdbcMapper, add test

This commit is contained in:
Travis Burtrum 2018-05-08 00:09:56 -04:00
parent 1c561181ff
commit c04a9ee842
4 changed files with 4 additions and 9 deletions

View File

@ -255,7 +255,9 @@ public class CompileTimeResultSetMapper {
final String returnTypeString = componentTypeMirror.toString();
writeCollection(w, keys, "java.util.List<" + returnTypeString + ">", "java.util.ArrayList", componentTypeMirror, maxRows, cal, cleaner, reflectionFields);
w.write("\t\t\treturn _colret.toArray(new ");
w.write(returnTypeString);
// have to strip generics to avoid "generic array creation" compilation failure
final int indexOfGeneric = returnTypeString.indexOf('<');
w.write(indexOfGeneric < 0 ? returnTypeString : returnTypeString.substring(0, indexOfGeneric));
w.write("[_colret.size()]);\n");
}

View File

@ -129,10 +129,8 @@ public interface QmDao extends JdbcMapper {
@SQL(allNames)
List<Map<String, String>> getAllNames() throws SQLException;
/*
@SQL(allNames)
Map[] getAllNamesArray() throws SQLException; // todo: try Map<String, String>[] fix 'generic array creation' error
*/
Map<String, String>[] getAllNamesArray() throws SQLException;
@SQL(allNames)
Map<String, String> getAllNameMap() throws SQLException;

View File

@ -195,12 +195,10 @@ public class QueryMapperQmDao implements QmDao {
return qm.toListMap(allNames, Map.class, String.class);
}
/*
@Override
public Map<String, String>[] getAllNamesArray() throws SQLException {
return qm.toArrayMap(allNames, Map.class, String.class);
}
*/
@Override
public Map<String, String> getAllNameMap() throws SQLException {

View File

@ -285,14 +285,11 @@ public class QueryMapperTest {
Assert.assertEquals(arrayMap, qm.getAllNames());
}
/*
// todo: fix jdbcmapper for this
@Test
public void testSelectArrayMap() throws Throwable {
final List<Map<String, String>> arrayMap = getListMap();
assertArrayEquals(arrayMap.toArray(new Map[arrayMap.size()]), qm.getAllNamesArray());
}
*/
@Test
public void testSelectMapString() throws Throwable {