use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class DefaultResultSetHandlerTest method shouldThrowExceptionWithColumnName.
@Test
public void shouldThrowExceptionWithColumnName() throws Exception {
final MappedStatement ms = getMappedStatement();
final RowBounds rowBounds = new RowBounds(0, 100);
final DefaultResultSetHandler defaultResultSetHandler = new DefaultResultSetHandler(null, /*executor*/
ms, null, /*parameterHandler*/
null, /*resultHandler*/
null, /*boundSql*/
rowBounds);
final ResultSetWrapper rsw = mock(ResultSetWrapper.class);
when(rsw.getResultSet()).thenReturn(mock(ResultSet.class));
final ResultMapping resultMapping = mock(ResultMapping.class);
final TypeHandler typeHandler = mock(TypeHandler.class);
when(resultMapping.getColumn()).thenReturn("column");
when(resultMapping.getTypeHandler()).thenReturn(typeHandler);
when(typeHandler.getResult(any(ResultSet.class), any(String.class))).thenThrow(new SQLException("exception"));
List<ResultMapping> constructorMappings = Collections.singletonList(resultMapping);
try {
defaultResultSetHandler.createParameterizedResultObject(rsw, null, /*resultType*/
constructorMappings, null, /*constructorArgTypes*/
null, /*constructorArgs*/
null);
Assert.fail("Should have thrown ExecutorException");
} catch (Exception e) {
Assert.assertTrue("Expected ExecutorException", e instanceof ExecutorException);
Assert.assertTrue("", e.getMessage().contains("mapping: " + resultMapping.toString()));
}
}
use of org.apache.ibatis.mapping.MappedStatement in project pinpoint by naver.
the class BindingLogPlugin32 method bindingLog.
private void bindingLog(Invocation invocation) throws SQLException {
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement) args[0];
Object parameterObject = args[1];
StatementType statementType = ms.getStatementType();
if (StatementType.PREPARED == statementType || StatementType.CALLABLE == statementType) {
Log statementLog = ms.getStatementLog();
if (isDebugEnable(statementLog)) {
BoundSql boundSql = ms.getBoundSql(parameterObject);
String sql = boundSql.getSql();
List<String> parameterList = getParameters(ms, parameterObject, boundSql);
debug(statementLog, "==> BindingLog: " + bindLogFormatter.format(sql, parameterList));
}
}
}
use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class DefaultSqlSession method update.
@Override
public int update(String statement, Object parameter) {
try {
dirty = true;
MappedStatement ms = configuration.getMappedStatement(statement);
return executor.update(ms, wrapCollection(parameter));
} catch (Exception e) {
throw ExceptionFactory.wrapException("Error updating database. Cause: " + e, e);
} finally {
ErrorContext.instance().reset();
}
}
use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class NonFullyQualifiedNamespaceTest method testCrossReferenceXmlConfig.
@Test
public void testCrossReferenceXmlConfig() throws Exception {
Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespaceConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
configReader.close();
Configuration configuration = sqlSessionFactory.getConfiguration();
MappedStatement selectPerson = configuration.getMappedStatement("person namespace.select");
assertEquals("org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespacePersonMapper.xml", selectPerson.getResource());
Connection conn = configuration.getEnvironment().getDataSource().getConnection();
initDb(conn);
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Person person = (Person) sqlSession.selectOne("person namespace.select", 1);
assertEquals((Integer) 1, person.getId());
assertEquals(2, person.getPets().size());
assertEquals((Integer) 2, person.getPets().get(1).getId());
Pet pet = (Pet) sqlSession.selectOne("person namespace.selectPet", 1);
assertEquals(Integer.valueOf(1), pet.getId());
Pet pet2 = (Pet) sqlSession.selectOne("pet namespace.select", 3);
assertEquals((Integer) 3, pet2.getId());
assertEquals((Integer) 2, pet2.getOwner().getId());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class MultipleCrossIncludeTest method testMappedStatementCache.
@Test
public void testMappedStatementCache() throws Exception {
Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/MultipleCrossIncludeMapperConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
configReader.close();
Configuration configuration = sqlSessionFactory.getConfiguration();
configuration.getMappedStatementNames();
MappedStatement selectPetStatement = configuration.getMappedStatement("org.apache.ibatis.submitted.xml_external_ref.MultipleCrossIncludePetMapper.select");
MappedStatement selectPersonStatement = configuration.getMappedStatement("org.apache.ibatis.submitted.xml_external_ref.MultipleCrossIncludePersonMapper.select");
Cache cache = selectPetStatement.getCache();
assertEquals("org.apache.ibatis.submitted.xml_external_ref.MultipleCrossIncludePetMapper", cache.getId());
assertSame(cache, selectPersonStatement.getCache());
}
Aggregations