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);
<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- ~ SonarQube, open source software quality management tool.
- ~ Copyright (C) 2008-2013 SonarSource
- ~ mailto:contact AT sonarsource DOT com
- ~
- ~ SonarQube is free software; you can redistribute it and/or
- ~ modify it under the terms of the GNU Lesser General Public
- ~ License as published by the Free Software Foundation; either
- ~ version 3 of the License, or (at your option) any later version.
- ~
- ~ SonarQube is distributed in the hope that it will be useful,
- ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
- ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- ~ Lesser General Public License for more details.
- ~
- ~ You should have received a copy of the GNU Lesser General Public License
- ~ along with this program; if not, write to the Free Software Foundation,
- ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- -->
-
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mappei.dtd">
<mapper namespace="org.sonar.core.issue.db.IssueChangeMapper">
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");