diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-08-14 11:23:46 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-08-24 14:00:31 +0200 |
commit | 7ea79ad0a5f9203a3f68169190429a232f5a5179 (patch) | |
tree | d4137255ed97d241b4c9e6e4248862aa304a8c51 /sonar-db | |
parent | 1d4769cd6fa1e0efad4b83d57581c535a1fab7a2 (diff) | |
download | sonarqube-7ea79ad0a5f9203a3f68169190429a232f5a5179.tar.gz sonarqube-7ea79ad0a5f9203a3f68169190429a232f5a5179.zip |
add RuleDao.selectById to be used by Views plugin
Diffstat (limited to 'sonar-db')
4 files changed, 22 insertions, 2 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java index a2e02898891..cf4be7e8278 100644 --- a/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/rule/RuleDao.java @@ -46,6 +46,15 @@ public class RuleDao implements Dao { } /** + * Retrieves a Rule by its id. + * + * Used by Views. + */ + public Optional<RuleDto> selectById(long id, DbSession session) { + return Optional.fromNullable(mapper(session).selectById(id)); + } + + /** * Select rules by keys, whatever their status. Returns an empty list * if the list of {@code keys} is empty, without any db round trip. */ diff --git a/sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java b/sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java index 84d2859b911..833fdedf37c 100644 --- a/sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/rule/RuleMapper.java @@ -38,7 +38,7 @@ public interface RuleMapper { List<RuleDto> selectBySubCharacteristicId(int characteristicId); - RuleDto selectById(Integer id); + RuleDto selectById(long id); RuleDto selectByKey(RuleKey ruleKey); diff --git a/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml b/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml index f03f57abced..bd3a3b6ac06 100644 --- a/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml @@ -59,7 +59,7 @@ where r.status != 'REMOVED' and r.plugin_name != 'manual' </select> - <select id="selectById" parameterType="Integer" resultType="Rule"> + <select id="selectById" parameterType="Long" resultType="Rule"> select <include refid="selectColumns"/> from rules r WHERE r.id=#{id} diff --git a/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java index 19b31f5b18c..8bd207050be 100644 --- a/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/rule/RuleDaoTest.java @@ -39,6 +39,7 @@ import org.sonar.test.DbTests; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.guava.api.Assertions.assertThat; @Category(DbTests.class) public class RuleDaoTest { @@ -63,6 +64,16 @@ public class RuleDaoTest { } @Test + public void selectById() { + dbTester.prepareDbUnit(getClass(), "shared.xml"); + + assertThat(underTest.selectById(55l, dbTester.getSession())).isAbsent(); + Optional<RuleDto> ruleDtoOptional = underTest.selectById(1l, dbTester.getSession()); + assertThat(ruleDtoOptional).isPresent(); + assertThat(ruleDtoOptional.get().getId()).isEqualTo(1); + } + + @Test public void selectOrFailByKey() { dbTester.prepareDbUnit(getClass(), "shared.xml"); |