Search in sources :

Example 6 with DefaultResultHandler

use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.

the class BindingTest method shouldExecuteMultipleBoundSelectOfBlogsByIdInWithProvidedResultHandlerBetweenSessions.

@Test
public void shouldExecuteMultipleBoundSelectOfBlogsByIdInWithProvidedResultHandlerBetweenSessions() {
    SqlSession session = sqlSessionFactory.openSession();
    try {
        final DefaultResultHandler handler = new DefaultResultHandler();
        session.select("selectBlogsAsMapById", handler);
        //new session
        session.close();
        session = sqlSessionFactory.openSession();
        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)

Example 7 with DefaultResultHandler

use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldExecuteSelectOneAuthorUsingMapperClassWithResultHandler.

@Test
public void shouldExecuteSelectOneAuthorUsingMapperClassWithResultHandler() {
    SqlSession session = sqlMapper.openSession();
    try {
        DefaultResultHandler handler = new DefaultResultHandler();
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        mapper.selectAuthor(101, handler);
        Author author = (Author) handler.getResultList().get(0);
        assertEquals(101, author.getId());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 8 with DefaultResultHandler

use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldFailExecutingAnAnnotatedMapperClassWithResultHandler.

@Test(expected = BindingException.class)
public void shouldFailExecutingAnAnnotatedMapperClassWithResultHandler() {
    SqlSession session = sqlMapper.openSession();
    try {
        DefaultResultHandler handler = new DefaultResultHandler();
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        mapper.selectAuthor2(101, handler);
        Author author = (Author) handler.getResultList().get(0);
        assertEquals(101, author.getId());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) ImmutableAuthor(org.apache.ibatis.domain.blog.ImmutableAuthor) Author(org.apache.ibatis.domain.blog.Author) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 9 with DefaultResultHandler

use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.

the class SqlSessionTest method shouldSelectAuthorsUsingMapperClassWithResultHandler.

@Test
public void shouldSelectAuthorsUsingMapperClassWithResultHandler() {
    SqlSession session = sqlMapper.openSession();
    try {
        DefaultResultHandler handler = new DefaultResultHandler();
        AuthorMapper mapper = session.getMapper(AuthorMapper.class);
        mapper.selectAllAuthors(handler);
        assertEquals(2, handler.getResultList().size());
    } finally {
        session.close();
    }
}
Also used : AuthorMapper(org.apache.ibatis.domain.blog.mappers.AuthorMapper) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 10 with DefaultResultHandler

use of org.apache.ibatis.executor.result.DefaultResultHandler in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method handleRefCursorOutputParameter.

private void handleRefCursorOutputParameter(ResultSet rs, ParameterMapping parameterMapping, MetaObject metaParam) throws SQLException {
    if (rs == null) {
        return;
    }
    try {
        final String resultMapId = parameterMapping.getResultMapId();
        final ResultMap resultMap = configuration.getResultMap(resultMapId);
        final DefaultResultHandler resultHandler = new DefaultResultHandler(objectFactory);
        final ResultSetWrapper rsw = new ResultSetWrapper(rs, configuration);
        handleRowValues(rsw, resultMap, resultHandler, new RowBounds(), null);
        metaParam.setValue(parameterMapping.getProperty(), resultHandler.getResultList());
    } finally {
        // issue #228 (close resultsets)
        closeResultSet(rs);
    }
}
Also used : ResultMap(org.apache.ibatis.mapping.ResultMap) RowBounds(org.apache.ibatis.session.RowBounds) DefaultResultHandler(org.apache.ibatis.executor.result.DefaultResultHandler)

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