diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2014-10-03 17:44:51 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2014-10-03 17:45:10 +0200 |
commit | 899f7efa859fa9f805eb82035be4b364826c5630 (patch) | |
tree | d61bca6eeec556772148e2395aa4d2acb859db90 /sonar-core | |
parent | 66db6f87003bd506d3b5b85a67b68029f84bb28a (diff) | |
download | sonarqube-899f7efa859fa9f805eb82035be4b364826c5630.tar.gz sonarqube-899f7efa859fa9f805eb82035be4b364826c5630.zip |
SONAR-5626 find and book next available analysis report
Diffstat (limited to 'sonar-core')
3 files changed, 39 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java index f54ff8e63a8..03493275fda 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java @@ -19,6 +19,7 @@ */ package org.sonar.core.computation.db; +import com.google.common.annotations.VisibleForTesting; import org.sonar.core.persistence.Dto; import javax.annotation.Nullable; @@ -30,6 +31,18 @@ public class AnalysisReportDto extends Dto<String> { private Status status; private String data; + public AnalysisReportDto() { + super(); + } + + @VisibleForTesting + public static AnalysisReportDto newForTests(Long id) { + AnalysisReportDto report = new AnalysisReportDto(); + report.id = id; + + return report; + } + public String getProjectKey() { return projectKey; } diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java index e777a3ba5f7..c3f061c071c 100644 --- a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java @@ -42,4 +42,9 @@ public interface AnalysisReportMapper { void cleanWithTruncate(); int update(AnalysisReportDto report); + + int updateWithBookingReport(@Param("id") Long id, @Param("updatedAt") Date updatedAt, @Param("availableStatus") AnalysisReportDto.Status availableStatus, + @Param("busyStatus") AnalysisReportDto.Status busyStatus); + + AnalysisReportDto selectById(Long id); } diff --git a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml index b0b437b8ff6..dbc90b8381b 100644 --- a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml @@ -3,10 +3,10 @@ <mapper namespace="org.sonar.core.computation.db.AnalysisReportMapper"> <sql id="reportColumns"> + <!-- the data report is not brought back by default as it could be too big in memory --> ar.id, ar.project_key as projectKey, ar.report_status as status, - ar.report_data as data, ar.created_at as createdAt, ar.updated_at as updatedAt </sql> @@ -22,10 +22,30 @@ set report_status=#{status}, updated_at=#{updatedAt} </update> + <update id="updateWithBookingReport" parameterType="map"> + update analysis_reports ar1 + set report_status=#{busyStatus}, + updated_at=#{updatedAt} + where ar1.id=#{id} and ar1.report_status=#{availableStatus} + and not exists( + select 1 + from analysis_reports ar2 + where ar1.project_key=ar2.project_key + and ar2.report_status=#{busyStatus} + ) + </update> + <delete id="cleanWithTruncate"> truncate table analysis_reports </delete> + <select id="selectById" resultType="AnalysisReport"> + select + <include refid="reportColumns"/> + from analysis_reports ar + where id = #{id} + </select> + <select id="selectByProjectKey" parameterType="String" resultType="AnalysisReport"> select <include refid="reportColumns"/> |