コード例 #1
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @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();
   }
 }
コード例 #2
0
 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)
   }
 }
コード例 #3
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @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();
   }
 }
コード例 #4
0
ファイル: SqlSessionTest.java プロジェクト: cuiiug/mybatis-3
 @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();
   }
 }
コード例 #5
0
 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)
   }
 }