mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-24 01:52:22 -05:00
Minor re-factoring
This commit is contained in:
parent
af0c0f3483
commit
ac4216709e
@ -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;
|
||||
}
|
||||
|
||||
|
@ -670,7 +670,7 @@ public class RowToObjectMapper<K, T> extends AbstractRowMapper<K, T> {
|
||||
} 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;
|
||||
|
@ -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()'
|
||||
|
Loading…
Reference in New Issue
Block a user