diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2013-12-20 15:15:29 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2013-12-20 15:26:05 +0100 |
commit | 8918854ac8abc7fb5131309edeec26a879f7e789 (patch) | |
tree | 2bce6f2daf0714b9c81f233adbf107e7c5e86c7a /sonar-core | |
parent | ab36a6ebf3c46f652d1b59cd3616bc6e97737f2c (diff) | |
download | sonarqube-8918854ac8abc7fb5131309edeec26a879f7e789.tar.gz sonarqube-8918854ac8abc7fb5131309edeec26a879f7e789.zip |
Use info collected by inheritance algo to update ES index
Diffstat (limited to 'sonar-core')
3 files changed, 92 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java index 39979aa1803..2b8b69feed3 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java @@ -20,10 +20,17 @@ package org.sonar.core.qualityprofile.db; +import com.google.common.collect.Lists; import org.apache.ibatis.session.SqlSession; import org.sonar.api.ServerComponent; import org.sonar.core.persistence.MyBatis; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static com.google.common.collect.Lists.newArrayList; + public class ActiveRuleDao implements ServerComponent { private final MyBatis mybatis; @@ -175,4 +182,48 @@ public class ActiveRuleDao implements ServerComponent { } } + public List<ActiveRuleDto> selectByIds(List<Integer> ids) { + SqlSession session = mybatis.openSession(); + try { + return selectByIds(ids, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleDto> selectByIds(Collection<Integer> ids, SqlSession session) { + if (ids.isEmpty()) { + return Collections.emptyList(); + } + List<ActiveRuleDto> dtosList = newArrayList(); + List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(ids), 1000); + for (List<Integer> idsPartition : idsPartitionList) { + List<ActiveRuleDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectByIds", newArrayList(idsPartition)); + dtosList.addAll(dtos); + } + return dtosList; + } + + public List<ActiveRuleParamDto> selectParamsByRuleIds(List<Integer> ids) { + SqlSession session = mybatis.openSession(); + try { + return selectParamsByRuleIds(ids, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleParamDto> selectParamsByRuleIds(Collection<Integer> ids, SqlSession session) { + if (ids.isEmpty()) { + return Collections.emptyList(); + } + List<ActiveRuleParamDto> dtosList = newArrayList(); + List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(ids), 1000); + for (List<Integer> idsPartition : idsPartitionList) { + List<ActiveRuleParamDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectParamsByRuleIds", newArrayList(idsPartition)); + dtosList.addAll(dtos); + } + return dtosList; + } + } diff --git a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml index bf24c81b336..ea158ba518f 100644 --- a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml @@ -101,6 +101,28 @@ DELETE FROM active_rule_parameters WHERE id=#{id} </update> + <select id="selectByIds" parameterType="map" resultType="ActiveRule"> + select + <include refid="activeRuleColumns"/> + from active_rules a + <where> + and a.id in + <foreach collection="list" open="(" close=")" item="id" separator=","> + #{id} + </foreach> + </where> + </select> + <select id="selectParamsByRuleIds" parameterType="map" resultType="ActiveRuleParam"> + select + <include refid="activeRuleParamColumns"/> + from active_rule_parameters p + <where> + and p.active_rule_id in + <foreach collection="list" open="(" close=")" item="id" separator=","> + #{id} + </foreach> + </where> + </select> </mapper> diff --git a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleDaoTest.java b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleDaoTest.java index e9fb37a87d2..abb6e9c8450 100644 --- a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/ActiveRuleDaoTest.java @@ -20,6 +20,7 @@ package org.sonar.core.qualityprofile.db; +import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import org.sonar.api.utils.DateUtils; @@ -53,6 +54,15 @@ public class ActiveRuleDaoTest extends AbstractDaoTestCase { } @Test + public void select_by_ids() { + setupData("shared"); + + assertThat(dao.selectByIds(ImmutableList.of(1))).hasSize(1); + assertThat(dao.selectByIds(ImmutableList.of(1, 2))).hasSize(2); + } + + + @Test public void select_by_profile_and_rule() { setupData("shared"); @@ -93,6 +103,15 @@ public class ActiveRuleDaoTest extends AbstractDaoTestCase { } @Test + public void select_params_by_active_rule_ids() { + setupData("shared"); + + assertThat(dao.selectParamsByRuleIds(ImmutableList.of(1))).hasSize(2); + assertThat(dao.selectParamsByRuleIds(ImmutableList.of(2))).hasSize(1); + assertThat(dao.selectParamsByRuleIds(ImmutableList.of(1, 2))).hasSize(3); + } + + @Test public void insert() { setupData("empty"); |