aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorEric Giffon <eric.giffon@sonarsource.com>2024-09-23 15:58:45 +0200
committersonartech <sonartech@sonarsource.com>2024-10-09 20:02:46 +0000
commita79666b02068f247ea26944d3ea0d0181365c3b7 (patch)
tree0a90e171f965d6257040150ec99cacceb9cfb4f8 /server/sonar-db-dao
parent449c62b7f35b191a320f8cfd7d378539c6864a51 (diff)
downloadsonarqube-a79666b02068f247ea26944d3ea0d0181365c3b7.tar.gz
sonarqube-a79666b02068f247ea26944d3ea0d0181365c3b7.zip
SONAR-22879 Remove code related to live_measures table
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java7
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/measure/LiveMeasureDaoIT.java419
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java32
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java7
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java35
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java85
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java139
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java55
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMainBranchLiveMeasureDto.java49
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java6
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml115
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml19
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java24
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java27
18 files changed, 1 insertions, 1040 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java
index 3240684ee32..f5096c9a414 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java
@@ -595,13 +595,6 @@ class BranchDaoIT {
ComponentDto project3 = projectData3.getMainBranchComponent();
db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setKey("p3-branch-1"));
- MetricDto unanalyzedC = db.measures().insertMetric(m -> m.setKey("unanalyzed_c"));
- MetricDto unanalyzedCpp = db.measures().insertMetric(m -> m.setKey("unanalyzed_cpp"));
- db.measures().insertLiveMeasure(project1, unanalyzedC);
- db.measures().insertLiveMeasure(project1, unanalyzedCpp);
- db.measures().insertLiveMeasure(project2, unanalyzedCpp);
- db.measures().insertLiveMeasure(project3, unanalyzedC);
-
assertThat(underTest.countPrBranchAnalyzedLanguageByProjectUuid(db.getSession()))
.extracting(PrBranchAnalyzedLanguageCountByProjectDto::getProjectUuid, PrBranchAnalyzedLanguageCountByProjectDto::getBranch,
PrBranchAnalyzedLanguageCountByProjectDto::getPullRequest)
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/measure/LiveMeasureDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/measure/LiveMeasureDaoIT.java
deleted file mode 100644
index 6b2796b348c..00000000000
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/measure/LiveMeasureDaoIT.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.measure;
-
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.IntStream;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.BranchType;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ProjectData;
-import org.sonar.db.metric.MetricDto;
-
-import static java.util.Arrays.asList;
-import static java.util.Collections.emptyList;
-import static java.util.Collections.singletonList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.groups.Tuple.tuple;
-import static org.sonar.api.measures.Metric.ValueType.DATA;
-import static org.sonar.api.measures.Metric.ValueType.INT;
-import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.measure.MeasureTesting.newLiveMeasure;
-
-class LiveMeasureDaoIT {
-
- @RegisterExtension
- private final DbTester db = DbTester.create(System2.INSTANCE);
-
- private final LiveMeasureDao underTest = db.getDbClient().liveMeasureDao();
- private MetricDto metric;
-
- private int branchId = 0;
-
- @BeforeEach
- void setUp() {
- metric = db.measures().insertMetric();
- }
-
- @Test
- void selectByComponentUuidsAndMetricUuids() {
- LiveMeasureDto measure1 = newLiveMeasure().setMetricUuid(metric.getUuid());
- LiveMeasureDto measure2 = newLiveMeasure().setMetricUuid(metric.getUuid());
- underTest.insert(db.getSession(), measure1);
- underTest.insert(db.getSession(), measure2);
-
- List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(),
- asList(measure1.getComponentUuid(), measure2.getComponentUuid()), singletonList(metric.getUuid()));
- assertThat(selected)
- .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricUuid,
- LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString)
- .containsExactlyInAnyOrder(
- tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricUuid(), measure1.getValue(),
- measure1.getDataAsString()),
- tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricUuid(), measure2.getValue(),
- measure2.getDataAsString()));
-
- assertThat(underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), emptyList(), singletonList(metric.getUuid()))).isEmpty();
- assertThat(underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList(measure1.getComponentUuid()), emptyList())).isEmpty();
- }
-
- @Test
- void selectByComponentUuidsAndMetricUuids_returns_empty_list_if_metric_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
- underTest.insert(db.getSession(), measure);
-
- String otherMetricUuid = metric.getUuid() + "other";
- List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(),
- singletonList(measure.getComponentUuid()), singletonList(otherMetricUuid));
-
- assertThat(selected).isEmpty();
- }
-
- @Test
- void selectByComponentUuidsAndMetricUuids_returns_empty_list_if_component_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure();
- underTest.insert(db.getSession(), measure);
-
- List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList("_missing_"),
- singletonList(measure.getMetricUuid()));
-
- assertThat(selected).isEmpty();
- }
-
- @Test
- void selectByComponentUuidAndMetricKey() {
- LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
- underTest.insert(db.getSession(), measure);
-
- Optional<LiveMeasureDto> selected = underTest.selectMeasure(db.getSession(), measure.getComponentUuid(), metric.getKey());
-
- assertThat(selected).isNotEmpty();
- assertThat(selected.get()).isEqualToComparingFieldByField(measure);
- }
-
- @Test
- void selectByComponentUuidAndMetricKey_return_empty_if_component_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
- underTest.insert(db.getSession(), measure);
-
- assertThat(underTest.selectMeasure(db.getSession(), "_missing_", metric.getKey())).isEmpty();
- }
-
- @Test
- void selectByComponentUuidAndMetricKey_return_empty_if_metric_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
- underTest.insert(db.getSession(), measure);
-
- assertThat(underTest.selectMeasure(db.getSession(), measure.getComponentUuid(), "_missing_")).isEmpty();
- }
-
- @Test
- void selectMeasure() {
- MetricDto metric = db.measures().insertMetric();
- LiveMeasureDto stored = newLiveMeasure().setMetricUuid(metric.getUuid());
- underTest.insert(db.getSession(), stored);
-
- // metric exists but not component
- assertThat(underTest.selectMeasure(db.getSession(), "_missing_", metric.getKey())).isEmpty();
-
- // component exists but not metric
- assertThat(underTest.selectMeasure(db.getSession(), stored.getComponentUuid(), "_missing_")).isEmpty();
-
- // component and metric don't match
- assertThat(underTest.selectMeasure(db.getSession(), "_missing_", "_missing_")).isEmpty();
-
- // matches
- assertThat(underTest.selectMeasure(db.getSession(), stored.getComponentUuid(), metric.getKey()).get())
- .isEqualToComparingFieldByField(stored);
- }
-
- @Test
- void selectMeasure_map_fields() {
- MetricDto metric = db.measures().insertMetric();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
- underTest.insert(db.getSession(), newLiveMeasure(file, metric).setValue(3.14).setData("text_value"));
-
- LiveMeasureDto result =
- underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not " +
- "found"));
-
- assertThat(result).as("Fail to map fields of %s", result.toString()).extracting(
- LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
- LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
- .contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, "text_value", "text_value");
- }
-
- @Test
- void insert_data() {
- byte[] data = "text_value".getBytes(StandardCharsets.UTF_8);
- MetricDto metric = db.measures().insertMetric();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
- LiveMeasureDto measure = newLiveMeasure(file, metric).setData(data);
-
- underTest.insert(db.getSession(), measure);
-
- LiveMeasureDto result =
- underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not " +
- "found"));
- assertThat(new String(result.getData(), StandardCharsets.UTF_8)).isEqualTo("text_value");
- assertThat(result.getDataAsString()).isEqualTo("text_value");
- }
-
- @Test
- void insertOrUpdate() {
- // insert
- LiveMeasureDto dto = newLiveMeasure();
- underTest.insertOrUpdate(db.getSession(), dto);
- verifyPersisted(dto);
- verifyTableSize(1);
-
- // update
- dto.setValue(dto.getValue() + 1);
- dto.setData(dto.getDataAsString() + "_new");
- underTest.insertOrUpdate(db.getSession(), dto);
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void deleteByComponentUuidExcludingMetricUuids() {
- LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("1");
- LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("2");
- LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("3");
- LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricUuid("3");
- underTest.insertOrUpdate(db.getSession(), measure1);
- underTest.insertOrUpdate(db.getSession(), measure2);
- underTest.insertOrUpdate(db.getSession(), measure3);
- underTest.insertOrUpdate(db.getSession(), measureOtherComponent);
-
- underTest.deleteByComponentUuidExcludingMetricUuids(db.getSession(), "C1", Arrays.asList("1", "2"));
-
- verifyTableSize(3);
- verifyPersisted(measure1);
- verifyPersisted(measure2);
- verifyPersisted(measureOtherComponent);
- }
-
- @Test
- void deleteByComponentUuidExcludingMetricUuids_with_empty_metrics() {
- LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("1");
- LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("2");
- LiveMeasureDto measureOnOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricUuid("2");
- underTest.insertOrUpdate(db.getSession(), measure1);
- underTest.insertOrUpdate(db.getSession(), measure2);
- underTest.insertOrUpdate(db.getSession(), measureOnOtherComponent);
-
- underTest.deleteByComponentUuidExcludingMetricUuids(db.getSession(), "C1", Collections.emptyList());
-
- verifyTableSize(1);
- verifyPersisted(measureOnOtherComponent);
- }
-
- @Test
- void upsert_inserts_or_updates_row() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
-
- // insert
- LiveMeasureDto dto = newLiveMeasure();
- int count = underTest.upsert(db.getSession(), dto);
- verifyPersisted(dto);
- verifyTableSize(1);
- assertThat(count).isOne();
-
- // update
- dto.setValue(dto.getValue() + 1);
- dto.setData(dto.getDataAsString() + "_new");
- count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void upsert_does_not_update_row_if_values_are_not_changed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
-
- LiveMeasureDto dto = newLiveMeasure();
- underTest.upsert(db.getSession(), dto);
-
- // update
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isZero();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void upsert_updates_row_if_lob_data_is_changed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
-
- LiveMeasureDto dto = newLiveMeasure().setData(RandomStringUtils.random(10_000));
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setData(RandomStringUtils.random(dto.getDataAsString().length() + 10));
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void upsert_does_not_update_row_if_lob_data_is_not_changed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setData(RandomStringUtils.random(10_000));
- underTest.upsert(db.getSession(), dto);
-
- // update
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isZero();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void upsert_updates_row_if_lob_data_is_removed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
-
- LiveMeasureDto dto = newLiveMeasure().setData(RandomStringUtils.random(10_000));
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setData((String) null);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void upsert_updates_row_if_value_is_changed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setValue(40.0);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setValue(50.0);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void upsert_updates_row_if_value_is_removed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setValue(40.0);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setValue(null);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void upsert_updates_row_if_value_is_added() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setValue(null);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setValue(40.0);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- void upsert_multiple_rows() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
-
- // insert 30
- List<LiveMeasureDto> inserted = new ArrayList<>();
- IntStream.range(0, 30).forEach(i -> inserted.add(newLiveMeasure()));
- for (LiveMeasureDto dto : inserted) {
- underTest.upsert(db.getSession(), dto);
- }
- verifyTableSize(30);
-
- // update 10 with new values, update 5 without any change and insert new 50
- List<LiveMeasureDto> upserted = new ArrayList<>();
- IntStream.range(0, 10).forEach(i -> {
- LiveMeasureDto d = inserted.get(i);
- upserted.add(d.setValue(d.getValue() + 123));
- });
- upserted.addAll(inserted.subList(10, 15));
- IntStream.range(0, 50).forEach(i -> upserted.add(newLiveMeasure()));
- for (LiveMeasureDto dto : upserted) {
- underTest.upsert(db.getSession(), dto);
- }
- db.getSession().commit();
- verifyTableSize(80);
- }
-
- private void verifyTableSize(int expectedSize) {
- assertThat(db.countRowsOfTable(db.getSession(), "live_measures")).isEqualTo(expectedSize);
- }
-
- private void verifyPersisted(LiveMeasureDto dto) {
- List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList(dto.getComponentUuid())
- , singletonList(dto.getMetricUuid()));
- assertThat(selected).hasSize(1);
- assertThat(selected.get(0)).isEqualToComparingOnlyGivenFields(dto,
- // do not compare the field "uuid", which is used only for insert, not select
- "componentUuid", "projectUuid", "metricUuid", "value", "textValue", "data");
- }
-}
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
index 56f593919df..594a941b51d 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
@@ -78,7 +78,6 @@ import org.sonar.db.event.EventTesting;
import org.sonar.db.issue.AnticipatedTransitionDto;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
-import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.measure.MeasureDto;
import org.sonar.db.measure.ProjectMeasureDto;
import org.sonar.db.metric.MetricDto;
@@ -324,15 +323,6 @@ project.getProjectDto().getUuid()), PurgeListener.EMPTY, new PurgeProfiler());
MetricDto metric1 = db.measures().insertMetric();
MetricDto metric2 = db.measures().insertMetric();
- LiveMeasureDto liveMeasureMetric1OnFile = db.measures().insertLiveMeasure(srcFile, metric1);
- LiveMeasureDto liveMeasureMetric2OnFile = db.measures().insertLiveMeasure(srcFile, metric2);
- LiveMeasureDto liveMeasureMetric1OnDir = db.measures().insertLiveMeasure(dir, metric1);
- LiveMeasureDto liveMeasureMetric2OnDir = db.measures().insertLiveMeasure(dir, metric2);
- LiveMeasureDto liveMeasureMetric1OnProject = db.measures().insertLiveMeasure(mainBranch, metric1);
- LiveMeasureDto liveMeasureMetric2OnProject = db.measures().insertLiveMeasure(mainBranch, metric2);
- LiveMeasureDto liveMeasureMetric1OnNonSelected = db.measures().insertLiveMeasure(enabledFile, metric1);
- LiveMeasureDto liveMeasureMetric2OnNonSelected = db.measures().insertLiveMeasure(enabledFile, metric2);
- assertThat(db.countRowsOfTable("live_measures")).isEqualTo(8);
db.measures().insertMeasure(srcFile,
m -> m.addValue(metric1.getKey(), RandomUtils.nextInt(50)).addValue(metric2.getKey(), RandomUtils.nextInt(50)));
@@ -370,18 +360,6 @@ project.getProjectDto().getUuid()), PurgeListener.EMPTY, new PurgeProfiler());
assertThat(db.countRowsOfTable("file_sources")).isOne();
assertThat(db.getDbClient().fileSourceDao().selectByFileUuid(dbSession, nonSelectedFileSource.getFileUuid())).isNotNull();
- // deletes live measure of selected
- assertThat(db.countRowsOfTable("live_measures")).isEqualTo(4);
- List<LiveMeasureDto> liveMeasureDtos = db.getDbClient().liveMeasureDao()
- .selectByComponentUuidsAndMetricUuids(dbSession, Set.of(srcFile.uuid(), dir.uuid(), mainBranch.uuid(), enabledFile.uuid()),
- Set.of(metric1.getUuid(), metric2.getUuid()));
- assertThat(liveMeasureDtos)
- .extracting(LiveMeasureDto::getComponentUuid)
- .containsOnly(enabledFile.uuid(), mainBranch.uuid());
- assertThat(liveMeasureDtos)
- .extracting(LiveMeasureDto::getMetricUuid)
- .containsOnly(metric1.getUuid(), metric2.getUuid());
-
// delete measures of selected
assertThat(db.countRowsOfTable("measures")).isEqualTo(2);
List<MeasureDto> measureDtos = Set.of(srcFile.uuid(), dir.uuid(), mainBranch.uuid(), enabledFile.uuid()).stream()
@@ -1714,29 +1692,21 @@ project.getProjectDto().getKey());
}
@Test
- void delete_live_measures_when_deleting_project() {
+ void delete_measures_when_deleting_project() {
MetricDto metric = db.measures().insertMetric();
ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto dir1 = db.components().insertComponent(newDirectory(project1, "path"));
- db.measures().insertLiveMeasure(project1, metric);
- db.measures().insertLiveMeasure(dir1, metric);
db.measures().insertMeasure(project1, m -> m.addValue(metric.getKey(), RandomUtils.nextInt(50)));
db.measures().insertMeasure(dir1, m -> m.addValue(metric.getKey(), RandomUtils.nextInt(50)));
ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto dir2 = db.components().insertComponent(newDirectory(project2, "path"));
- db.measures().insertLiveMeasure(project2, metric);
- db.measures().insertLiveMeasure(dir2, metric);
db.measures().insertMeasure(project2, m -> m.addValue(metric.getKey(), RandomUtils.nextInt(50)));
db.measures().insertMeasure(dir2, m -> m.addValue(metric.getKey(), RandomUtils.nextInt(50)));
underTest.deleteProject(dbSession, project1.uuid(), project1.qualifier(), project1.name(), project1.getKey());
- assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, List.of(project1.uuid(), dir1.uuid()),
- List.of(metric.getUuid()))).isEmpty();
- assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, List.of(project2.uuid(), dir2.uuid()),
- List.of(metric.getUuid()))).hasSize(2);
assertThat(dbClient.measureDao().selectByComponentUuid(dbSession, project1.uuid())).isEmpty();
assertThat(dbClient.measureDao().selectByComponentUuid(dbSession, dir1.uuid())).isEmpty();
assertThat(dbClient.measureDao().selectByComponentUuid(dbSession, project2.uuid())).isNotEmpty();
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
index c0852b111a5..2913c653a97 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
@@ -50,7 +50,6 @@ import org.sonar.db.issue.AnticipatedTransitionDao;
import org.sonar.db.issue.IssueChangeDao;
import org.sonar.db.issue.IssueDao;
import org.sonar.db.issue.IssueFixedDao;
-import org.sonar.db.measure.LiveMeasureDao;
import org.sonar.db.measure.MeasureDao;
import org.sonar.db.measure.ProjectMeasureDao;
import org.sonar.db.metric.MetricDao;
@@ -155,7 +154,6 @@ public class DaoModule extends Module {
IssueFixedDao.class,
IssuesDependencyDao.class,
MeasureDao.class,
- LiveMeasureDao.class,
ProjectMeasureDao.class,
MetricDao.class,
NewCodePeriodDao.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
index 200f3547cb4..46cb3d67623 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
@@ -50,7 +50,6 @@ import org.sonar.db.issue.AnticipatedTransitionDao;
import org.sonar.db.issue.IssueChangeDao;
import org.sonar.db.issue.IssueDao;
import org.sonar.db.issue.IssueFixedDao;
-import org.sonar.db.measure.LiveMeasureDao;
import org.sonar.db.measure.MeasureDao;
import org.sonar.db.measure.ProjectMeasureDao;
import org.sonar.db.metric.MetricDao;
@@ -177,7 +176,6 @@ public class DbClient {
private final AnalysisPropertiesDao analysisPropertiesDao;
private final QProfileEditUsersDao qProfileEditUsersDao;
private final QProfileEditGroupsDao qProfileEditGroupsDao;
- private final LiveMeasureDao liveMeasureDao;
private final WebhookDao webhookDao;
private final WebhookDeliveryDao webhookDeliveryDao;
private final NewCodePeriodDao newCodePeriodDao;
@@ -276,7 +274,6 @@ public class DbClient {
analysisPropertiesDao = getDao(map, AnalysisPropertiesDao.class);
qProfileEditUsersDao = getDao(map, QProfileEditUsersDao.class);
qProfileEditGroupsDao = getDao(map, QProfileEditGroupsDao.class);
- liveMeasureDao = getDao(map, LiveMeasureDao.class);
webhookDao = getDao(map, WebhookDao.class);
webhookDeliveryDao = getDao(map, WebhookDeliveryDao.class);
internalComponentPropertiesDao = getDao(map, InternalComponentPropertiesDao.class);
@@ -580,10 +577,6 @@ public class DbClient {
return qProfileEditGroupsDao;
}
- public LiveMeasureDao liveMeasureDao() {
- return liveMeasureDao;
- }
-
protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
return (K) map.get(clazz);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
index 9aafec712ab..6239cb6bde9 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
@@ -88,7 +88,6 @@ import org.sonar.db.issue.IssueMapper;
import org.sonar.db.issue.NewCodeReferenceIssueDto;
import org.sonar.db.issue.PrIssueDto;
import org.sonar.db.measure.LargestBranchNclocDto;
-import org.sonar.db.measure.LiveMeasureMapper;
import org.sonar.db.measure.MeasureMapper;
import org.sonar.db.measure.ProjectLocDistributionDto;
import org.sonar.db.measure.ProjectMeasureDto;
@@ -296,7 +295,6 @@ public class MyBatis {
ComponentMapper.class,
CveMapper.class,
CveCweMapper.class,
- LiveMeasureMapper.class,
DefaultQProfileMapper.class,
DuplicationMapper.class,
EntityMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java
deleted file mode 100644
index 6ebe886adf9..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.measure;
-
-import java.util.Comparator;
-
-public enum LiveMeasureComparator implements Comparator<LiveMeasureDto> {
- INSTANCE;
-
- @Override
- public int compare(LiveMeasureDto o1, LiveMeasureDto o2) {
- int componentUuidComp = o1.getComponentUuid().compareTo(o2.getComponentUuid());
- if (componentUuidComp != 0) {
- return componentUuidComp;
- }
- return o1.getMetricUuid().compareTo(o2.getMetricUuid());
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
deleted file mode 100644
index be285e98e4a..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.measure;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import org.sonar.api.utils.System2;
-import org.sonar.core.util.Uuids;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.dialect.Dialect;
-
-import static org.sonar.db.DatabaseUtils.executeLargeInputs;
-
-public class LiveMeasureDao implements Dao {
-
- private final System2 system2;
-
- public LiveMeasureDao(System2 system2) {
- this.system2 = system2;
- }
-
- public List<LiveMeasureDto> selectByComponentUuidsAndMetricUuids(DbSession dbSession, Collection<String> largeComponentUuids, Collection<String> metricUuids) {
- if (largeComponentUuids.isEmpty() || metricUuids.isEmpty()) {
- return Collections.emptyList();
- }
-
- return executeLargeInputs(
- largeComponentUuids,
- componentUuids -> mapper(dbSession).selectByComponentUuidsAndMetricUuids(componentUuids, metricUuids));
- }
-
- public Optional<LiveMeasureDto> selectMeasure(DbSession dbSession, String componentUuid, String metricKey) {
- LiveMeasureDto liveMeasureDto = mapper(dbSession).selectByComponentUuidAndMetricKey(componentUuid, metricKey);
- return Optional.ofNullable(liveMeasureDto);
- }
-
- public void insert(DbSession dbSession, LiveMeasureDto dto) {
- mapper(dbSession).insert(dto, Uuids.create(), system2.now());
- }
-
- public void insertOrUpdate(DbSession dbSession, LiveMeasureDto dto) {
- LiveMeasureMapper mapper = mapper(dbSession);
- long now = system2.now();
- if (mapper.update(dto, now) == 0) {
- mapper.insert(dto, Uuids.create(), now);
- }
- }
-
- /**
- * Similar to {@link #insertOrUpdate(DbSession, LiveMeasureDto)}, except that it triggers a single SQL request
- * <strong>This method should not be called unless {@link Dialect#supportsUpsert()} is true</strong>
- */
- public int upsert(DbSession dbSession, LiveMeasureDto dto) {
- dto.setUuidForUpsert(Uuids.create());
- return mapper(dbSession).upsert(dto, system2.now());
- }
-
- public void deleteByComponentUuidExcludingMetricUuids(DbSession dbSession, String componentUuid, List<String> excludedMetricUuids) {
- mapper(dbSession).deleteByComponentUuidExcludingMetricUuids(componentUuid, excludedMetricUuids);
- }
-
- private static LiveMeasureMapper mapper(DbSession dbSession) {
- return dbSession.getMapper(LiveMeasureMapper.class);
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java
deleted file mode 100644
index eb60db3dc2d..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.measure;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-public class LiveMeasureDto {
-
- private static final int MAX_TEXT_VALUE_LENGTH = 4000;
-
- /**
- * UUID generated only for UPSERT statements in PostgreSQL. It's never used
- * in SELECT or regular INSERT/UPDATE.
- */
- @Nullable
- private String uuidForUpsert;
-
- private String componentUuid;
- private String projectUuid;
- private String metricUuid;
- @Nullable
- private Double value;
- @Nullable
- private String textValue;
- @Nullable
- private byte[] data;
-
- void setUuidForUpsert(@Nullable String s) {
- this.uuidForUpsert = s;
- }
-
- public String getComponentUuid() {
- return componentUuid;
- }
-
- public LiveMeasureDto setComponentUuid(String s) {
- this.componentUuid = s;
- return this;
- }
-
- public String getProjectUuid() {
- return projectUuid;
- }
-
- public LiveMeasureDto setProjectUuid(String s) {
- this.projectUuid = s;
- return this;
- }
-
- public String getMetricUuid() {
- return metricUuid;
- }
-
- public LiveMeasureDto setMetricUuid(String uuid) {
- this.metricUuid = uuid;
- return this;
- }
-
- @CheckForNull
- public Double getValue() {
- return value;
- }
-
- public LiveMeasureDto setValue(@Nullable Double value) {
- this.value = value;
- return this;
- }
-
- @CheckForNull
- public String getTextValue() {
- return textValue;
- }
-
- @CheckForNull
- public byte[] getData() {
- return data;
- }
-
- @CheckForNull
- public String getDataAsString() {
- if (data != null) {
- return new String(data, StandardCharsets.UTF_8);
- }
- return textValue;
- }
-
- public LiveMeasureDto setData(@Nullable String data) {
- if (data == null) {
- this.textValue = null;
- this.data = null;
- } else if (data.length() > MAX_TEXT_VALUE_LENGTH) {
- this.textValue = null;
- this.data = data.getBytes(StandardCharsets.UTF_8);
- } else {
- this.textValue = data;
- this.data = null;
- }
- return this;
- }
-
- public LiveMeasureDto setData(@Nullable byte[] data) {
- this.textValue = null;
- this.data = data;
- return this;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("LiveMeasureDto{");
- sb.append("componentUuid='").append(componentUuid).append('\'');
- sb.append(", projectUuid='").append(projectUuid).append('\'');
- sb.append(", metricUuid=").append(metricUuid);
- sb.append(", value=").append(value);
- sb.append(", textValue='").append(textValue).append('\'');
- sb.append(", data=").append(Arrays.toString(data));
- sb.append('}');
- return sb.toString();
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
deleted file mode 100644
index 691168ad52e..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.measure;
-
-import java.util.Collection;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.ResultHandler;
-
-public interface LiveMeasureMapper {
-
- List<LiveMeasureDto> selectByComponentUuidsAndMetricUuids(
- @Param("componentUuids") Collection<String> componentUuids,
- @Param("metricUuids") Collection<String> metricUuids);
-
- LiveMeasureDto selectByComponentUuidAndMetricKey(
- @Param("componentUuid") String componentUuid,
- @Param("metricKey") String metricKey);
-
- void insert(
- @Param("dto") LiveMeasureDto dto,
- @Param("uuid") String uuid,
- @Param("now") long now);
-
- int update(
- @Param("dto") LiveMeasureDto dto,
- @Param("now") long now);
-
- int upsert(
- @Param("dto") LiveMeasureDto dto,
- @Param("now") long now);
-
- void deleteByComponentUuidExcludingMetricUuids(
- @Param("componentUuid") String componentUuid,
- @Param("excludedMetricUuids") List<String> excludedMetricUuids);
-
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMainBranchLiveMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMainBranchLiveMeasureDto.java
deleted file mode 100644
index 6644b1245bb..00000000000
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMainBranchLiveMeasureDto.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.measure;
-
-import javax.annotation.Nullable;
-
-public class ProjectMainBranchLiveMeasureDto {
- private String projectUuid;
- private String metricUuid;
- @Nullable
- private Double value;
- @Nullable
- private String textValue;
-
- public String getProjectUuid() {
- return projectUuid;
- }
-
- @Nullable
- public Double getValue() {
- return value;
- }
-
- @Nullable
- public String getTextValue() {
- return textValue;
- }
-
- public String getMetricUuid() {
- return metricUuid;
- }
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
index 68f55067421..696ad185515 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
@@ -158,15 +158,6 @@ class PurgeCommands {
});
profiler.stop();
- profiler.start("purgeDisabledComponents (live_measures)");
- executeLargeInputs(
- purgeMapper.selectDisabledComponentsWithLiveMeasures(rootComponentUuid),
- input -> {
- purgeMapper.deleteLiveMeasuresByComponentUuids(input);
- return input;
- });
- profiler.stop();
-
profiler.start("purgeDisabledComponents (measures)");
executeLargeInputs(
purgeMapper.selectDisabledComponentsWithMeasures(rootComponentUuid),
@@ -458,13 +449,6 @@ class PurgeCommands {
profiler.stop();
}
- void deleteLiveMeasures(String rootUuid) {
- profiler.start("deleteLiveMeasures (live_measures)");
- purgeMapper.deleteLiveMeasuresByProjectUuid(rootUuid);
- session.commit();
- profiler.stop();
- }
-
void deleteMeasures(String rootUuid) {
profiler.start("deleteMeasures (measures)");
purgeMapper.deleteMeasuresByBranchUuid(rootUuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
index 51e06e94f90..36bf5417a30 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -271,7 +271,6 @@ public class PurgeDao implements Dao {
commands.deleteFileSources(branchUuid);
commands.deleteCeActivity(branchUuid);
commands.deleteCeQueue(branchUuid);
- commands.deleteLiveMeasures(branchUuid);
commands.deleteMeasures(branchUuid);
commands.deleteNewCodePeriodsForBranch(branchUuid);
commands.deleteBranch(branchUuid);
@@ -295,7 +294,6 @@ public class PurgeDao implements Dao {
commands.deleteCeQueue(projectUuid);
commands.deleteWebhooks(projectUuid);
commands.deleteWebhookDeliveries(projectUuid);
- commands.deleteLiveMeasures(projectUuid);
commands.deleteMeasures(projectUuid);
commands.deleteProjectAlmSettings(projectUuid);
commands.deletePermissions(projectUuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
index 6053dc0fe32..00c96ee50bd 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
@@ -38,8 +38,6 @@ public interface PurgeMapper {
Set<String> selectDisabledComponentsWithUnresolvedIssues(@Param("branchUuid") String branchUuid);
- Set<String> selectDisabledComponentsWithLiveMeasures(@Param("branchUuid") String branchUuid);
-
Set<String> selectDisabledComponentsWithMeasures(@Param("branchUuid") String branchUuid);
void deleteAnalyses(@Param("analysisUuids") List<String> analysisUuids);
@@ -169,12 +167,8 @@ public interface PurgeMapper {
void deleteBranchByUuid(@Param("uuid") String uuid);
- void deleteLiveMeasuresByProjectUuid(@Param("projectUuid") String projectUuid);
-
void deleteMeasuresByBranchUuid(@Param("branchUuid") String branchUuid);
- void deleteLiveMeasuresByComponentUuids(@Param("componentUuids") List<String> componentUuids);
-
void deleteMeasuresByComponentUuids(@Param("componentUuids") List<String> componentUuids);
void deleteNewCodePeriodsByProjectUuid(String projectUuid);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
deleted file mode 100644
index bc684fd1e09..00000000000
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
+++ /dev/null
@@ -1,115 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.measure.LiveMeasureMapper">
-
- <sql id="columns">
- lm.component_uuid as componentUuid,
- lm.project_uuid as projectUuid,
- lm.metric_uuid as metricUuid,
- lm.value as value,
- lm.text_value as textValue,
- lm.measure_data as data
- </sql>
-
- <select id="selectByComponentUuidsAndMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
- select <include refid="columns"/> from live_measures lm
- where
- lm.metric_uuid in <foreach item="metricUuid" collection="metricUuids" open="(" separator=","
- close=")">#{metricUuid, jdbcType=VARCHAR}</foreach>
- and lm.component_uuid in
- <foreach item="componentUuid" collection="componentUuids" open="(" separator="," close=")">
- #{componentUuid, jdbcType=VARCHAR}
- </foreach>
- </select>
-
- <select id="selectByComponentUuidAndMetricKey" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
- select <include refid="columns"/> from live_measures lm
- inner join metrics m on m.uuid = lm.metric_uuid
- where
- m.name = #{metricKey, jdbcType=VARCHAR}
- and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR}
- </select>
-
- <insert id="insert" parameterType="map" useGeneratedKeys="false">
- insert into live_measures (
- uuid,
- component_uuid,
- project_uuid,
- metric_uuid,
- value,
- text_value,
- measure_data,
- created_at,
- updated_at
- ) values (
- #{uuid, jdbcType=VARCHAR},
- #{dto.componentUuid, jdbcType=VARCHAR},
- #{dto.projectUuid, jdbcType=VARCHAR},
- #{dto.metricUuid, jdbcType=VARCHAR},
- #{dto.value, jdbcType=DOUBLE},
- #{dto.textValue, jdbcType=VARCHAR},
- #{dto.data, jdbcType=BINARY},
- #{now, jdbcType=BIGINT},
- #{now, jdbcType=BIGINT}
- )
- </insert>
-
- <update id="update" parameterType="map">
- update live_measures set
- value = #{dto.value, jdbcType=DOUBLE},
- text_value = #{dto.textValue, jdbcType=VARCHAR},
- measure_data = #{dto.data, jdbcType=BINARY},
- updated_at = #{now, jdbcType=BIGINT}
- where
- component_uuid = #{dto.componentUuid, jdbcType=VARCHAR}
- and metric_uuid = #{dto.metricUuid, jdbcType=VARCHAR}
- </update>
-
- <update id="upsert" parameterType="map" useGeneratedKeys="false" databaseId="postgresql">
- insert into live_measures (
- uuid,
- component_uuid,
- project_uuid,
- metric_uuid,
- value,
- text_value,
- measure_data,
- created_at,
- updated_at
- ) values (
- #{dto.uuidForUpsert, jdbcType=VARCHAR},
- #{dto.componentUuid, jdbcType=VARCHAR},
- #{dto.projectUuid, jdbcType=VARCHAR},
- #{dto.metricUuid, jdbcType=VARCHAR},
- #{dto.value, jdbcType=DOUBLE},
- #{dto.textValue, jdbcType=VARCHAR},
- #{dto.data, jdbcType=BINARY},
- #{now, jdbcType=BIGINT},
- #{now, jdbcType=BIGINT}
- )
- on conflict(component_uuid, metric_uuid) do update set
- value = excluded.value,
- text_value = excluded.text_value,
- measure_data = excluded.measure_data,
- updated_at = excluded.updated_at
- where
- live_measures.value is distinct from excluded.value or
- live_measures.text_value is distinct from excluded.text_value or
- live_measures.measure_data is distinct from excluded.measure_data
- </update>
-
- <delete id="deleteByComponentUuidExcludingMetricUuids" parameterType="map">
- <include refid="sql_deleteByComponentUuidExcludingMetricUuids"/>
- </delete>
-
- <sql id="sql_deleteByComponentUuidExcludingMetricUuids">
- delete from live_measures
- where
- component_uuid = #{componentUuid, jdbcType=VARCHAR}
- <if test="!excludedMetricUuids.isEmpty()">
- and metric_uuid not in <foreach collection="excludedMetricUuids" item="metricUuid" open="(" close=")" separator=",">#{metricUuid,jdbcType=VARCHAR}</foreach>
- </if>
- </sql>
-
-</mapper>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
index 7e4ebdafb46..3700a8df647 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
@@ -114,16 +114,6 @@
resolution is null
</select>
- <select id="selectDisabledComponentsWithLiveMeasures" parameterType="map" resultType="String">
- select
- lm.component_uuid
- from live_measures lm
- inner join components p on
- p.uuid = lm.component_uuid
- and p.enabled = ${_false}
- and p.branch_uuid=#{branchUuid,jdbcType=VARCHAR}
- </select>
-
<select id="selectDisabledComponentsWithMeasures" parameterType="map" resultType="String">
select
m.component_uuid
@@ -637,19 +627,10 @@
delete from project_branches where uuid=#{uuid,jdbcType=VARCHAR}
</delete>
- <delete id="deleteLiveMeasuresByProjectUuid">
- delete from live_measures where project_uuid = #{projectUuid,jdbcType=VARCHAR}
- </delete>
-
<delete id="deleteMeasuresByBranchUuid">
delete from measures where branch_uuid = #{branchUuid,jdbcType=VARCHAR}
</delete>
- <delete id="deleteLiveMeasuresByComponentUuids">
- delete from live_measures where component_uuid in <foreach item="componentUuid" index="index" collection="componentUuids" open="("
- separator="," close=")">#{componentUuid, jdbcType=VARCHAR}</foreach>
- </delete>
-
<delete id="deleteMeasuresByComponentUuids">
delete from measures where component_uuid in <foreach item="componentUuid" index="index" collection="componentUuids" open="("
separator="," close=")">#{componentUuid, jdbcType=VARCHAR}</foreach>
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
index 3e71d2a924a..2e4dc73955e 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
@@ -35,7 +35,6 @@ import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
-import static org.sonar.db.measure.MeasureTesting.newLiveMeasure;
import static org.sonar.db.measure.MeasureTesting.newMeasure;
import static org.sonar.db.measure.MeasureTesting.newProjectMeasureDto;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
@@ -86,29 +85,6 @@ public class MeasureDbTester {
}
@SafeVarargs
- public final LiveMeasureDto insertLiveMeasure(ComponentDto component, MetricDto metric, Consumer<LiveMeasureDto>... consumers) {
- LiveMeasureDto dto = newLiveMeasure(component, metric);
- Arrays.stream(consumers).forEach(c -> c.accept(dto));
- dbClient.liveMeasureDao().insert(db.getSession(), dto);
- db.commit();
- return dto;
- }
-
- @SafeVarargs
- public final LiveMeasureDto insertLiveMeasure(BranchDto branchDto, MetricDto metric, Consumer<LiveMeasureDto>... consumers) {
- LiveMeasureDto dto = newLiveMeasure(branchDto, metric);
- Arrays.stream(consumers).forEach(c -> c.accept(dto));
- dbClient.liveMeasureDao().insert(db.getSession(), dto);
- db.commit();
- return dto;
- }
-
- @SafeVarargs
- public final LiveMeasureDto insertLiveMeasure(ProjectData projectData, MetricDto metric, Consumer<LiveMeasureDto>... consumers) {
- return insertLiveMeasure(projectData.getMainBranchComponent(), metric, consumers);
- }
-
- @SafeVarargs
public final MeasureDto insertMeasure(ComponentDto component, Consumer<MeasureDto>... consumers) {
return insertMeasure(component.uuid(), component.branchUuid(), consumers);
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
index 24379ae20bb..7457e5645b5 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
@@ -64,33 +64,6 @@ public class MeasureTesting {
.setValue((double) cursor++);
}
- public static LiveMeasureDto newLiveMeasure() {
- return new LiveMeasureDto()
- .setMetricUuid(String.valueOf(cursor++))
- .setComponentUuid(String.valueOf(cursor++))
- .setProjectUuid(String.valueOf(cursor++))
- .setData(String.valueOf(cursor++))
- .setValue((double) cursor++);
- }
-
- public static LiveMeasureDto newLiveMeasure(ComponentDto component, MetricDto metric) {
- return new LiveMeasureDto()
- .setMetricUuid(metric.getUuid())
- .setComponentUuid(component.uuid())
- .setProjectUuid(component.branchUuid())
- .setData(String.valueOf(cursor++))
- .setValue((double) cursor++);
- }
-
- public static LiveMeasureDto newLiveMeasure(BranchDto branchDto, MetricDto metric) {
- return new LiveMeasureDto()
- .setMetricUuid(metric.getUuid())
- .setComponentUuid(branchDto.getUuid())
- .setProjectUuid(branchDto.getProjectUuid())
- .setData(String.valueOf(cursor++))
- .setValue((double) cursor++);
- }
-
public static MeasureDto newMeasure() {
return newMeasure(String.valueOf(cursor++), String.valueOf(cursor++), "metric" + cursor++, (double) cursor++);
}