@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(); } }
private void handleRefCursorOutputParameter( ResultSet rs, ParameterMapping parameterMapping, MetaObject metaParam) throws SQLException { 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 { closeResultSet(rs); // issue #228 (close resultsets) } }
@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(); } }
@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(); } }
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 { closeResultSet(rsw.getResultSet()); // issue #228 (close resultsets) } }