package org.sonar.core.issue.db;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.BatchComponent;
import org.sonar.core.persistence.MyBatis;
import javax.annotation.CheckForNull;
+
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import static com.google.common.collect.Lists.newArrayList;
+
/**
* @since 3.6
*/
}
List<IssueChangeDto> selectByIssuesAndType(SqlSession session, Collection<String> issueKeys, String changeType) {
- Preconditions.checkArgument(issueKeys.size() < 1000, "Number of issue keys is greater than or equal 1000");
if (issueKeys.isEmpty()) {
return Collections.emptyList();
}
IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
- return mapper.selectByIssuesAndType(issueKeys, changeType);
+
+ List<List<String>> keysPartition = Lists.partition(newArrayList(issueKeys), 1000);
+ return mapper.selectByIssuesAndType(keysPartition, changeType);
}
public boolean delete(String key) {
import org.apache.ibatis.annotations.Param;
import javax.annotation.CheckForNull;
-import java.util.Collection;
+
import java.util.List;
/**
/**
* Issue changes by chronological date of creation
*/
- List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") Collection<String> issueKeys,
+ List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") List<List<String>> issueKeys,
@Param("changeType") String changeType);
List<IssueChangeDto> selectByIssue(String issueKey);
select
<include refid="issueChangeColumns"/>
from issue_changes c
- where c.change_type=#{changeType} and c.issue_key in (
- <foreach collection="issueKeys" item="key" separator=",">#{key}</foreach>
- )
+ where c.change_type=#{changeType} and
+ <foreach collection="issueKeys" open="c.issue_key in (" close=")" item="list" separator=") or c.issue_key in (">
+ <foreach collection="list" item="element" separator=",">
+ #{element}
+ </foreach>
+ </foreach>
order by c.created_at
</select>
import java.util.Collections;
import java.util.List;
+import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
assertThat(second.markdownText()).isEqualTo("recent comment");
}
+ @Test
+ public void selectCommentsByIssuesOnHugeNumberOfIssues() {
+ setupData("shared");
+
+ SqlSession session = getMyBatis().openSession();
+ List<String> hugeNbOfIssues = newArrayList();
+ for (int i=0; i<1500; i++) {
+ hugeNbOfIssues.add("ABCD"+i);
+ }
+ List<DefaultIssueComment> comments = dao.selectCommentsByIssues(session, hugeNbOfIssues);
+ MyBatis.closeQuietly(session);
+
+ // The goal of this test is only to check that the query do no fail, not to check the number of results
+ assertThat(comments).isEmpty();
+ }
+
@Test
public void selectCommentByKey() {
setupData("shared");
assertThat(dao.selectCommentByKey("UNKNOWN")).isNull();
}
-
@Test
public void selectIssueChangelog() {
setupData("shared");