aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2022-02-28 09:27:47 +0100
committersonartech <sonartech@sonarsource.com>2022-03-02 20:03:47 +0000
commitbb4cc98d5f0b52c3caeb52fc4f772248be8d95fa (patch)
tree52bb9ec0e6368ef52c7d254ea6d06c4d9690e0f7 /server/sonar-db-dao
parentc1db3d50a5d01d86417d40a45e0ecc769134f0c8 (diff)
downloadsonarqube-bb4cc98d5f0b52c3caeb52fc4f772248be8d95fa.tar.gz
sonarqube-bb4cc98d5f0b52c3caeb52fc4f772248be8d95fa.zip
SONAR-13704 activity of a project now also display QG changes caused by changing issues status
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotQuery.java14
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml8
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotQueryTest.java7
7 files changed, 28 insertions, 12 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java
index 5f4f1178a89..324deefa08e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java
@@ -88,8 +88,8 @@ public class SnapshotDao implements Dao {
return mapper(session).selectSnapshotsByQuery(query);
}
- public Optional<SnapshotDto> selectOldestSnapshot(DbSession session, String componentUuid) {
- return mapper(session).selectOldestSnapshots(componentUuid, new RowBounds(0, 1))
+ public Optional<SnapshotDto> selectOldestAnalysis(DbSession session, String componentUuid) {
+ return mapper(session).selectOldestSnapshots(componentUuid, SnapshotDto.STATUS_PROCESSED, new RowBounds(0, 1))
.stream()
.findFirst();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
index 0bc32f5670f..0f72273fff9 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
@@ -33,6 +33,7 @@ public final class SnapshotDto {
*/
public static final String STATUS_UNPROCESSED = "U";
public static final String STATUS_PROCESSED = "P";
+ public static final String STATUS_LIVE_MEASURE_COMPUTED = "L";
public static final int MAX_VERSION_LENGTH = 100;
public static final int MAX_BUILD_STRING_LENGTH = 100;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java
index 83c00d4ccc8..dce8ea3cd84 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java
@@ -42,7 +42,7 @@ public interface SnapshotMapper {
List<SnapshotDto> selectSnapshotsByQuery(@Param("query") SnapshotQuery query);
- List<SnapshotDto> selectOldestSnapshots(@Param("componentUuid") String componentUuid, RowBounds rowBounds);
+ List<SnapshotDto> selectOldestSnapshots(@Param("componentUuid") String componentUuid, @Param("status") String status, RowBounds rowBounds);
List<ViewsSnapshotDto> selectSnapshotBefore(@Param("componentUuid") String componentUuid, @Param("date") long date);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotQuery.java
index 3b3ad28f693..70975f23ca8 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotQuery.java
@@ -19,6 +19,7 @@
*/
package org.sonar.db.component;
+import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -45,7 +46,7 @@ public final class SnapshotQuery {
private String componentUuid;
private Long createdAfter;
private Long createdBefore;
- private String status;
+ private List<String> statuses;
private String projectVersion;
private Boolean isLast;
private String sortField;
@@ -98,12 +99,17 @@ public final class SnapshotQuery {
}
@CheckForNull
- public String getStatus() {
- return status;
+ public List<String> getStatus() {
+ return statuses;
}
public SnapshotQuery setStatus(@Nullable String status) {
- this.status = status;
+ this.statuses = List.of(status);
+ return this;
+ }
+
+ public SnapshotQuery setStatuses(@Nullable List<String> statuses) {
+ this.statuses = statuses;
return this;
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
index 577547b007a..0c6d32cf627 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
@@ -91,7 +91,10 @@
</if>
<where>
<if test="query.status != null">
- AND s.status=#{query.status,jdbcType=VARCHAR}
+ AND s.status IN
+ <foreach collection="query.status" open="(" close=")" item="singleStatus" separator=" , ">
+ #{singleStatus, jdbcType=VARCHAR}
+ </foreach>
</if>
<if test="query.projectVersion != null">
AND s.version=#{query.projectVersion,jdbcType=VARCHAR}
@@ -140,7 +143,8 @@
<include refid="snapshotColumns" />
FROM snapshots s
<where>
- s.component_uuid=#{componentUuid,jdbcType=VARCHAR}
+ and s.component_uuid=#{componentUuid,jdbcType=VARCHAR}
+ and s.status = #{status,jdbcType=VARCHAR}
</where>
ORDER BY s.created_at ASC
</select>
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
index 3aab425c071..38577cf793e 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
@@ -319,11 +319,11 @@ public class SnapshotDaoTest {
newAnalysis(project).setCreatedAt(1L));
dbSession.commit();
- Optional<SnapshotDto> dto = underTest.selectOldestSnapshot(dbSession, project.uuid());
+ Optional<SnapshotDto> dto = underTest.selectOldestAnalysis(dbSession, project.uuid());
assertThat(dto).isNotEmpty();
assertThat(dto.get().getCreatedAt()).isOne();
- assertThat(underTest.selectOldestSnapshot(dbSession, "blabla")).isEmpty();
+ assertThat(underTest.selectOldestAnalysis(dbSession, "blabla")).isEmpty();
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotQueryTest.java
index df177cea1f8..d009aa475b4 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotQueryTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotQueryTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.db.component;
+import java.util.List;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,11 +41,15 @@ public class SnapshotQueryTest {
assertThat(query.getComponentUuid()).isEqualTo("abcd");
assertThat(query.getIsLast()).isTrue();
- assertThat(query.getStatus()).isEqualTo("P");
+ assertThat(query.getStatus()).isEqualTo(List.of("P"));
assertThat(query.getProjectVersion()).isEqualTo("1.0");
assertThat(query.getCreatedAfter()).isEqualTo(10L);
assertThat(query.getCreatedBefore()).isEqualTo(20L);
assertThat(query.getSortField()).isEqualTo("created_at");
assertThat(query.getSortOrder()).isEqualTo("asc");
+
+ query.setStatuses(List.of("P", "L"));
+
+ assertThat(query.getStatus()).isEqualTo(List.of("P", "L"));
}
}