use of org.apache.ibatis.executor.result.ResultMapException in project mybatis-3 by mybatis.
the class UnknownTypeHandlerTest method getResultWithResultSetAndColumnNameThrowsException.
@Test
public void getResultWithResultSetAndColumnNameThrowsException() throws SQLException {
doThrow(new SQLException("invalid column")).when((UnknownTypeHandler) TYPE_HANDLER).getNullableResult(rs, "foo");
try {
TYPE_HANDLER.getResult(rs, "foo");
Assert.fail("Should have thrown a ResultMapException");
} catch (Exception e) {
Assert.assertTrue("Expected ResultMapException", e instanceof ResultMapException);
Assert.assertTrue("column name is not in exception", e.getMessage().contains("column 'foo'"));
}
}
use of org.apache.ibatis.executor.result.ResultMapException in project mybatis-3 by mybatis.
the class UnknownTypeHandlerTest method getResultWithCallableStatementAndColumnIndexThrowsException.
@Test
public void getResultWithCallableStatementAndColumnIndexThrowsException() throws SQLException {
doThrow(new SQLException("invalid column")).when((UnknownTypeHandler) TYPE_HANDLER).getNullableResult(cs, 1);
try {
TYPE_HANDLER.getResult(cs, 1);
Assert.fail("Should have thrown a ResultMapException");
} catch (Exception e) {
Assert.assertTrue("Expected ResultMapException", e instanceof ResultMapException);
Assert.assertTrue("column index is not in exception", e.getMessage().contains("column #1"));
}
}
use of org.apache.ibatis.executor.result.ResultMapException in project mybatis-3 by mybatis.
the class DefaultResultSetHandler method createParameterizedResultObject.
Object createParameterizedResultObject(ResultSetWrapper rsw, Class<?> resultType, List<ResultMapping> constructorMappings, List<Class<?>> constructorArgTypes, List<Object> constructorArgs, String columnPrefix) {
boolean foundValues = false;
for (ResultMapping constructorMapping : constructorMappings) {
final Class<?> parameterType = constructorMapping.getJavaType();
final String column = constructorMapping.getColumn();
final Object value;
try {
if (constructorMapping.getNestedQueryId() != null) {
value = getNestedQueryConstructorValue(rsw.getResultSet(), constructorMapping, columnPrefix);
} else if (constructorMapping.getNestedResultMapId() != null) {
final ResultMap resultMap = configuration.getResultMap(constructorMapping.getNestedResultMapId());
value = getRowValue(rsw, resultMap);
} else {
final TypeHandler<?> typeHandler = constructorMapping.getTypeHandler();
value = typeHandler.getResult(rsw.getResultSet(), prependPrefix(column, columnPrefix));
}
} catch (ResultMapException e) {
throw new ExecutorException("Could not process result for mapping: " + constructorMapping, e);
} catch (SQLException e) {
throw new ExecutorException("Could not process result for mapping: " + constructorMapping, e);
}
constructorArgTypes.add(parameterType);
constructorArgs.add(value);
foundValues = value != null || foundValues;
}
return foundValues ? objectFactory.create(resultType, constructorArgTypes, constructorArgs) : null;
}
use of org.apache.ibatis.executor.result.ResultMapException in project mybatis-3 by mybatis.
the class UnknownTypeHandlerTest method getResultWithResultSetAndColumnIndexThrowsException.
@Test
public void getResultWithResultSetAndColumnIndexThrowsException() throws SQLException {
doThrow(new SQLException("invalid column")).when((UnknownTypeHandler) TYPE_HANDLER).getNullableResult(rs, 1);
try {
TYPE_HANDLER.getResult(rs, 1);
Assert.fail("Should have thrown a ResultMapException");
} catch (Exception e) {
Assert.assertTrue("Expected ResultMapException", e instanceof ResultMapException);
Assert.assertTrue("column index is not in exception", e.getMessage().contains("column #1"));
}
}
Aggregations