aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-06-12 17:25:50 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-06-12 17:30:46 +0200
commit7f1d0426458733fb7bde55e103a44ace814a5fe0 (patch)
treea52e80e30e7f37c82195eba7768b524adf64de95 /sonar-core
parent7ad750aa576edec8108ff2f0a1e7cc9541542f97 (diff)
downloadsonarqube-7f1d0426458733fb7bde55e103a44ace814a5fe0.tar.gz
sonarqube-7f1d0426458733fb7bde55e103a44ace814a5fe0.zip
SONAR-3755 Delete limitation of max number of issues when loading issue changes
(cherry picked from commit 9e1f713)
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java4
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml9
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java18
4 files changed, 31 insertions, 9 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
index 3061586f253..cf9e5c6a678 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
@@ -20,7 +20,6 @@
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;
@@ -30,11 +29,14 @@ import org.sonar.api.issue.internal.FieldDiffs;
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
*/
@@ -81,12 +83,13 @@ public class IssueChangeDao implements BatchComponent, ServerComponent {
}
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) {
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java
index b9c85f78fb1..edb57a03bcd 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java
@@ -23,7 +23,7 @@ package org.sonar.core.issue.db;
import org.apache.ibatis.annotations.Param;
import javax.annotation.CheckForNull;
-import java.util.Collection;
+
import java.util.List;
/**
@@ -43,7 +43,7 @@ public interface IssueChangeMapper {
/**
* 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);
diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
index 0d1c57ee136..1620663a1ff 100644
--- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
@@ -42,9 +42,12 @@
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>
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
index 239168c3cc1..95e524dfe40 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java
@@ -32,6 +32,7 @@ import java.util.Arrays;
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;
@@ -65,6 +66,22 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase {
}
@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");
@@ -77,7 +94,6 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase {
assertThat(dao.selectCommentByKey("UNKNOWN")).isNull();
}
-
@Test
public void selectIssueChangelog() {
setupData("shared");