use of org.apache.ibatis.session.ResultHandler in project mybatis-3 by mybatis.
the class RefCursorTest method shouldUseResultHandlerOnOutputParam.
@Test
void shouldUseResultHandlerOnOutputParam() {
class OrderResultHandler implements ResultHandler<Order> {
private List<Order> orders = new ArrayList<>();
@Override
public void handleResult(ResultContext<? extends Order> resultContext) {
Order order = resultContext.getResultObject();
order.setCustomerName("Anonymous");
orders.add(order);
}
List<Order> getResult() {
return orders;
}
}
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
OrderResultHandler handler = new OrderResultHandler();
Map<String, Object> parameter = new HashMap<>();
parameter.put("orderId", 1);
mapper.getOrder3(parameter, handler);
assertNull(parameter.get("order"));
assertEquals(3, parameter.get("detailCount"));
assertEquals("Anonymous", handler.getResult().get(0).getCustomerName());
}
}
use of org.apache.ibatis.session.ResultHandler in project mybatis-3 by mybatis.
the class CommonPropertyDeferLoadTest method testDeferLoadAfterResultHandlerWithLazyLoad.
@Test
void testDeferLoadAfterResultHandlerWithLazyLoad() {
try (SqlSession sqlSession = lazyLoadSqlSessionFactory.openSession()) {
class MyResultHandler implements ResultHandler {
private List<Child> children = new ArrayList<>();
@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());
}
}
}
use of org.apache.ibatis.session.ResultHandler in project mybatis-3 by mybatis.
the class CommonPropertyDeferLoadTest method testDeferLoadDuringResultHandler.
@Test
void testDeferLoadDuringResultHandler() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
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());
}
}
use of org.apache.ibatis.session.ResultHandler in project mybatis-3 by mybatis.
the class CommonPropertyDeferLoadTest method testDeferLoadAfterResultHandler.
@Test
void testDeferLoadAfterResultHandler() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
class MyResultHandler implements ResultHandler {
private List<Child> children = new ArrayList<>();
@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());
}
}
}
use of org.apache.ibatis.session.ResultHandler in project sonarqube by SonarSource.
the class IssueMapperTest method scrollClosedByComponentUuid_returns_closed_issues_of_type_SECURITY_HOTSPOT.
@Test
public void scrollClosedByComponentUuid_returns_closed_issues_of_type_SECURITY_HOTSPOT() {
RuleType ruleType = randomSupportedRuleType();
ComponentDto component = randomComponent();
IssueDto securityHotspotIssue = insertNewClosedIssue(component, RuleType.SECURITY_HOTSPOT);
IssueChangeDto hotspotChangedData = insertToClosedDiff(securityHotspotIssue);
IssueDto issue = insertNewClosedIssue(component, ruleType);
IssueChangeDto issueChange = insertToClosedDiff(issue);
RecorderResultHandler resultHandler = new RecorderResultHandler();
underTest.scrollClosedByComponentUuid(component.uuid(), NO_FILTERING_ON_CLOSE_DATE, resultHandler);
assertThat(resultHandler.issues).extracting(IssueDto::getKey, t -> t.getClosedChangeData().get()).containsOnly(tuple(issue.getKey(), issueChange.getChangeData()), tuple(securityHotspotIssue.getKey(), hotspotChangedData.getChangeData()));
}
Aggregations