diff --git a/common/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapper.java b/common/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapper.java index 5913af5..2b4ca57 100644 --- a/common/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapper.java +++ b/common/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapper.java @@ -129,7 +129,7 @@ public interface JdbcMapper extends Closeable { public enum DatabaseType { DEFAULT(null, null), STANDARD("numeric", "text"), - UNNEST("numeric", "text"), + UNNEST("NUMERIC", "VARCHAR"), ORACLE("ARRAY_NUM_TYPE", "ARRAY_STR_TYPE"); public final String arrayNumberTypeName, arrayStringTypeName; diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/ArrayInList.java b/querymapper/src/main/java/com/moparisthebest/jdbc/ArrayInList.java index 7245d58..5bb9e66 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/ArrayInList.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/ArrayInList.java @@ -1,5 +1,7 @@ package com.moparisthebest.jdbc; +import com.moparisthebest.jdbc.codegen.JdbcMapper; + import java.sql.Array; import java.sql.Connection; import java.sql.SQLException; @@ -24,7 +26,7 @@ public class ArrayInList implements InList { } public ArrayInList() { - this("numeric", "text"); + this(JdbcMapper.DatabaseType.STANDARD.arrayNumberTypeName, JdbcMapper.DatabaseType.STANDARD.arrayStringTypeName); } protected String columnAppend(final String columnName) { diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/OracleArrayInList.java b/querymapper/src/main/java/com/moparisthebest/jdbc/OracleArrayInList.java index 40d02ba..ca894e4 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/OracleArrayInList.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/OracleArrayInList.java @@ -1,5 +1,7 @@ package com.moparisthebest.jdbc; +import com.moparisthebest.jdbc.codegen.JdbcMapper; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.Array; @@ -39,7 +41,7 @@ public class OracleArrayInList extends ArrayInList { } public OracleArrayInList() { - this("ARRAY_NUM_TYPE", "ARRAY_STR_TYPE"); + this(JdbcMapper.DatabaseType.ORACLE.arrayNumberTypeName, JdbcMapper.DatabaseType.ORACLE.arrayStringTypeName); } protected String columnAppend(final String columnName) { diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/UnNestArrayInList.java b/querymapper/src/main/java/com/moparisthebest/jdbc/UnNestArrayInList.java index c8877bf..1147624 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/UnNestArrayInList.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/UnNestArrayInList.java @@ -1,5 +1,7 @@ package com.moparisthebest.jdbc; +import com.moparisthebest.jdbc.codegen.JdbcMapper; + /** * HSQLDB requires array in lists to be implemented this way: * https://stackoverflow.com/questions/35939489/createarrayof-string-in-hsqldb-jdbc-returns-abstractmethoderror/35964424#35964424 @@ -17,7 +19,7 @@ public class UnNestArrayInList extends ArrayInList { } public UnNestArrayInList() { - super(); + this(JdbcMapper.DatabaseType.UNNEST.arrayNumberTypeName, JdbcMapper.DatabaseType.UNNEST.arrayStringTypeName); } protected String columnAppend(final String columnName) { diff --git a/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java b/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java index a122fac..73983a1 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java +++ b/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java @@ -249,4 +249,7 @@ public interface QmDao extends JdbcMapper { @SQL("SELECT person_no, first_name, last_name, birth_date from person WHERE {person_no IN personNos} ORDER BY person_no") List getFieldPeople(List personNos) throws SQLException; + + @SQL("SELECT person_no, first_name, last_name, birth_date from person WHERE {person_no IN personNos} AND ({first_name IN names} OR {last_name IN names}) ORDER BY person_no") + List getFieldPeopleByName(List personNos, List names) throws SQLException; } diff --git a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java index 64d41d2..c579f00 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java +++ b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java @@ -14,6 +14,7 @@ import java.util.stream.Stream; import java.time.*; //IFJAVA8_END +import static com.moparisthebest.jdbc.ListQueryMapper.inListReplace; import static com.moparisthebest.jdbc.TryClose.tryClose; public class QueryMapperQmDao implements QmDao { @@ -456,6 +457,16 @@ public class QueryMapperQmDao implements QmDao { @Override public List getFieldPeople(final List personNos) throws SQLException { - return lqm.toList("SELECT * from person WHERE " + ListQueryMapper.inListReplace + " ORDER BY person_no", FieldPerson.class, lqm.inList("person_no", personNos)); + return lqm.toList("SELECT * from person WHERE " + inListReplace + " ORDER BY person_no", FieldPerson.class, lqm.inList("person_no", personNos)); + } + + @Override + public List getFieldPeopleByName(final List personNos, final List names) throws SQLException { + return lqm.toList("SELECT * from person WHERE " + inListReplace + " AND (" + inListReplace + " OR " + inListReplace + ") ORDER BY person_no", + FieldPerson.class, + lqm.inList("person_no", personNos), + lqm.inList("first_name", names), + lqm.inList("last_name", names) + ); } } diff --git a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperTypeQmDao.java b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperTypeQmDao.java index 0255b92..1b3419b 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperTypeQmDao.java +++ b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperTypeQmDao.java @@ -15,6 +15,8 @@ import java.util.Map; //IFJAVA8_START import java.util.stream.Stream; import java.time.*; + +import static com.moparisthebest.jdbc.ListQueryMapper.inListReplace; //IFJAVA8_END public class QueryMapperTypeQmDao extends QueryMapperQmDao { @@ -336,4 +338,14 @@ public class QueryMapperTypeQmDao extends QueryMapperQmDao { public List getFieldPeople(final List personNos) throws SQLException { return lqm.toType("SELECT * from person WHERE " + ListQueryMapper.inListReplace + " ORDER BY person_no", new TypeReference>() {}, lqm.inList("person_no", personNos)); } + + @Override + public List getFieldPeopleByName(final List personNos, final List names) throws SQLException { + return lqm.toType("SELECT * from person WHERE " + inListReplace + " AND (" + inListReplace + " OR " + inListReplace + ") ORDER BY person_no", + new TypeReference>() {}, + lqm.inList("person_no", personNos), + lqm.inList("first_name", names), + lqm.inList("last_name", names) + ); + } } diff --git a/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java b/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java index 4bfc24d..7c2ea0d 100644 --- a/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java +++ b/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java @@ -533,6 +533,16 @@ public class QueryMapperTest { assertArrayEquals(people, fromDb.toArray()); } + @Test + public void testListQueryMapperListMultiple() throws SQLException { + if(!supportsInList(qm)) + return; + final List fromDb = qm.getFieldPeopleByName( + Arrays.asList(people[0].getPersonNo(), people[1].getPersonNo(), people[2].getPersonNo()), + Arrays.asList(people[0].getFirstName(), people[1].getFirstName(), people[2].getFirstName())); + assertArrayEquals(people, fromDb.toArray()); + } + @Test public void testResultSetIterable() throws SQLException { final ResultSetIterable rsi = qm.getThreePeopleResultSetIterable(people[0].getPersonNo(), people[1].getPersonNo(), people[2].getPersonNo());