diff --git a/common/src/main/java/com/moparisthebest/jdbc/util/ResultSetUtil.java b/common/src/main/java/com/moparisthebest/jdbc/util/ResultSetUtil.java index f29d657..bba3119 100644 --- a/common/src/main/java/com/moparisthebest/jdbc/util/ResultSetUtil.java +++ b/common/src/main/java/com/moparisthebest/jdbc/util/ResultSetUtil.java @@ -12,8 +12,9 @@ import java.time.*; */ public class ResultSetUtil { - public static final String YES = System.getProperty("UpdateableDTO.YES", "Y"); - public static final String NO = System.getProperty("UpdateableDTO.NO", "N"); + // the UpdateableDTO.YES/NO constants are for legacy reasons and should be considered deprecated + public static final String TRUE = System.getProperty("ResultSetUtil.TRUE", System.getProperty("UpdateableDTO.YES", "Y")); + public static final String FALSE = System.getProperty("ResultSetUtil.FALSE", System.getProperty("UpdateableDTO.NO", "N")); public static Integer getObjectInt(final ResultSet rs, final int index) throws SQLException { final int ret = rs.getInt(index); @@ -56,9 +57,9 @@ public class ResultSetUtil { } catch (SQLException e) { // if we are here, it wasn't a boolean or null, so try to grab a string instead final String bool = rs.getString(index);//.toUpperCase(); // do we want it case-insensitive? - final boolean ret = YES.equals(bool); - if (!ret && !NO.equals(bool)) - throw new SQLException(String.format("Implicit conversion of database string to boolean failed on column '%d'. Returned string needs to be '%s' or '%s' and was instead '%s'.", index, YES, NO, bool)); + final boolean ret = TRUE.equals(bool); + if (!ret && !FALSE.equals(bool)) + throw new SQLException(String.format("Implicit conversion of database string to boolean failed on column '%d'. Returned string needs to be '%s' or '%s' and was instead '%s'.", index, TRUE, FALSE, bool)); return ret; } } @@ -66,7 +67,7 @@ public class ResultSetUtil { public static boolean getBooleanYN(final ResultSet rs, final int index) throws SQLException { final Boolean ret = getObjectBooleanYN(rs, index); if(ret == null) - throw new SQLException(String.format("Implicit conversion of database string to boolean failed on column '%d'. Returned string needs to be '%s' or '%s' and was instead 'null'. If you want to accept null values, make it an object Boolean instead of primitive boolean.", index, YES, NO)); + throw new SQLException(String.format("Implicit conversion of database string to boolean failed on column '%d'. Returned string needs to be '%s' or '%s' and was instead 'null'. If you want to accept null values, make it an object Boolean instead of primitive boolean.", index, TRUE, FALSE)); return ret; } diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java b/querymapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java index cc74c9c..03169da 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/RowToObjectMapper.java @@ -670,7 +670,7 @@ public class RowToObjectMapper extends AbstractRowMapper { } catch (SQLException e) { // if we are here, it wasn't a boolean or null, so try to grab a string instead String bool = _resultSet.getString(index);//.toUpperCase(); // do we want it case-insensitive? - ret = YES.equals(bool); + ret = YES.equals(bool); // todo: how do we handle null here? looks to be different than ResultSetUtil.java if (!ret && !NO.equals(bool)) throw new MapperException(String.format("Implicit conversion of database string to boolean failed on column '%d'. Returned string needs to be 'Y' or 'N' and was instead '%s'.", index, bool)); //throw e; diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/UpdateableDTO.java b/querymapper/src/main/java/com/moparisthebest/jdbc/UpdateableDTO.java index 52cac10..c3e11e5 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/UpdateableDTO.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/UpdateableDTO.java @@ -1,5 +1,7 @@ package com.moparisthebest.jdbc; +import com.moparisthebest.jdbc.util.ResultSetUtil; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -16,8 +18,8 @@ public abstract class UpdateableDTO implements Finishable { private String tableName; private String whereClause; - public static final String YES = System.getProperty("UpdateableDTO.YES", "Y"); - public static final String NO = System.getProperty("UpdateableDTO.NO", "N"); + public static final String YES = ResultSetUtil.TRUE; + public static final String NO = ResultSetUtil.FALSE; /** * Will always return YES or NO from this class, so they CAN be compared with object equality '==' instead of '.equals()'