use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.
the class DefaultResultSetHandler method handleResultSet.
private void handleResultSet(ResultSetWrapper rsw, ResultMap resultMap, List<Object> multipleResults, ResultMapping parentMapping) throws SQLException {
try {
if (parentMapping != null) {
handleRowValues(rsw, resultMap, null, RowBounds.DEFAULT, parentMapping);
} else {
if (resultHandler == null) {
DefaultResultHandler defaultResultHandler = new DefaultResultHandler(objectFactory);
handleRowValues(rsw, resultMap, defaultResultHandler, rowBounds, null);
multipleResults.add(defaultResultHandler.getResultList());
} else {
handleRowValues(rsw, resultMap, resultHandler, rowBounds, null);
}
}
} finally {
// issue #228 (close resultsets)
closeResultSet(rsw.getResultSet());
}
}
use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.
the class SqlSessionTest method shouldFailSelectOneAuthorUsingMapperClassWithTwoResultHandlers.
@Test(expected = BindingException.class)
public void shouldFailSelectOneAuthorUsingMapperClassWithTwoResultHandlers() {
Configuration configuration = new Configuration(sqlMapper.getConfiguration().getEnvironment());
configuration.addMapper(AuthorMapperWithMultipleHandlers.class);
SqlSessionFactory sqlMapperWithMultipleHandlers = new DefaultSqlSessionFactory(configuration);
SqlSession sqlSession = sqlMapperWithMultipleHandlers.openSession();
try {
DefaultResultHandler handler1 = new DefaultResultHandler();
DefaultResultHandler handler2 = new DefaultResultHandler();
AuthorMapperWithMultipleHandlers mapper = sqlSession.getMapper(AuthorMapperWithMultipleHandlers.class);
mapper.selectAuthor(101, handler1, handler2);
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.executor.result.DefaultResultHandler in project pinpoint by naver.
the class SqlSessionTestBase method testAndVerifySelect.
protected final void testAndVerifySelect() throws Exception {
// Given
final String selectId = "selectId";
SqlSession sqlSession = getSqlSession();
// When
sqlSession.select(selectId, new DefaultResultHandler());
sqlSession.select(selectId, new Object(), new DefaultResultHandler());
sqlSession.select(selectId, new Object(), RowBounds.DEFAULT, new DefaultResultHandler());
// Then
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
Method select1 = sqlSession.getClass().getDeclaredMethod("select", String.class, ResultHandler.class);
verifier.verifyTrace(event("MYBATIS", select1, Expectations.cachedArgs(selectId)));
Method select2 = sqlSession.getClass().getDeclaredMethod("select", String.class, Object.class, ResultHandler.class);
verifier.verifyTrace(event("MYBATIS", select2, Expectations.cachedArgs(selectId)));
Method select3 = sqlSession.getClass().getDeclaredMethod("select", String.class, Object.class, RowBounds.class, ResultHandler.class);
verifier.verifyTrace(event("MYBATIS", select3, Expectations.cachedArgs(selectId)));
}
use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.
the class BindingTest method executeWithResultHandlerAndRowBounds.
@Test
public void executeWithResultHandlerAndRowBounds() {
SqlSession session = sqlSessionFactory.openSession();
try {
BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
final DefaultResultHandler handler = new DefaultResultHandler();
mapper.collectRangeBlogs(handler, new RowBounds(1, 1));
assertEquals(1, handler.getResultList().size());
Blog blog = (Blog) handler.getResultList().get(0);
assertEquals(2, blog.getId());
} finally {
session.close();
}
}
use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.
the class BindingTest method shouldExecuteMultipleBoundSelectOfBlogsByIdInWithProvidedResultHandlerInSameSession.
@Test
public void shouldExecuteMultipleBoundSelectOfBlogsByIdInWithProvidedResultHandlerInSameSession() {
SqlSession session = sqlSessionFactory.openSession();
try {
final DefaultResultHandler handler = new DefaultResultHandler();
session.select("selectBlogsAsMapById", handler);
final DefaultResultHandler moreHandler = new DefaultResultHandler();
session.select("selectBlogsAsMapById", moreHandler);
assertEquals(2, handler.getResultList().size());
assertEquals(2, moreHandler.getResultList().size());
} finally {
session.close();
}
}
Aggregations