diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-12-24 17:17:12 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-12-24 17:20:12 +0100 |
commit | caa0bff61111f0dcaf67b28d02afcb27e0eecee4 (patch) | |
tree | 97aa98141dc704e2c612f50ba863bb754257a2a6 /sonar-core/src | |
parent | 73e8c11630b7999342ab56072281719493efe2d1 (diff) | |
download | sonarqube-caa0bff61111f0dcaf67b28d02afcb27e0eecee4.tar.gz sonarqube-caa0bff61111f0dcaf67b28d02afcb27e0eecee4.zip |
SONAR-4535 Revert active rule use Java facade
Diffstat (limited to 'sonar-core/src')
6 files changed, 68 insertions, 1 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 069b07d7cf6..6bbd825ebf2 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 @@ -61,6 +61,19 @@ public class ActiveRuleDao implements ServerComponent { return session.getMapper(ActiveRuleMapper.class).selectByProfileAndRule(profileId, ruleId); } + public ActiveRuleDto selectParent(Integer activeRuleId) { + SqlSession session = mybatis.openSession(); + try { + return selectParent(activeRuleId, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public ActiveRuleDto selectParent(Integer activeRuleId, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectParent(activeRuleId); + } + public ActiveRuleParamDto selectParamById(Integer activeRuleParamId) { SqlSession session = mybatis.openSession(); try { diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java index 5b9176acd3f..29f024110e2 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java @@ -20,12 +20,17 @@ package org.sonar.core.qualityprofile.db; +import org.apache.commons.lang.StringUtils; + import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.util.Date; public class ActiveRuleDto { + public static final String INHERITED = "INHERITED"; + public static final String OVERRIDES = "OVERRIDES"; + private Integer id; private Integer profileId; private Integer ruleId; @@ -121,4 +126,13 @@ public class ActiveRuleDto { this.noteData = noteData; return this; } + + public boolean isInherited() { + return StringUtils.equals(INHERITED, inheritance); + } + + public boolean doesOverride() { + return StringUtils.equals(OVERRIDES, inheritance); + } + } 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 02d9a9b3604..e8a1333664d 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 @@ -35,6 +35,9 @@ public interface ActiveRuleMapper { List<ActiveRuleDto> selectByRuleId(Integer ruleId); + @CheckForNull + ActiveRuleDto selectParent(Integer id); + void insert(ActiveRuleDto dto); void update(ActiveRuleDto dto); 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 d7e0e5476b5..051e74fbdef 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 @@ -44,10 +44,18 @@ SELECT <include refid="activeRuleColumns"/> FROM active_rules a <where> - AND rule_id=#{ruleId} + AND a.rule_id=#{ruleId} </where> </select> + <select id="selectParent" parameterType="Integer" resultType="ActiveRule"> + SELECT <include refid="activeRuleColumns"/> + FROM active_rules a + INNER JOIN rules_profiles profile_parent ON profile_parent.id=a.profile_id + INNER JOIN rules_profiles profile_child ON profile_child.parent_name=profile_parent.name and profile_child.language=profile_parent.language + INNER JOIN active_rules active_rule_child ON active_rule_child.profile_id=profile_child.id and active_rule_child.id=#{childId} AND a.rule_id=active_rule_child.rule_id + </select> + <select id="selectParamById" parameterType="Integer" resultType="ActiveRuleParam"> SELECT <include refid="activeRuleParamColumns"/> FROM active_rule_parameters p 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 a2af9d31c67..dbdf7d9934a 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 @@ -89,6 +89,14 @@ public class ActiveRuleDaoTest extends AbstractDaoTestCase { } @Test + public void select_parent() { + setupData("select_parent"); + + ActiveRuleDto result = dao.selectParent(1); + assertThat(result.getId()).isEqualTo(2); + } + + @Test public void select_param_by_id() { setupData("shared"); diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/ActiveRuleDaoTest/select_parent.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/ActiveRuleDaoTest/select_parent.xml new file mode 100644 index 00000000000..962dc31bed5 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/ActiveRuleDaoTest/select_parent.xml @@ -0,0 +1,21 @@ +<dataset> + + <!-- Active rule child --> + <active_rules id="1" profile_id="1" rule_id="11" failure_level="2" inheritance="INHERITED" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="some note"/> + + <!-- Active rule parent --> + <active_rules id="2" profile_id="2" rule_id="11" failure_level="0" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="john" note_data="other note"/> + + <!-- Other Active rule on parent --> + <active_rules id="3" profile_id="2" rule_id="12" failure_level="1" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="other note"/> + + <rules_profiles id="1" name="Child" language="java" parent_name="Parent" version="1" + used_profile="[false]"/> + + <rules_profiles id="2" name="Parent" language="java" parent_name="[null]" version="1" + used_profile="[false]"/> + +</dataset> |