summaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-04-24 10:19:30 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-04-24 10:19:30 +0200
commitd5e8c6cc4cee60aa29f0f403b294f67e9f98d008 (patch)
treebaa57765bb557f91a400d4846af6314f11b1f60c /sonar-core
parent25b225b1ed7081bdc11344cd746d376adcbcf9bd (diff)
downloadsonarqube-d5e8c6cc4cee60aa29f0f403b294f67e9f98d008.tar.gz
sonarqube-d5e8c6cc4cee60aa29f0f403b294f67e9f98d008.zip
SONAR-3755 Improve IssueFinder pagination
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/IssueDao.java14
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java3
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java4
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml8
5 files changed, 23 insertions, 14 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueDao.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueDao.java
index 941bf0873ae..3f2add7205f 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/IssueDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueDao.java
@@ -22,7 +22,6 @@ package org.sonar.core.issue;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
-import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
@@ -30,6 +29,7 @@ import org.sonar.api.issue.IssueQuery;
import org.sonar.core.persistence.MyBatis;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -102,28 +102,24 @@ public class IssueDao implements BatchComponent, ServerComponent {
public List<IssueDto> select(IssueQuery query) {
SqlSession session = mybatis.openSession();
try {
- return select(query, session);
+ return session.selectList("org.sonar.core.issue.IssueMapper.select", query);
} finally {
MyBatis.closeQuietly(session);
}
}
- public List<IssueDto> select(IssueQuery query, SqlSession session) {
- // TODO support ordering
-
- return session.selectList("org.sonar.core.issue.IssueMapper.select", query, new RowBounds(query.offset(), query.limit()));
- }
-
/**
* The returned IssueDto list contains only the issue id and the resource id
*/
public List<IssueDto> selectIssueIdsAndComponentsId(IssueQuery query, SqlSession session) {
// TODO support ordering
-
return session.selectList("org.sonar.core.issue.IssueMapper.selectIssueIdsAndComponentsId", query);
}
public Collection<IssueDto> selectByIds(Collection<Long> ids, SqlSession session) {
+ if (ids.isEmpty()) {
+ return Collections.emptyList();
+ }
List <List<Long>> idsPartition = Lists.partition(newArrayList(ids), 1000);
Map<String, List <List<Long>>> params = ImmutableMap.of("ids", idsPartition);
return session.selectList("org.sonar.core.issue.IssueMapper.selectByIds", params);
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
index 5e5d0f8d435..79e5d1b13c0 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
@@ -19,12 +19,14 @@
*/
package org.sonar.core.resource;
+import com.google.common.collect.Lists;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.component.Component;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.persistence.MyBatis;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -133,9 +135,13 @@ public class ResourceDao {
}
public Collection<Component> findByIds(Collection<Integer> ids) {
+ if (ids.isEmpty()) {
+ return Collections.emptyList();
+ }
SqlSession session = mybatis.openSession();
try {
- Collection<ResourceDto> resources = session.getMapper(ResourceMapper.class).selectResourcesById(ids);
+ List <List<Integer>> idsPartition = Lists.partition(newArrayList(ids), 1000);
+ Collection<ResourceDto> resources = session.getMapper(ResourceMapper.class).selectResourcesById(idsPartition);
Collection<Component> components = newArrayList();
for (ResourceDto resourceDto : resources) {
components.add(toComponent(resourceDto));
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java
index a5a1e603f7b..13093cce06c 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java
@@ -22,7 +22,6 @@ package org.sonar.core.resource;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.ResultHandler;
-import java.util.Collection;
import java.util.List;
public interface ResourceMapper {
@@ -54,7 +53,7 @@ public interface ResourceMapper {
/**
* @since3.6
*/
- List<ResourceDto> selectResourcesById(@Param("ids") Collection<Integer> ids);
+ List<ResourceDto> selectResourcesById(@Param("ids") List <List<Integer>> ids);
void insert(ResourceDto resource);
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
index 50996b16219..667549554be 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
@@ -31,6 +31,7 @@ import org.sonar.jpa.session.DatabaseSessionFactory;
import javax.persistence.Query;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -57,6 +58,9 @@ public class DefaultRuleFinder implements RuleFinder {
}
public Collection<Rule> findByIds(Collection<Integer> ruleIds) {
+ if (ruleIds.isEmpty()) {
+ return Collections.emptyList();
+ }
DatabaseSession session = sessionFactory.getSession();
StringBuilder hql = new StringBuilder().append("from ").append(Rule.class.getSimpleName()).append(" r where r.id in (:ids) and status<>:status ");
Query hqlQuery = session.createQuery(hql.toString())
diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
index 24482461298..ded87d52b8f 100644
--- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
@@ -76,9 +76,13 @@
</select>
<select id="selectResourcesById" parameterType="map" resultMap="resourceResultMap">
- select * from projects p where p.enabled=${_true} and p.id in
- <foreach item="id" index="index" collection="ids" open="(" separator="," close=")">#{id}
+ select * from projects p where p.enabled=${_true} and
+ <foreach collection="ids" open="p.id in (" close=")" item="list" separator=") or p.id in (" >
+ <foreach collection="list" item="element" separator=",">
+ #{element}
+ </foreach>
</foreach>
+
</select>
<select id="selectSnapshot" parameterType="long" resultMap="snapshotResultMap">