diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-12-16 16:13:39 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-12-16 16:13:39 +0100 |
commit | c8e35b404af75053d5e457f612f8aefe4bda7f5f (patch) | |
tree | 61090cca462615cf7fcb9128565cf1436cb6983d /sonar-core/src/main | |
parent | 705171c0d42cb1fbe930466a6c0a8e5291f7cff7 (diff) | |
download | sonarqube-c8e35b404af75053d5e457f612f8aefe4bda7f5f.tar.gz sonarqube-c8e35b404af75053d5e457f612f8aefe4bda7f5f.zip |
SONAR-4535 Projects associate to a quality profile now uses MyBatis
Diffstat (limited to 'sonar-core/src/main')
4 files changed, 34 insertions, 8 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 2fb00f2a0bc..55e112bee13 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -34,6 +34,7 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.model.MeasureData; import org.sonar.api.database.model.MeasureMapper; import org.sonar.api.database.model.MeasureModel; +import org.sonar.core.component.ComponentDto; import org.sonar.core.config.Logback; import org.sonar.core.dashboard.*; import org.sonar.core.dependency.DependencyDto; @@ -98,6 +99,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class); loadAlias(conf, "Author", AuthorDto.class); + loadAlias(conf, "Component", ComponentDto.class); loadAlias(conf, "Dashboard", DashboardDto.class); loadAlias(conf, "Dependency", DependencyDto.class); loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class); 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 38be39d73d2..7335a08f6e4 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 @@ -23,6 +23,7 @@ package org.sonar.core.qualityprofile.db; import org.apache.commons.lang.StringUtils; import org.apache.ibatis.session.SqlSession; import org.sonar.api.ServerComponent; +import org.sonar.core.component.ComponentDto; import org.sonar.core.persistence.MyBatis; import java.util.List; @@ -62,6 +63,15 @@ public class QualityProfileDao implements ServerComponent { } } + public List<ComponentDto> selectProjects(String propertyKey, String propertyValue) { + SqlSession session = mybatis.openSession(); + try { + return session.getMapper(QualityProfileMapper.class).selectProjects(propertyKey, propertyValue); + } 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 743841117b4..4ed5e64361a 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 @@ -21,6 +21,7 @@ package org.sonar.core.qualityprofile.db; import org.apache.ibatis.annotations.Param; +import org.sonar.core.component.ComponentDto; import javax.annotation.CheckForNull; @@ -36,6 +37,8 @@ public interface QualityProfileMapper { @CheckForNull QualityProfileDto selectById(@Param("id") Integer id); + List<ComponentDto> selectProjects(@Param("key") String propertyKey, @Param("value") String propertyValue); + 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 9afaeaffab1..d41f6b02ae4 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 @@ -13,24 +13,35 @@ </sql> <select id="selectAll" parameterType="map" resultType="QualityProfile"> - select <include refid="profilesColumns"/> - from rules_profiles p + SELECT <include refid="profilesColumns"/> + FROM rules_profiles p </select> <select id="selectByNameAndLanguage" parameterType="map" resultType="QualityProfile"> - select <include refid="profilesColumns"/> - from rules_profiles p + SELECT <include refid="profilesColumns"/> + FROM rules_profiles p <where> AND UPPER(p.name)=#{name} - and p.language=#{language} + AND p.language=#{language} </where> </select> <select id="selectById" parameterType="Integer" resultType="QualityProfile"> - select <include refid="profilesColumns"/> - from rules_profiles p + SELECT <include refid="profilesColumns"/> + FROM rules_profiles p <where> - and p.id=#{id} + AND p.id=#{id} + </where> + </select> + + <select id="selectProjects" parameterType="Integer" resultType="Component"> + SELECT projects.id as id, projects.name as name, projects.kee as key + FROM projects projects + LEFT JOIN properties ON properties.resource_id = projects.id + <where> + AND properties.resource_id IS NOT NULL + AND properties.prop_key=#{key} + AND properties.text_value like #{value} </where> </select> |