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 7347349..bd7cc2b 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java +++ b/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java @@ -28,6 +28,17 @@ public interface QmDao extends JdbcMapper { "FROM person p " + "JOIN boss b ON p.person_no = b.person_no " + "WHERE p.person_no = {personNo}"; + + public static final String personRegularNoConstructor = "SELECT person_no, first_name, last_name, birth_date, first_name AS dummy FROM person WHERE person_no = {personNo}"; + public static final String bossRegularAndUnderscoreNoConstructor = "SELECT p.person_no, p.first_name AS firstName, p.last_name, p.birth_date, b.department, p.first_name, p.first_name AS dummy " + + "FROM person p " + + "JOIN boss b ON p.person_no = b.person_no " + + "WHERE p.person_no = {personNo}"; + public static final String bossRegularAndUnderscoreReverseNoConstructor = "SELECT p.person_no, p.first_name, p.last_name, p.birth_date, b.department, p.first_name AS firstName, p.first_name AS dummy " + + "FROM person p " + + "JOIN boss b ON p.person_no = b.person_no " + + "WHERE p.person_no = {personNo}"; + public static final String bossRegular = "SELECT p.person_no, p.first_name AS firstName, p.last_name, p.birth_date, b.department " + "FROM person p " + "JOIN boss b ON p.person_no = b.person_no " + @@ -63,6 +74,12 @@ public interface QmDao extends JdbcMapper { @JdbcMapper.SQL(bossRegularAndUnderscoreReverse) FieldBoss getFieldRegularAndUnderscoreReverse(long personNo) throws SQLException; + @JdbcMapper.SQL(bossRegularAndUnderscoreNoConstructor) + FieldBoss getFieldRegularAndUnderscoreNoConstructor(long personNo) throws SQLException; + + @JdbcMapper.SQL(bossRegularAndUnderscoreReverseNoConstructor) + FieldBoss getFieldRegularAndUnderscoreReverseNoConstructor(long personNo) throws SQLException; + @JdbcMapper.SQL(bossRegular) FieldBoss getFieldRegular(long personNo) throws SQLException; @@ -72,6 +89,9 @@ public interface QmDao extends JdbcMapper { @JdbcMapper.SQL(personRegular) SetPerson getSetRegularPerson(long personNo) throws SQLException; + @JdbcMapper.SQL(personRegularNoConstructor) + SetPerson getSetRegularPersonNoConstructor(long personNo) throws SQLException; + @JdbcMapper.SQL(bossRegularAndUnderscore) SetBoss getSetRegularAndUnderscore(long personNo) 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 afa84ca..6f6778d 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java +++ b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java @@ -30,6 +30,17 @@ public class QueryMapperQmDao implements QmDao { "FROM person p " + "JOIN boss b ON p.person_no = b.person_no " + "WHERE p.person_no = ?"; + + public static final String personRegularNoConstructor = "SELECT person_no, first_name, last_name, birth_date, first_name AS dummy FROM person WHERE person_no = ?"; + public static final String bossRegularAndUnderscoreNoConstructor = "SELECT p.person_no, p.first_name AS firstName, p.last_name, p.birth_date, b.department, p.first_name, p.first_name AS dummy " + + "FROM person p " + + "JOIN boss b ON p.person_no = b.person_no " + + "WHERE p.person_no = ?"; + public static final String bossRegularAndUnderscoreReverseNoConstructor = "SELECT p.person_no, p.first_name, p.last_name, p.birth_date, b.department, p.first_name AS firstName, p.first_name AS dummy " + + "FROM person p " + + "JOIN boss b ON p.person_no = b.person_no " + + "WHERE p.person_no = ?"; + public static final String bossRegular = "SELECT p.person_no, p.first_name AS firstName, p.last_name, p.birth_date, b.department " + "FROM person p " + "JOIN boss b ON p.person_no = b.person_no " + @@ -85,6 +96,16 @@ public class QueryMapperQmDao implements QmDao { return qm.toObject(bossRegularAndUnderscoreReverse, FieldBoss.class, personNo); } + @Override + public FieldBoss getFieldRegularAndUnderscoreNoConstructor(final long personNo) throws SQLException { + return qm.toObject(bossRegularAndUnderscoreNoConstructor, FieldBoss.class, personNo); + } + + @Override + public FieldBoss getFieldRegularAndUnderscoreReverseNoConstructor(final long personNo) throws SQLException { + return qm.toObject(bossRegularAndUnderscoreReverseNoConstructor, FieldBoss.class, personNo); + } + @Override public FieldBoss getFieldRegular(final long personNo) throws SQLException { return qm.toObject(bossRegular, FieldBoss.class, personNo); @@ -100,6 +121,11 @@ public class QueryMapperQmDao implements QmDao { return qm.toObject(personRegular, SetPerson.class, personNo); } + @Override + public SetPerson getSetRegularPersonNoConstructor(final long personNo) throws SQLException { + return qm.toObject(personRegularNoConstructor, SetPerson.class, personNo); + } + @Override public SetBoss getSetRegularAndUnderscore(final long personNo) throws SQLException { return qm.toObject(bossRegularAndUnderscore, SetBoss.class, personNo); diff --git a/test/src/main/java/com/moparisthebest/jdbc/dto/FieldBoss.java b/test/src/main/java/com/moparisthebest/jdbc/dto/FieldBoss.java index 7e66454..40ac50b 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/dto/FieldBoss.java +++ b/test/src/main/java/com/moparisthebest/jdbc/dto/FieldBoss.java @@ -33,6 +33,10 @@ public class FieldBoss extends FieldPerson implements Boss { return first_name; } + public void setDummy(String dummy) { + // do nothing, this is simply to avoid calling the constructor in some cases + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/test/src/main/java/com/moparisthebest/jdbc/dto/SetPerson.java b/test/src/main/java/com/moparisthebest/jdbc/dto/SetPerson.java index 9f7b803..4416944 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/dto/SetPerson.java +++ b/test/src/main/java/com/moparisthebest/jdbc/dto/SetPerson.java @@ -33,4 +33,8 @@ public class SetPerson extends FieldPerson { this.lastName = lastName; } + public void setDummy(String dummy) { + // do nothing, this is simply to avoid calling the constructor in some cases + } + } diff --git a/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java b/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java index b562672..270c30b 100644 --- a/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java +++ b/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java @@ -167,10 +167,22 @@ public class QueryMapperTest { @Test public void testFieldRegularAndUnderscoreReverse() throws Throwable { - final Person expected = fieldBoss1; // todo: these call constructor, write another test to call setters + final Person expected = fieldBoss1; Assert.assertEquals(expected, qm.getFieldRegularAndUnderscoreReverse(expected.getPersonNo())); } + @Test + public void testFieldRegularAndUnderscoreNoConstructor() throws Throwable { + final Person expected = fieldBoss1; + Assert.assertEquals(expected, qm.getFieldRegularAndUnderscoreNoConstructor(expected.getPersonNo())); + } + + @Test + public void testFieldRegularAndUnderscoreReverseNoConstructor() throws Throwable { + final Person expected = fieldBoss1; + Assert.assertEquals(expected, qm.getFieldRegularAndUnderscoreReverseNoConstructor(expected.getPersonNo())); + } + @Test public void testFieldRegular() throws Throwable { final Person expected = fieldBoss2; @@ -191,6 +203,12 @@ public class QueryMapperTest { Assert.assertEquals(expected, qm.getSetRegularPerson(expected.getPersonNo())); } + @Test + public void testSetRegularPersonNoConstructor() throws Throwable { + final Person expected = setPerson1; + Assert.assertEquals(expected, qm.getSetRegularPersonNoConstructor(expected.getPersonNo())); + } + @Test public void testSetRegularAndUnderscore() throws Throwable { final Person expected = setBoss1;