diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-12-23 12:21:14 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-12-23 12:21:14 +0100 |
commit | 676932e588e925e22da9f5b83313607258f392df (patch) | |
tree | a1ac17efa0a7f008a6e39591c3860e3ca1b36007 /sonar-core | |
parent | 193260715b52e175f6875a4e0056cebdd5d30fa3 (diff) | |
download | sonarqube-676932e588e925e22da9f5b83313607258f392df.tar.gz sonarqube-676932e588e925e22da9f5b83313607258f392df.zip |
SONAR-4535 Reindex active rule note update
Diffstat (limited to 'sonar-core')
4 files changed, 50 insertions, 18 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 2b8b69feed3..1ab38d9a113 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 @@ -204,23 +204,36 @@ public class ActiveRuleDao implements ServerComponent { return dtosList; } - public List<ActiveRuleParamDto> selectParamsByRuleIds(List<Integer> ids) { + public List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId) { SqlSession session = mybatis.openSession(); try { - return selectParamsByRuleIds(ids, session); + return selectParamsByActiveRuleId(activeRuleId, session); } finally { MyBatis.closeQuietly(session); } } - public List<ActiveRuleParamDto> selectParamsByRuleIds(Collection<Integer> ids, SqlSession session) { - if (ids.isEmpty()) { + public List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectParamsByActiveRuleId(activeRuleId); + } + + public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(List<Integer> activeRuleIds) { + SqlSession session = mybatis.openSession(); + try { + return selectParamsByActiveRuleIds(activeRuleIds, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(Collection<Integer> activeRuleIds, SqlSession session) { + if (activeRuleIds.isEmpty()) { return Collections.emptyList(); } List<ActiveRuleParamDto> dtosList = newArrayList(); - List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(ids), 1000); + List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(activeRuleIds), 1000); for (List<Integer> idsPartition : idsPartitionList) { - List<ActiveRuleParamDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectParamsByRuleIds", newArrayList(idsPartition)); + List<ActiveRuleParamDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectParamsByActiveRuleIds", newArrayList(idsPartition)); dtosList.addAll(dtos); } return dtosList; diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleMapper.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleMapper.java index 34050e6da9e..dd142cd99bc 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleMapper.java @@ -24,6 +24,8 @@ import org.apache.ibatis.annotations.Param; import javax.annotation.CheckForNull; +import java.util.List; + public interface ActiveRuleMapper { @CheckForNull @@ -32,6 +34,8 @@ public interface ActiveRuleMapper { @CheckForNull ActiveRuleDto selectByProfileAndRule(@Param("profileId") Integer profileId, @Param("ruleId") Integer ruleId); + List<ActiveRuleParamDto> selectParamsByActiveRuleId(Integer activeRuleId); + @CheckForNull ActiveRuleParamDto selectParamById(Integer activeRuleParamId); 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 ea158ba518f..66346a0f28e 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 @@ -106,22 +106,29 @@ <include refid="activeRuleColumns"/> from active_rules a <where> - and a.id in - <foreach collection="list" open="(" close=")" item="id" separator=","> - #{id} - </foreach> + (<foreach collection="list" item="id" open="(" separator=" or " close=")"> + a.id=#{id} + </foreach>) </where> </select> - <select id="selectParamsByRuleIds" parameterType="map" resultType="ActiveRuleParam"> + <select id="selectParamsByActiveRuleId" parameterType="Integer" 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> + p.active_rule_id=#{id} + </where> + </select> + + <select id="selectParamsByActiveRuleIds" parameterType="map" resultType="ActiveRuleParam"> + select + <include refid="activeRuleParamColumns"/> + from active_rule_parameters p + <where> + (<foreach collection="list" item="id" open="(" separator=" or " close=")"> + p.active_rule_id=#{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 abb6e9c8450..b1b9ca7b7d8 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 @@ -91,6 +91,14 @@ public class ActiveRuleDaoTest extends AbstractDaoTestCase { } @Test + public void select_params_by_active_rule_id() { + setupData("shared"); + + assertThat(dao.selectParamsByActiveRuleId(1)).hasSize(2); + assertThat(dao.selectParamsByActiveRuleId(2)).hasSize(1); + } + + @Test public void select_param_by_active_rule_and_key() { setupData("shared"); @@ -106,9 +114,9 @@ public class ActiveRuleDaoTest extends AbstractDaoTestCase { 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); + assertThat(dao.selectParamsByActiveRuleIds(ImmutableList.of(1))).hasSize(2); + assertThat(dao.selectParamsByActiveRuleIds(ImmutableList.of(2))).hasSize(1); + assertThat(dao.selectParamsByActiveRuleIds(ImmutableList.of(1, 2))).hasSize(3); } @Test |