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();
}
}
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();
}
}
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();
}
}
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());
}
Aggregations