Package org.apache.ibatis.executor.result

Examples of org.apache.ibatis.executor.result.DefaultResultHandler


  @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();
    }
  }
View Full Code Here


 
  @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();
    }
  }
View Full Code Here

    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();
    }
View Full Code Here

  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 {
      // issue #228 (close resultsets)
      closeResultSet(rs);
    }
  }
View Full Code Here

    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 {
View Full Code Here

  @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();
    }
  }
View Full Code Here

  @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();
    }
  }
View Full Code Here

  @Test
  public void select_issue_changelog_by_module() {
    setupData("select_issue_changelog_by_module");

    // 400 is a non-root module, we should find 2 + 1 changelog from classes and one on itself
    DefaultResultHandler handler = new DefaultResultHandler();
    dao.selectChangelogOnNonClosedIssuesByModuleAndType(400, handler);
    assertThat(handler.getResultList()).hasSize(4);

    IssueChangeDto issueChangeDto = (IssueChangeDto) handler.getResultList().get(0);
    assertThat(issueChangeDto.getId()).isNotNull();
    assertThat(issueChangeDto.getKey()).isNotNull();
    assertThat(issueChangeDto.getIssueKey()).isNotNull();
    assertThat(issueChangeDto.getUserLogin()).isNotNull();
    assertThat(issueChangeDto.getChangeType()).isNotNull();
    assertThat(issueChangeDto.getChangeData()).isNotNull();
    assertThat(issueChangeDto.getCreatedAt()).isNotNull();
    assertThat(issueChangeDto.getUpdatedAt()).isNotNull();

    for (Object changeDtoObject : handler.getResultList()) {
      IssueChangeDto changeDto = (IssueChangeDto) changeDtoObject;
      assertThat(changeDto.getChangeType()).isEqualTo(IssueChangeDto.TYPE_FIELD_CHANGE);
    }

    // 399 is the root module, we should only find 1 changelog on itself
    handler = new DefaultResultHandler();
    dao.selectChangelogOnNonClosedIssuesByModuleAndType(399, handler);
    assertThat(handler.getResultList()).hasSize(1);
  }
View Full Code Here

  @Test
  public void select_issue_changelog_by_module_should_be_sorted_by_creation_date() {
    setupData("select_issue_changelog_by_module_are_sorted_by_creation_date");

    DefaultResultHandler handler = new DefaultResultHandler();
    dao.selectChangelogOnNonClosedIssuesByModuleAndType(399, handler);
    assertThat(handler.getResultList()).hasSize(3);
    assertThat(((IssueChangeDto) handler.getResultList().get(0)).getId()).isEqualTo(1001);
    assertThat(((IssueChangeDto) handler.getResultList().get(1)).getId()).isEqualTo(1002);
    assertThat(((IssueChangeDto) handler.getResultList().get(2)).getId()).isEqualTo(1000);
  }
View Full Code Here

  @Test
  public void select_non_closed_issues_by_module() {
    setupData("shared", "should_select_non_closed_issues_by_module");

    // 400 is a non-root module, we should find 2 issues from classes and one on itself
    DefaultResultHandler handler = new DefaultResultHandler();
    dao.selectNonClosedIssuesByModule(400, handler);
    assertThat(handler.getResultList()).hasSize(3);

    IssueDto issue = (IssueDto) handler.getResultList().get(0);
    assertThat(issue.getRuleRepo()).isNotNull();
    assertThat(issue.getRule()).isNotNull();
    assertThat(issue.getComponentKey()).isNotNull();
    assertThat(issue.getProjectKey()).isEqualTo("struts");

    // 399 is the root module, we should only find 1 issue on itself
    handler = new DefaultResultHandler();
    dao.selectNonClosedIssuesByModule(399, handler);
    assertThat(handler.getResultList()).hasSize(1);

    issue = (IssueDto) handler.getResultList().get(0);
    assertThat(issue.getComponentKey()).isEqualTo("struts");
    assertThat(issue.getProjectKey()).isEqualTo("struts");
  }
View Full Code Here

TOP

Related Classes of org.apache.ibatis.executor.result.DefaultResultHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.