aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-13 14:47:29 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-13 14:47:29 +0100
commit20585b09427b7560f07fec3132f2081d55eda701 (patch)
treedb821f4bbf5ad476ef898254fb417deaa8860903 /sonar-core
parent874db94063251ecc6747f74b9ad185450d4c9e3f (diff)
downloadsonarqube-20585b09427b7560f07fec3132f2081d55eda701.tar.gz
sonarqube-20585b09427b7560f07fec3132f2081d55eda701.zip
SONAR-4535 Quality profile creation is now done in Java
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java7
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml9
-rw-r--r--sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java15
4 files changed, 40 insertions, 0 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 fb158675c08..a364ae1fcc7 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
@@ -43,6 +43,15 @@ public class QualityProfileDao implements ServerComponent {
}
}
+ public QualityProfileDto selectByNameAndLanguage(String name, String language) {
+ SqlSession session = mybatis.openSession();
+ try {
+ return session.getMapper(QualityProfileMapper.class).selectByNameAndLanguage(name, language);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
public void insert(QualityProfileDto dto, SqlSession session) {
session.getMapper(QualityProfileMapper.class).insert(dto);
}
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 15acccf2e0e..dcfe0b93337 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
@@ -20,12 +20,19 @@
package org.sonar.core.qualityprofile.db;
+import org.apache.ibatis.annotations.Param;
+
+import javax.annotation.CheckForNull;
+
import java.util.List;
public interface QualityProfileMapper {
List<QualityProfileDto> selectAll();
+ @CheckForNull
+ QualityProfileDto selectByNameAndLanguage(@Param("name") String name, @Param("language") String language);
+
void insert(QualityProfileDto dto);
void update(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 217ba29567b..cd44060bef0 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
@@ -17,6 +17,15 @@
from rules_profiles p
</select>
+ <select id="selectByNameAndLanguage" parameterType="map" resultType="QualityProfile">
+ select <include refid="profilesColumns"/>
+ from rules_profiles p
+ <where>
+ and p.name=#{name}
+ and p.language=#{language}
+ </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 315af5e11ac..69761aaef1d 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
@@ -63,6 +63,21 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase {
}
@Test
+ public void select_by_name_and_language() {
+ setupData("shared");
+
+ QualityProfileDto dto = dao.selectByNameAndLanguage("Sonar way", "java");
+ assertThat(dto.getId()).isEqualTo(1);
+ 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", "unknown"));
+ }
+
+ @Test
public void insert() {
setupData("shared");