diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-05-19 14:02:45 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-05-21 17:37:56 +0200 |
commit | a27d5efd0aa3ce834ee20bccd5044c3c36a3467a (patch) | |
tree | b5a5251ba6f53a3c7bad70f881557dddbbe213a6 /sonar-core | |
parent | 303f3f29a59629ea5644043fae2e01ec57656fab (diff) | |
download | sonarqube-a27d5efd0aa3ce834ee20bccd5044c3c36a3467a.tar.gz sonarqube-a27d5efd0aa3ce834ee20bccd5044c3c36a3467a.zip |
SONAR-6259 Persist components in db
Diffstat (limited to 'sonar-core')
4 files changed, 71 insertions, 21 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java index 5c934b98490..93a2feb82ee 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java @@ -49,6 +49,7 @@ public class ComponentDto implements Component { private String name; private String longName; private String language; + private String description; private boolean enabled = true; private Date createdAt; @@ -186,6 +187,16 @@ public class ComponentDto implements Component { } @CheckForNull + public String description() { + return description; + } + + public ComponentDto setDescription(@Nullable String description) { + this.description = description; + return this; + } + + @CheckForNull public Long parentProjectId() { return parentProjectId; } diff --git a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java index 643c34ddc19..be3f2b12412 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java @@ -94,14 +94,17 @@ public interface ComponentMapper { List<UuidWithProjectUuidDto> selectUuidsForQualifiers(@Param("qualifiers") String... qualifiers); /** + * Return all components of a project + */ + List<ComponentDto> selectComponentsFromProjectUuid(@Param("projectUuid") String projectUuid); + + /** * Return technical projects from a view or a sub-view */ List<String> selectProjectsFromView(@Param("viewUuidLikeQuery") String viewUuidLikeQuery, @Param("projectViewUuid") String projectViewUuid); long countById(long id); - void insert(ComponentDto rule); - List<ComponentDto> selectProvisionedProjects(Map<String, String> parameters, RowBounds rowBounds); int countProvisionedProjects(Map<String, String> parameters); @@ -109,4 +112,8 @@ public interface ComponentMapper { List<ComponentDto> selectGhostProjects(Map<String, String> parameters, RowBounds rowBounds); long countGhostProjects(Map<String, String> parameters); + + void insert(ComponentDto componentDto); + + void update(ComponentDto componentDto); } diff --git a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml index 54e3ffd9754..f7690f358a0 100644 --- a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml @@ -12,6 +12,7 @@ p.deprecated_kee as deprecatedKey, p.name as name, p.long_name as longName, + p.description as description, p.qualifier as qualifier, p.scope as scope, p.language as language, @@ -212,16 +213,14 @@ </where> </select> - <sql id="insertColumns"> - (kee, deprecated_kee, uuid, project_uuid, module_uuid, module_uuid_path, name, long_name, qualifier, scope, language, root_id, path, copy_resource_id, enabled, - created_at, authorization_updated_at) - </sql> - - <insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> - insert into projects <include refid="insertColumns"/> - values (#{kee}, #{deprecatedKey}, #{uuid}, #{projectUuid}, #{moduleUuid}, #{moduleUuidPath}, #{name}, #{longName}, #{qualifier}, #{scope}, - #{language}, #{parentProjectId}, #{path}, #{copyResourceId}, #{enabled}, #{createdAt}, #{authorizationUpdatedAt}) - </insert> + <select id="selectComponentsFromProjectUuid" parameterType="map" resultType="Component"> + SELECT <include refid="componentColumns"/> + FROM projects p + <where> + AND p.project_uuid=#{projectUuid} + AND p.enabled=${_true} + </where> + </select> <select id="selectProvisionedProjects" parameterType="map" resultType="Component"> select <include refid="componentColumns"/> @@ -266,14 +265,45 @@ inner join snapshots s1 on s1.project_id = p.id and s1.status='U' left join snapshots s2 on s2.project_id = p.id and s2.status='P' where - s2.id is null - and p.qualifier=#{qualifier} - and p.copy_resource_id is null - <if test="query!=null"> - and ( - UPPER(p.name) like #{query} - or UPPER(p.kee) like #{query} - ) - </if> + s2.id is null + and p.qualifier=#{qualifier} + and p.copy_resource_id is null + <if test="query!=null"> + and ( + UPPER(p.name) like #{query} + or UPPER(p.kee) like #{query} + ) + </if> </sql> + + <insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + INSERT INTO projects (kee, deprecated_kee, uuid, project_uuid, module_uuid, module_uuid_path, name, long_name, qualifier, scope, language, description, root_id, path, copy_resource_id, enabled, + created_at, authorization_updated_at) + VALUES (#{kee,jdbcType=VARCHAR}, #{deprecatedKey,jdbcType=VARCHAR}, #{uuid,jdbcType=VARCHAR}, #{projectUuid,jdbcType=VARCHAR}, #{moduleUuid,jdbcType=VARCHAR}, #{moduleUuidPath,jdbcType=VARCHAR}, + #{name,jdbcType=VARCHAR}, #{longName,jdbcType=VARCHAR}, #{qualifier,jdbcType=VARCHAR}, #{scope,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, + #{parentProjectId,jdbcType=BIGINT}, #{path,jdbcType=VARCHAR}, #{copyResourceId,jdbcType=BIGINT}, #{enabled,jdbcType=BOOLEAN}, + #{createdAt,jdbcType=TIMESTAMP}, #{authorizationUpdatedAt,jdbcType=BIGINT}) + </insert> + + <insert id="update" parameterType="Component"> + UPDATE projects SET + kee=#{kee,jdbcType=VARCHAR}, + deprecated_kee=#{deprecatedKey,jdbcType=VARCHAR}, + project_uuid=#{projectUuid,jdbcType=VARCHAR}, + module_uuid=#{moduleUuid,jdbcType=VARCHAR}, + module_uuid_path=#{moduleUuidPath,jdbcType=VARCHAR}, + name=#{name,jdbcType=VARCHAR}, + long_name=#{longName,jdbcType=VARCHAR}, + qualifier=#{qualifier,jdbcType=VARCHAR}, + scope=#{scope,jdbcType=VARCHAR}, + language=#{language,jdbcType=VARCHAR}, + description=#{description,jdbcType=VARCHAR}, + root_id=#{parentProjectId,jdbcType=BIGINT}, + path=#{path,jdbcType=VARCHAR}, + copy_resource_id=#{copyResourceId,jdbcType=BIGINT}, + enabled=#{enabled,jdbcType=BOOLEAN}, + authorization_updated_at=#{authorizationUpdatedAt,jdbcType=BIGINT} + WHERE uuid=#{uuid} + </insert> + </mapper> diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentDtoTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentDtoTest.java index 5383b6472d1..bd030b5dd78 100644 --- a/sonar-core/src/test/java/org/sonar/core/component/ComponentDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/component/ComponentDtoTest.java @@ -39,6 +39,7 @@ public class ComponentDtoTest { .setQualifier("FIL") .setScope("FIL") .setLanguage("java") + .setDescription("desc") .setPath("src/org/struts/RequestContext.java") .setCopyResourceId(5L) .setParentProjectId(3L) @@ -53,6 +54,7 @@ public class ComponentDtoTest { assertThat(componentDto.scope()).isEqualTo("FIL"); assertThat(componentDto.path()).isEqualTo("src/org/struts/RequestContext.java"); assertThat(componentDto.language()).isEqualTo("java"); + assertThat(componentDto.description()).isEqualTo("desc"); assertThat(componentDto.parentProjectId()).isEqualTo(3L); assertThat(componentDto.getCopyResourceId()).isEqualTo(5L); assertThat(componentDto.getAuthorizationUpdatedAt()).isEqualTo(123456789L); |