diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-12-17 16:32:00 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-12-17 16:32:00 +0100 |
commit | ed30ff904722e105c8068cae3ff099756cd63c19 (patch) | |
tree | c215bccf91cfb85a5452a2c23cdb7d73c0af3d35 /sonar-core | |
parent | 8956adb51a551e175cfc66844676ba19cfd2aa17 (diff) | |
download | sonarqube-ed30ff904722e105c8068cae3ff099756cd63c19.tar.gz sonarqube-ed30ff904722e105c8068cae3ff099756cd63c19.zip |
SONAR-4535 List of profiles by project now uses Mybatis
Diffstat (limited to 'sonar-core')
9 files changed, 81 insertions, 22 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java index 7335a08f6e4..bcfcaeba288 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java @@ -45,6 +45,24 @@ public class QualityProfileDao implements ServerComponent { } } + public QualityProfileDto selectDefaultProfile(String language, String key) { + SqlSession session = mybatis.openSession(); + try { + return session.getMapper(QualityProfileMapper.class).selectDefaultProfile(language, key); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<QualityProfileDto> selectByProject(Long projectId, String propKeyPrefix) { + SqlSession session = mybatis.openSession(); + try { + return session.getMapper(QualityProfileMapper.class).selectByProject(projectId, propKeyPrefix); + } finally { + MyBatis.closeQuietly(session); + } + } + public QualityProfileDto selectById(Integer id) { SqlSession session = mybatis.openSession(); try { diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java index 4ed5e64361a..bcedfddc03d 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java @@ -32,12 +32,17 @@ public interface QualityProfileMapper { List<QualityProfileDto> selectAll(); @CheckForNull + QualityProfileDto selectDefaultProfile(@Param("language") String language, @Param("key") String key); + + @CheckForNull QualityProfileDto selectByNameAndLanguage(@Param("name") String name, @Param("language") String language); @CheckForNull QualityProfileDto selectById(@Param("id") Integer id); - List<ComponentDto> selectProjects(@Param("key") String propertyKey, @Param("value") String propertyValue); + List<ComponentDto> selectProjects(@Param("value") String propertyValue, @Param("key") String propertyKey); + + List<QualityProfileDto> selectByProject(@Param("projectId") Long projectId, @Param("key") String propertyKeyPrefix); void insert(QualityProfileDto dto); diff --git a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml index 69517926991..35d70cfe04e 100644 --- a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml @@ -34,6 +34,17 @@ </where> </select> + <select id="selectDefaultProfile" parameterType="Integer" resultType="QualityProfile"> + SELECT <include refid="profilesColumns"/> + FROM rules_profiles p + INNER JOIN properties prop ON prop.text_value = p.name + <where> + AND p.language=#{language} + AND prop.prop_key=#{key} + AND prop.resource_id IS NULL + </where> + </select> + <select id="selectProjects" parameterType="Integer" resultType="Component"> SELECT projects.id as id, projects.name as name, projects.kee as kee FROM projects projects @@ -45,6 +56,16 @@ </where> </select> + <select id="selectByProject" parameterType="map" resultType="QualityProfile"> + SELECT DISTINCT <include refid="profilesColumns"/> + FROM rules_profiles p + INNER JOIN properties prop ON prop.text_value = p.name + <where> + AND prop.resource_id=#{projectId} + AND prop.prop_key like #{key} + </where> + </select> + <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> INSERT INTO rules_profiles (name, language, parent_name, version, used_profile) VALUES (#{name}, #{language}, #{parent}, #{version}, #{used}) diff --git a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java index 8dc59e0337e..f64d63be7c0 100644 --- a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java @@ -47,7 +47,7 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase { QualityProfileDto dto1 = dtos.get(0); assertThat(dto1.getId()).isEqualTo(1); - assertThat(dto1.getName()).isEqualTo("Sonar way"); + assertThat(dto1.getName()).isEqualTo("Sonar Way"); assertThat(dto1.getLanguage()).isEqualTo("java"); assertThat(dto1.getParent()).isNull(); assertThat(dto1.getVersion()).isEqualTo(1); @@ -55,7 +55,7 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase { QualityProfileDto dto2 = dtos.get(1); assertThat(dto2.getId()).isEqualTo(2); - assertThat(dto2.getName()).isEqualTo("Sonar way"); + assertThat(dto2.getName()).isEqualTo("Sonar Way"); assertThat(dto2.getLanguage()).isEqualTo("js"); assertThat(dto2.getParent()).isNull(); assertThat(dto2.getVersion()).isEqualTo(1); @@ -63,19 +63,27 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase { } @Test + public void select_default_profile() { + setupData("shared"); + + assertThat(dao.selectDefaultProfile("java", "sonar.profile.java")).isNotNull(); + assertThat(dao.selectDefaultProfile("js", "sonar.profile.js")).isNull(); + } + + @Test public void select_by_name_and_language() { setupData("shared"); - QualityProfileDto dto = dao.selectByNameAndLanguage("Sonar way", "java"); + QualityProfileDto dto = dao.selectByNameAndLanguage("Sonar Way", "java"); assertThat(dto.getId()).isEqualTo(1); - assertThat(dto.getName()).isEqualTo("Sonar way"); + assertThat(dto.getName()).isEqualTo("Sonar Way"); assertThat(dto.getLanguage()).isEqualTo("java"); assertThat(dto.getParent()).isNull(); assertThat(dto.getVersion()).isEqualTo(1); assertThat(dto.isUsed()).isFalse(); - assertThat(dao.selectByNameAndLanguage("Sonar WAY", "java")).isNotNull(); - assertThat(dao.selectByNameAndLanguage("Sonar way", "unknown")).isNull(); + assertThat(dao.selectByNameAndLanguage("Sonar Way", "java")).isNotNull(); + assertThat(dao.selectByNameAndLanguage("Sonar Way", "unknown")).isNull(); } @Test @@ -84,7 +92,7 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase { QualityProfileDto dto = dao.selectById(1); assertThat(dto.getId()).isEqualTo(1); - assertThat(dto.getName()).isEqualTo("Sonar way"); + assertThat(dto.getName()).isEqualTo("Sonar Way"); assertThat(dto.getLanguage()).isEqualTo("java"); assertThat(dto.getParent()).isNull(); assertThat(dto.getVersion()).isEqualTo(1); @@ -97,7 +105,14 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase { public void select_projects() { setupData("projects"); - assertThat(dao.selectProjects("sonar.profile.java", "Sonar Way")).hasSize(2); + assertThat(dao.selectProjects("Sonar Way", "sonar.profile.java")).hasSize(2); + } + + @Test + public void select_by_project() { + setupData("projects"); + + assertThat(dao.selectByProject(1L, "sonar.profile.%")).hasSize(2); } @Test diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/delete-result.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/delete-result.xml index b43d589e9eb..4ee0c55136b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/delete-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/delete-result.xml @@ -1,6 +1,6 @@ <dataset> - <rules_profiles id="2" name="Sonar way" language="js" parent_name="[null]" version="1" + <rules_profiles id="2" name="Sonar Way" language="js" parent_name="[null]" version="1" used_profile="[false]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/insert-result.xml index c0190f3a5ad..291c7fde5ed 100644 --- a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/insert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/insert-result.xml @@ -1,9 +1,9 @@ <dataset> - <rules_profiles id="1" name="Sonar way" language="java" parent_name="[null]" version="1" + <rules_profiles id="1" name="Sonar Way" language="java" parent_name="[null]" version="1" used_profile="[false]"/> - <rules_profiles id="2" name="Sonar way" language="js" parent_name="[null]" version="1" + <rules_profiles id="2" name="Sonar Way" language="js" parent_name="[null]" version="1" used_profile="[false]"/> <rules_profiles id="3" name="Sonar Way with Findbugs" language="xoo" parent_name="Sonar Way" version="2" diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/projects.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/projects.xml index d2727cc36ba..9605c2377b1 100644 --- a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/projects.xml +++ b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/projects.xml @@ -1,10 +1,7 @@ <dataset> - <rules_profiles id="1" name="Sonar way" language="java" parent_name="[null]" version="1" - used_profile="[false]"/> - - <rules_profiles id="2" name="Sonar way" language="js" parent_name="[null]" version="1" - used_profile="[false]"/> + <rules_profiles id="1" name="Sonar Way" language="java" parent_name="[null]" version="1" used_profile="[false]"/> + <rules_profiles id="2" name="Sonar Way" language="js" parent_name="[null]" version="1" used_profile="[false]"/> <projects id="1" kee="org.codehaus.sonar:sonar" name="SonarQube"/> <projects id="2" kee="org.codehaus.sonar-plugins.java:java" name="SonarQube Java"/> @@ -15,8 +12,8 @@ <!-- Property used to know the default profile, should not be returned when searching for projects --> <properties id="3" prop_key="sonar.profile.java" text_value="Sonar Way" resource_id="[null]"/> - <properties id="4" prop_key="sonar.profile.js" text_value="Sonar Way" resource_id="3"/> - <properties id="5" prop_key="sonar.profile.js" text_value="Sonar Way" resource_id="4"/> + <properties id="4" prop_key="sonar.profile.js" text_value="Sonar Way" resource_id="1"/> + <properties id="5" prop_key="sonar.profile.js" text_value="Sonar Way" resource_id="2"/> <properties id="6" prop_key="sonar.profile.js" text_value="Sonar Way" resource_id="[null]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/shared.xml index 45e95e254d8..e4fd036f631 100644 --- a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/shared.xml @@ -1,9 +1,12 @@ <dataset> - <rules_profiles id="1" name="Sonar way" language="java" parent_name="[null]" version="1" + <rules_profiles id="1" name="Sonar Way" language="java" parent_name="[null]" version="1" used_profile="[false]"/> - <rules_profiles id="2" name="Sonar way" language="js" parent_name="[null]" version="1" + <rules_profiles id="2" name="Sonar Way" language="js" parent_name="[null]" version="1" used_profile="[false]"/> + <properties id="1" prop_key="sonar.profile.java" text_value="Sonar Way" resource_id="[null]"/> + <properties id="2" prop_key="sonar.profile.java" text_value="Sonar Way" resource_id="1"/> + </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/update-result.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/update-result.xml index 4f2bff4e53d..474f8d55e7b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/update-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/update-result.xml @@ -3,7 +3,7 @@ <rules_profiles id="1" name="New Sonar Way with Findbugs" language="js" parent_name="New Sonar Way" version="3" used_profile="[false]"/> - <rules_profiles id="2" name="Sonar way" language="js" parent_name="[null]" version="1" + <rules_profiles id="2" name="Sonar Way" language="js" parent_name="[null]" version="1" used_profile="[false]"/> </dataset> |