mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-24 18:02:18 -05:00
Call com.moparisthebest.jdbc.Finishable.finish(ResultSet) in more cases as appropriate
This commit is contained in:
parent
4c8c848a1f
commit
1fa08bc74b
@ -319,6 +319,7 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
|
|
||||||
if (resultSetConstructor) {
|
if (resultSetConstructor) {
|
||||||
java.append("final ").append(tType).append(" ret = new ").append(tType).append("(rs);\n");
|
java.append("final ").append(tType).append(" ret = new ").append(tType).append("(rs);\n");
|
||||||
|
finishIfNeeded(java);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,6 +331,7 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
java.append(",\n");
|
java.append(",\n");
|
||||||
}
|
}
|
||||||
java.append(");\n");
|
java.append(");\n");
|
||||||
|
finishIfNeeded(java);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,6 +384,7 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
java.append("final ").append(tType).append(" ret = ");
|
java.append("final ").append(tType).append(" ret = ");
|
||||||
extractColumnValueString(java, 1, typeId, _returnTypeClass.toString());
|
extractColumnValueString(java, 1, typeId, _returnTypeClass.toString());
|
||||||
java.append(";\n");
|
java.append(";\n");
|
||||||
|
finishIfNeeded(java);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// we still might want a single value (i.e. java.util.Date)
|
// we still might want a single value (i.e. java.util.Date)
|
||||||
@ -433,6 +436,10 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
java.append(");\n");
|
java.append(");\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finishIfNeeded(java);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finishIfNeeded(final Appendable java) throws IOException {
|
||||||
// if this resultObject is Finishable, call finish()
|
// if this resultObject is Finishable, call finish()
|
||||||
if (rsm.types.isAssignable(_returnTypeClass, rsm.finishableType))
|
if (rsm.types.isAssignable(_returnTypeClass, rsm.finishableType))
|
||||||
java.append("ret.finish(rs);\n");
|
java.append("ret.finish(rs);\n");
|
||||||
|
@ -238,7 +238,7 @@ public class RowToObjectMapper<K, T> extends AbstractRowMapper<K, T> {
|
|||||||
|
|
||||||
if (resultSetConstructor)
|
if (resultSetConstructor)
|
||||||
try {
|
try {
|
||||||
return constructor.newInstance(_resultSet);
|
return finishIfNeeded(constructor.newInstance(_resultSet), _resultSet);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new MapperException(e.getClass().getName() + " when trying to create instance of : "
|
throw new MapperException(e.getClass().getName() + " when trying to create instance of : "
|
||||||
+ _returnTypeClass.getName() + " sending in a ResultSet object as a parameter", e);
|
+ _returnTypeClass.getName() + " sending in a ResultSet object as a parameter", e);
|
||||||
@ -249,7 +249,7 @@ public class RowToObjectMapper<K, T> extends AbstractRowMapper<K, T> {
|
|||||||
for(int x = 1; x <= _columnCount; ++x)
|
for(int x = 1; x <= _columnCount; ++x)
|
||||||
_args[x-1] = extractColumnValue(_fieldOrder[x], _fieldTypes[x], _fieldClasses[x]);
|
_args[x-1] = extractColumnValue(_fieldOrder[x], _fieldTypes[x], _fieldClasses[x]);
|
||||||
//System.out.println("creating " + constructor + " sending in a objects: " + Arrays.toString(_args));
|
//System.out.println("creating " + constructor + " sending in a objects: " + Arrays.toString(_args));
|
||||||
return constructor.newInstance(_args);
|
return finishIfNeeded(constructor.newInstance(_args), _resultSet);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new MapperException(e.getClass().getName() + " when trying to create instance of : "
|
throw new MapperException(e.getClass().getName() + " when trying to create instance of : "
|
||||||
+ _returnTypeClass.getName() + " sending in a objects: " + Arrays.toString(_args), e);
|
+ _returnTypeClass.getName() + " sending in a objects: " + Arrays.toString(_args), e);
|
||||||
@ -298,12 +298,12 @@ public class RowToObjectMapper<K, T> extends AbstractRowMapper<K, T> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (typeId != TypeMappingsFactory.TYPE_UNKNOWN) {
|
if (typeId != TypeMappingsFactory.TYPE_UNKNOWN) {
|
||||||
return (T)extractColumnValue(1, typeId, _returnTypeClass);
|
return finishIfNeeded((T)extractColumnValue(1, typeId, _returnTypeClass), _resultSet);
|
||||||
} else {
|
} else {
|
||||||
// we still might want a single value (i.e. java.util.Date)
|
// we still might want a single value (i.e. java.util.Date)
|
||||||
Object val = extractColumnValue(1, typeId, _returnTypeClass);
|
Object val = extractColumnValue(1, typeId, _returnTypeClass);
|
||||||
if (_returnTypeClass.isAssignableFrom(val.getClass())) {
|
if (_returnTypeClass.isAssignableFrom(val.getClass())) {
|
||||||
return _returnTypeClass.cast(val);
|
return finishIfNeeded(_returnTypeClass.cast(val), _resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -379,6 +379,14 @@ public class RowToObjectMapper<K, T> extends AbstractRowMapper<K, T> {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new MapperException(e.getMessage(), e);
|
throw new MapperException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
finishIfNeeded(resultObject, _resultSet);
|
||||||
|
return resultObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T finishIfNeeded(final T resultObject, final ResultSet _resultSet) throws SQLException {
|
||||||
|
// if this resultObject is Finishable, call finish()
|
||||||
|
if (resultObject instanceof Finishable) // todo: use isAssignable and cache this...
|
||||||
|
((Finishable) resultObject).finish(_resultSet);
|
||||||
return resultObject;
|
return resultObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user