Search in sources :

Example 6 with ResultContext

use of org.apache.ibatis.session.ResultContext in project mybatis-3 by mybatis.

the class CommonPropertyDeferLoadError method testDeferLoadAfterResultHandlerWithLazyLoad.

@Test
public void testDeferLoadAfterResultHandlerWithLazyLoad() {
    SqlSession sqlSession = lazyLoadSqlSessionFactory.openSession();
    try {
        class MyResultHandler implements ResultHandler {

            List<Child> children = new ArrayList<Child>();

            @Override
            public void handleResult(ResultContext context) {
                Child child = (Child) context.getResultObject();
                children.add(child);
            }
        }
        ;
        MyResultHandler myResultHandler = new MyResultHandler();
        sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", myResultHandler);
        for (Child child : myResultHandler.children) {
            assertNotNull(child.getFather());
        }
    } finally {
        sqlSession.close();
    }
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) List(java.util.List) ResultHandler(org.apache.ibatis.session.ResultHandler) Test(org.junit.Test)

Example 7 with ResultContext

use of org.apache.ibatis.session.ResultContext in project mybatis-3 by mybatis.

the class CommonPropertyDeferLoadError method testDeferLoadDuringResultHandlerWithLazyLoad.

@Test
public void testDeferLoadDuringResultHandlerWithLazyLoad() {
    SqlSession sqlSession = lazyLoadSqlSessionFactory.openSession();
    try {
        class MyResultHandler implements ResultHandler {

            @Override
            public void handleResult(ResultContext context) {
                Child child = (Child) context.getResultObject();
                assertNotNull(child.getFather());
            }
        }
        ;
        sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", new MyResultHandler());
    } finally {
        sqlSession.close();
    }
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) SqlSession(org.apache.ibatis.session.SqlSession) ResultHandler(org.apache.ibatis.session.ResultHandler) Test(org.junit.Test)

Example 8 with ResultContext

use of org.apache.ibatis.session.ResultContext in project mybatis-3 by mybatis.

the class CommonPropertyDeferLoadError method testDeferLoadDuringResultHandler.

@Test
public void testDeferLoadDuringResultHandler() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        class MyResultHandler implements ResultHandler {

            @Override
            public void handleResult(ResultContext context) {
                Child child = (Child) context.getResultObject();
                assertNotNull(child.getFather());
            }
        }
        ;
        sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", new MyResultHandler());
    } finally {
        sqlSession.close();
    }
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) SqlSession(org.apache.ibatis.session.SqlSession) ResultHandler(org.apache.ibatis.session.ResultHandler) Test(org.junit.Test)

Example 9 with ResultContext

use of org.apache.ibatis.session.ResultContext in project mybatis-3 by mybatis.

the class NestedResultHandlerAssociationTest method shouldHandleStop.

@Test
public void shouldHandleStop() throws Exception {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
    final List<Account> accounts = new ArrayList<Account>();
    try {
        Date targetMonth = fmt.parse("2014-01-01");
        sqlSession.select("collectPageByBirthMonth", targetMonth, new ResultHandler() {

            @Override
            public void handleResult(ResultContext context) {
                Account account = (Account) context.getResultObject();
                accounts.add(account);
                if (accounts.size() > 1)
                    context.stop();
            }
        });
    } finally {
        sqlSession.close();
    }
    assertEquals(2, accounts.size());
    assertEquals("Bob1", accounts.get(0).getAccountName());
    assertEquals("Bob2", accounts.get(1).getAccountName());
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) ResultHandler(org.apache.ibatis.session.ResultHandler) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ResultContext (org.apache.ibatis.session.ResultContext)9 ResultHandler (org.apache.ibatis.session.ResultHandler)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 SqlSession (org.apache.ibatis.session.SqlSession)6 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 List (java.util.List)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 RowBounds (org.apache.ibatis.session.RowBounds)1 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)1 GroupDto (org.sonar.db.user.GroupDto)1 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)1