use of org.apache.ibatis.session.ResultHandler in project sonarqube by SonarSource.
the class IssueMapperTest method scrollClosedByComponentUuid_does_not_return_closed_issues_of_orphan_component.
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_orphan_component(RuleType ruleType) {
ComponentDto component = randomComponent();
IssueDto issue = insertNewClosedIssue(component, ruleType);
IssueChangeDto issueChange = insertToClosedDiff(issue);
IssueDto issueMissingComponent = insertNewClosedIssue(component, ruleType, t -> t.setComponentUuid("does_not_exist"));
insertToClosedDiff(issueMissingComponent);
IssueDto issueMissingProject = insertNewClosedIssue(component, ruleType, t -> t.setProjectUuid("does_not_exist"));
insertToClosedDiff(issueMissingProject);
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()));
}
use of org.apache.ibatis.session.ResultHandler in project sonarqube by SonarSource.
the class IssueMapperTest method scrollClosedByComponentUuid_does_not_return_row_for_status_change_from_close.
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_does_not_return_row_for_status_change_from_close(RuleType ruleType) {
ComponentDto component = randomComponent();
IssueDto issue = insertNewClosedIssue(component, ruleType);
Date date = new Date();
IssueChangeDto[] changes = new IssueChangeDto[] { insertToClosedDiff(issue, DateUtils.addDays(date, -10), Issue.STATUS_CLOSED, Issue.STATUS_REOPENED), insertToClosedDiff(issue, DateUtils.addDays(date, -60)), insertToClosedDiff(issue, date), insertToClosedDiff(issue, DateUtils.addDays(date, -5)) };
RecorderResultHandler resultHandler = new RecorderResultHandler();
underTest.scrollClosedByComponentUuid(component.uuid(), NO_FILTERING_ON_CLOSE_DATE, resultHandler);
assertThat(resultHandler.issues).hasSize(3).extracting(IssueDto::getKey, t -> t.getClosedChangeData().get()).containsExactly(tuple(issue.getKey(), changes[2].getChangeData()), tuple(issue.getKey(), changes[3].getChangeData()), tuple(issue.getKey(), changes[1].getChangeData()));
}
use of org.apache.ibatis.session.ResultHandler in project sonarqube by SonarSource.
the class DbSessionImplTest method all_methods_to_wrapped_SqlSession.
@Test
public void all_methods_to_wrapped_SqlSession() {
Random random = new Random();
boolean randomBoolean = random.nextBoolean();
int randomInt = random.nextInt(200);
String randomStatement = randomAlphabetic(10);
Object randomParameter = new Object();
Cursor<Object> mockCursor = mock(Cursor.class);
RowBounds rowBounds = new RowBounds();
Object randomObject = new Object();
List<Object> randomList = new ArrayList<>();
Map<Object, Object> randomMap = new HashMap<>();
String randomMapKey = randomAlphabetic(10);
ResultHandler randomResultHandler = resultContext -> {
// don't care
};
List<BatchResult> randomBatchResults = new ArrayList<>();
Configuration randomConfiguration = new Configuration();
verifyDelegation(DbSessionImpl::commit, s -> verify(s).commit());
verifyDelegation(t -> t.commit(randomBoolean), s -> verify(s).commit(randomBoolean));
verifyDelegation(sqlSession -> when(sqlSession.selectCursor(randomStatement)).thenReturn(mockCursor), dbSession -> dbSession.selectCursor(randomStatement), sqlSession -> {
verify(sqlSession).selectCursor(randomStatement);
return mockCursor;
});
verifyDelegation(sqlSession -> when(sqlSession.selectCursor(randomStatement, randomParameter)).thenReturn(mockCursor), dbSession -> dbSession.selectCursor(randomStatement, randomParameter), sqlSession -> {
verify(sqlSessionMock).selectCursor(randomStatement, randomParameter);
return mockCursor;
});
verifyDelegation(sqlSession -> when(sqlSession.selectCursor(randomStatement, randomParameter, rowBounds)).thenReturn(mockCursor), dbSession -> dbSession.selectCursor(randomStatement, randomParameter, rowBounds), sqlSession -> {
verify(sqlSessionMock).selectCursor(randomStatement, randomParameter, rowBounds);
return mockCursor;
});
verifyDelegation(sqlSession -> when(sqlSession.selectOne(randomStatement)).thenReturn(randomObject), dbSession -> dbSession.selectOne(randomStatement), sqlSession -> {
verify(sqlSession).selectOne(randomStatement);
return randomObject;
});
verifyDelegation(sqlSession -> when(sqlSession.selectOne(randomStatement, randomParameter)).thenReturn(randomObject), dbSession -> dbSession.selectOne(randomStatement, randomParameter), sqlSession -> {
verify(sqlSessionMock).selectOne(randomStatement, randomParameter);
return randomObject;
});
verifyDelegation(sqlSession -> when(sqlSession.selectList(randomStatement)).thenReturn(randomList), dbSession -> dbSession.selectList(randomStatement), sqlSession -> {
verify(sqlSession).selectList(randomStatement);
return randomList;
});
verifyDelegation(sqlSession -> when(sqlSession.selectList(randomStatement, randomParameter)).thenReturn(randomList), dbSession -> dbSession.selectList(randomStatement, randomParameter), sqlSession -> {
verify(sqlSessionMock).selectList(randomStatement, randomParameter);
return randomList;
});
verifyDelegation(sqlSession -> when(sqlSession.selectList(randomStatement, randomParameter, rowBounds)).thenReturn(randomList), dbSession -> dbSession.selectList(randomStatement, randomParameter, rowBounds), sqlSession -> {
verify(sqlSessionMock).selectList(randomStatement, randomParameter, rowBounds);
return randomList;
});
verifyDelegation(sqlSession -> when(sqlSession.selectMap(randomStatement, randomMapKey)).thenReturn(randomMap), dbSession -> dbSession.selectMap(randomStatement, randomMapKey), sqlSession -> {
verify(sqlSession).selectMap(randomStatement, randomMapKey);
return randomMap;
});
verifyDelegation(sqlSession -> when(sqlSession.selectMap(randomStatement, randomParameter, randomMapKey)).thenReturn(randomMap), dbSession -> dbSession.selectMap(randomStatement, randomParameter, randomMapKey), sqlSession -> {
verify(sqlSessionMock).selectMap(randomStatement, randomParameter, randomMapKey);
return randomMap;
});
verifyDelegation(sqlSession -> when(sqlSession.selectMap(randomStatement, randomParameter, randomMapKey, rowBounds)).thenReturn(randomMap), dbSession -> dbSession.selectMap(randomStatement, randomParameter, randomMapKey, rowBounds), sqlSession -> {
verify(sqlSessionMock).selectMap(randomStatement, randomParameter, randomMapKey, rowBounds);
return randomMap;
});
verifyDelegation(dbSession -> dbSession.select(randomStatement, randomResultHandler), sqlSession -> verify(sqlSessionMock).select(randomStatement, randomResultHandler));
verifyDelegation(dbSession -> dbSession.select(randomStatement, randomParameter, randomResultHandler), sqlSession -> verify(sqlSession).select(randomStatement, randomParameter, randomResultHandler));
verifyDelegation(dbSession -> dbSession.select(randomStatement, randomParameter, rowBounds, randomResultHandler), sqlSession -> verify(sqlSessionMock).select(randomStatement, randomParameter, rowBounds, randomResultHandler));
verifyDelegation(sqlSession -> when(sqlSession.insert(randomStatement)).thenReturn(randomInt), dbSession -> dbSession.insert(randomStatement), sqlSession -> {
verify(sqlSession).insert(randomStatement);
return randomInt;
});
verifyDelegation(sqlSession -> when(sqlSession.insert(randomStatement, randomParameter)).thenReturn(randomInt), dbSession -> dbSession.insert(randomStatement, randomParameter), sqlSession -> {
verify(sqlSessionMock).insert(randomStatement, randomParameter);
return randomInt;
});
verifyDelegation(sqlSession -> when(sqlSession.update(randomStatement)).thenReturn(randomInt), dbSession -> dbSession.update(randomStatement), sqlSession -> {
verify(sqlSession).update(randomStatement);
return randomInt;
});
verifyDelegation(sqlSession -> when(sqlSession.update(randomStatement, randomParameter)).thenReturn(randomInt), dbSession -> dbSession.update(randomStatement, randomParameter), sqlSession -> {
verify(sqlSessionMock).update(randomStatement, randomParameter);
return randomInt;
});
verifyDelegation(sqlSession -> when(sqlSession.delete(randomStatement)).thenReturn(randomInt), dbSession -> dbSession.delete(randomStatement), sqlSession -> {
verify(sqlSession).delete(randomStatement);
return randomInt;
});
verifyDelegation(sqlSession -> when(sqlSession.delete(randomStatement, randomParameter)).thenReturn(randomInt), dbSession -> dbSession.delete(randomStatement, randomParameter), sqlSession -> {
verify(sqlSessionMock).delete(randomStatement, randomParameter);
return randomInt;
});
verifyDelegation(DbSessionImpl::rollback, s -> verify(s).rollback());
verifyDelegation(t -> t.rollback(randomBoolean), s -> verify(s).rollback(randomBoolean));
verifyDelegation(sqlSession -> when(sqlSession.flushStatements()).thenReturn(randomBatchResults), DbSessionImpl::flushStatements, sqlSession -> {
verify(sqlSession).flushStatements();
return randomBatchResults;
});
verifyDelegation(DbSessionImpl::close, s -> verify(s).close());
verifyDelegation(DbSessionImpl::clearCache, s -> verify(s).clearCache());
verifyDelegation(sqlSession -> when(sqlSession.getConfiguration()).thenReturn(randomConfiguration), DbSessionImpl::getConfiguration, sqlSession -> {
verify(sqlSession).getConfiguration();
return randomConfiguration;
});
verifyDelegation(sqlSession -> when(sqlSession.getMapper(DbSessionImplTest.class)).thenReturn(DbSessionImplTest.this), dbSession -> dbSession.getMapper(DbSessionImplTest.class), sqlSession -> {
verify(sqlSession).getMapper(DbSessionImplTest.class);
return DbSessionImplTest.this;
});
verifyDelegation(DbSessionImpl::getConnection, s -> verify(s).getConnection());
}
use of org.apache.ibatis.session.ResultHandler in project mybatis-3 by mybatis.
the class CommonPropertyDeferLoadTest method testDeferLoadDuringResultHandlerWithLazyLoad.
@Test
void testDeferLoadDuringResultHandlerWithLazyLoad() {
try (SqlSession sqlSession = lazyLoadSqlSessionFactory.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 alfresco-repository by Alfresco.
the class PropertyValueDAOImpl method getPropertyUniqueContextByValues.
@Override
protected void getPropertyUniqueContextByValues(final PropertyUniqueContextCallback callback, Long... valueIds) {
PropertyUniqueContextEntity entity = new PropertyUniqueContextEntity();
for (int i = 0; i < valueIds.length; i++) {
switch(i) {
case 0:
entity.setValue1PropId(valueIds[i]);
break;
case 1:
entity.setValue2PropId(valueIds[i]);
break;
case 2:
entity.setValue3PropId(valueIds[i]);
break;
default:
throw new IllegalArgumentException("Only 3 ids allowed");
}
}
ResultHandler valueResultHandler = new ResultHandler() {
public void handleResult(ResultContext context) {
PropertyUniqueContextEntity result = (PropertyUniqueContextEntity) context.getResultObject();
Long id = result.getId();
Long propId = result.getPropertyId();
Serializable[] keys = new Serializable[3];
keys[0] = result.getValue1PropId();
keys[1] = result.getValue2PropId();
keys[2] = result.getValue3PropId();
callback.handle(id, propId, keys);
}
};
template.select(SELECT_PROPERTY_UNIQUE_CTX_BY_VALUES, entity, valueResultHandler);
// Done
}
Aggregations