From caa0bff61111f0dcaf67b28d02afcb27e0eecee4 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 24 Dec 2013 17:17:12 +0100 Subject: SONAR-4535 Revert active rule use Java facade --- .../sonar/core/qualityprofile/db/ActiveRuleDao.java | 13 +++++++++++++ .../sonar/core/qualityprofile/db/ActiveRuleDto.java | 14 ++++++++++++++ .../core/qualityprofile/db/ActiveRuleMapper.java | 3 +++ .../core/qualityprofile/db/ActiveRuleMapper.xml | 10 +++++++++- .../core/qualityprofile/db/ActiveRuleDaoTest.java | 8 ++++++++ .../db/ActiveRuleDaoTest/select_parent.xml | 21 +++++++++++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/ActiveRuleDaoTest/select_parent.xml (limited to 'sonar-core/src') 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 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 FROM active_rules a - AND rule_id=#{ruleId} + AND a.rule_id=#{ruleId} + +