Search in sources :

Example 1 with DefaultResultHandler

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());
    }
}
Also used : DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler)

Example 2 with DefaultResultHandler

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();
    }
}
Also used : DefaultSqlSessionFactory(org.apache.ibatis.session.defaults.DefaultSqlSessionFactory) DefaultSqlSessionFactory(org.apache.ibatis.session.defaults.DefaultSqlSessionFactory) AuthorMapperWithMultipleHandlers(org.apache.ibatis.domain.blog.mappers.AuthorMapperWithMultipleHandlers) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 3 with DefaultResultHandler

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)));
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler)

Example 4 with DefaultResultHandler

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();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) RowBounds(org.apache.ibatis.session.RowBounds) Blog(org.apache.ibatis.domain.blog.Blog) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 5 with DefaultResultHandler

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();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

DefaultResultHandler (org.apache.ibatis.executor.result.DefaultResultHandler)10 BaseDataTest (org.apache.ibatis.BaseDataTest)7 Test (org.junit.Test)7 SqlSession (org.apache.ibatis.session.SqlSession)4 AuthorMapper (org.apache.ibatis.domain.blog.mappers.AuthorMapper)3 Author (org.apache.ibatis.domain.blog.Author)2 ImmutableAuthor (org.apache.ibatis.domain.blog.ImmutableAuthor)2 RowBounds (org.apache.ibatis.session.RowBounds)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)1 Method (java.lang.reflect.Method)1 Blog (org.apache.ibatis.domain.blog.Blog)1 AuthorMapperWithMultipleHandlers (org.apache.ibatis.domain.blog.mappers.AuthorMapperWithMultipleHandlers)1 ResultMap (org.apache.ibatis.mapping.ResultMap)1 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)1