aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-10-31 14:40:32 -0500
committersonartech <sonartech@sonarsource.com>2022-11-05 20:03:18 +0000
commit9b62ebf3361b96a2d693660236f1bce89d71edfa (patch)
tree8837dc35b5e6dfafa7df62f62bf2c1e55688d87a /server/sonar-db-dao
parent717613ac072b0cb9b49fff79354b99f26060be72 (diff)
downloadsonarqube-9b62ebf3361b96a2d693660236f1bce89d71edfa.tar.gz
sonarqube-9b62ebf3361b96a2d693660236f1bce89d71edfa.zip
SONAR-16455 Merge measure's 'variation' and 'value'
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java13
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java13
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml5
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java58
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java8
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java6
10 files changed, 19 insertions, 113 deletions
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
index b4efadc12ec..7a6277851b4 100644
--- 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
@@ -44,8 +44,6 @@ public class LiveMeasureDto {
private String textValue;
@Nullable
private byte[] data;
- @Nullable
- private Double variation;
void setUuidForUpsert(@Nullable String s) {
this.uuidForUpsert = s;
@@ -126,16 +124,6 @@ public class LiveMeasureDto {
return this;
}
- @CheckForNull
- public Double getVariation() {
- return variation;
- }
-
- public LiveMeasureDto setVariation(@Nullable Double variation) {
- this.variation = variation;
- return this;
- }
-
@Override
public String toString() {
StringBuilder sb = new StringBuilder("LiveMeasureDto{");
@@ -143,7 +131,6 @@ public class LiveMeasureDto {
sb.append(", projectUuid='").append(projectUuid).append('\'');
sb.append(", metricUuid=").append(metricUuid);
sb.append(", value=").append(value);
- sb.append(", variation=").append(variation);
sb.append(", textValue='").append(textValue).append('\'');
sb.append(", data=").append(Arrays.toString(data));
sb.append('}');
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
index c930a899a6e..d2a435d966b 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
@@ -31,7 +31,6 @@ public class MeasureDto {
private Double value;
private String textValue;
private byte[] dataValue;
- private Double variation;
private String alertStatus;
private String alertText;
private String componentUuid;
@@ -89,16 +88,6 @@ public class MeasureDto {
}
@CheckForNull
- public Double getVariation() {
- return variation;
- }
-
- public MeasureDto setVariation(@Nullable Double d) {
- variation = d;
- return this;
- }
-
- @CheckForNull
public String getAlertStatus() {
return alertStatus;
}
@@ -142,7 +131,6 @@ public class MeasureDto {
.add("value", value)
.add("textValue", textValue)
.add("dataValue", dataValue)
- .add("variation", variation)
.add("alertStatus", alertStatus)
.add("alertText", alertText)
.add("componentUuid", componentUuid)
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
index e4dba2dce99..45c5389bc33 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
@@ -79,18 +79,18 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
private static final String PROJECT_FILTER = " AND p.uuid=?";
- private static final String SQL_MEASURES = "SELECT m.name, pm.value, pm.variation, pm.text_value FROM live_measures pm " +
+ private static final String SQL_MEASURES = "SELECT m.name, pm.value, pm.text_value FROM live_measures pm " +
"INNER JOIN metrics m ON m.uuid = pm.metric_uuid " +
"WHERE pm.component_uuid = ? " +
"AND m.name IN ({metricNames}) " +
- "AND (pm.value IS NOT NULL OR pm.variation IS NOT NULL OR pm.text_value IS NOT NULL) " +
+ "AND (pm.value IS NOT NULL OR pm.text_value IS NOT NULL) " +
"AND m.enabled = ? ";
- private static final String SQL_NCLOC_LANGUAGE_DISTRIBUTION = "SELECT m.name, pm.value, pm.variation, pm.text_value FROM live_measures pm " +
+ private static final String SQL_NCLOC_LANGUAGE_DISTRIBUTION = "SELECT m.name, pm.value, pm.text_value FROM live_measures pm " +
"INNER JOIN metrics m ON m.uuid = pm.metric_uuid " +
"WHERE pm.component_uuid = ? " +
"AND m.name = ? " +
- "AND (pm.value IS NOT NULL OR pm.variation IS NOT NULL OR pm.text_value IS NOT NULL) " +
+ "AND (pm.value IS NOT NULL OR pm.text_value IS NOT NULL) " +
"AND m.enabled = ? ";
private static final String SQL_PROJECT_BRANCHES = "SELECT uuid FROM project_branches pb " +
@@ -109,8 +109,7 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
private static final boolean ENABLED = true;
private static final int FIELD_METRIC_NAME = 1;
private static final int FIELD_MEASURE_VALUE = 2;
- private static final int FIELD_MEASURE_VARIATION = 3;
- private static final int FIELD_MEASURE_TEXT_VALUE = 4;
+ private static final int FIELD_MEASURE_TEXT_VALUE = 3;
private final DbSession dbSession;
private final PreparedStatement measuresStatement;
@@ -310,7 +309,7 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
private static void readMeasure(ResultSet rs, Measures measures) throws SQLException {
String metricKey = rs.getString(FIELD_METRIC_NAME);
- Optional<Double> value = metricKey.startsWith("new_") ? getDouble(rs, FIELD_MEASURE_VARIATION) : getDouble(rs, FIELD_MEASURE_VALUE);
+ Optional<Double> value = getDouble(rs, FIELD_MEASURE_VALUE);
if (value.isPresent()) {
measures.addNumericMeasure(metricKey, value.get());
return;
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
index f0664d0a558..efdb50c965c 100644
--- 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
@@ -9,8 +9,7 @@
lm.metric_uuid as metricUuid,
lm.value as value,
lm.text_value as textValue,
- lm.measure_data as data,
- lm.variation as variation
+ lm.measure_data as data
</sql>
<select id="selectByComponentUuidsAndMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
@@ -118,7 +117,6 @@
metric_uuid,
value,
text_value,
- variation,
measure_data,
created_at,
updated_at
@@ -129,7 +127,6 @@
#{dto.metricUuid, jdbcType=VARCHAR},
#{dto.value, jdbcType=DOUBLE},
#{dto.textValue, jdbcType=VARCHAR},
- #{dto.variation, jdbcType=DOUBLE},
#{dto.data, jdbcType=BINARY},
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
@@ -139,7 +136,6 @@
<update id="update" parameterType="map">
update live_measures set
value = #{dto.value, jdbcType=DOUBLE},
- variation = #{dto.variation, jdbcType=DOUBLE},
text_value = #{dto.textValue, jdbcType=VARCHAR},
measure_data = #{dto.data, jdbcType=BINARY},
updated_at = #{now, jdbcType=BIGINT}
@@ -162,7 +158,6 @@
metric_uuid,
value,
text_value,
- variation,
measure_data,
created_at,
updated_at
@@ -173,20 +168,17 @@
#{dto.metricUuid, jdbcType=VARCHAR},
#{dto.value, jdbcType=DOUBLE},
#{dto.textValue, jdbcType=VARCHAR},
- #{dto.variation, jdbcType=DOUBLE},
#{dto.data, jdbcType=BINARY},
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
)
on conflict(component_uuid, metric_uuid) do update set
value = excluded.value,
- variation = excluded.variation,
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.variation is distinct from excluded.variation or
live_measures.text_value is distinct from excluded.text_value or
live_measures.measure_data is distinct from excluded.measure_data
</update>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
index 8fa3ab066b1..3071c777ecd 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
@@ -12,8 +12,7 @@
pm.text_value as textValue,
pm.alert_status as alertStatus,
pm.alert_text as alertText,
- pm.measure_data as dataValue,
- pm.variation_value_1 as variation
+ pm.measure_data as dataValue
</sql>
<select id="selectLastMeasure" parameterType="map" resultType="Measure">
@@ -106,7 +105,6 @@
text_value,
alert_status,
alert_text,
- variation_value_1,
measure_data)
VALUES (
#{uuid, jdbcType=VARCHAR},
@@ -117,7 +115,6 @@
#{textValue, jdbcType=VARCHAR},
#{alertStatus, jdbcType=VARCHAR},
#{alertText, jdbcType=VARCHAR},
- #{variation, jdbcType=DOUBLE},
#{dataValue, jdbcType=BINARY}
)
</insert>
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 89f6761b83c..3e0f5bcdde0 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -446,7 +446,6 @@ CREATE TABLE "LIVE_MEASURES"(
"METRIC_UUID" CHARACTER VARYING(40) NOT NULL,
"VALUE" DOUBLE PRECISION,
"TEXT_VALUE" CHARACTER VARYING(4000),
- "VARIATION" DOUBLE PRECISION,
"MEASURE_DATA" BINARY LARGE OBJECT,
"UPDATE_MARKER" CHARACTER VARYING(40),
"CREATED_AT" BIGINT NOT NULL,
@@ -690,7 +689,6 @@ CREATE TABLE "PROJECT_MEASURES"(
"ALERT_STATUS" CHARACTER VARYING(5),
"ALERT_TEXT" CHARACTER VARYING(4000),
"PERSON_ID" INTEGER,
- "VARIATION_VALUE_1" DOUBLE PRECISION,
"MEASURE_DATA" BINARY LARGE OBJECT,
"METRIC_UUID" CHARACTER VARYING(40) NOT NULL
);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
index d080a7223ba..5e9fabdafb0 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
@@ -291,14 +291,14 @@ public class LiveMeasureDaoTest {
MetricDto metric = db.measures().insertMetric();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- underTest.insert(db.getSession(), newLiveMeasure(file, metric).setValue(3.14).setVariation(0.1).setData("text_value"));
+ 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::getVariation,
+ LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
- .contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, 0.1, "text_value", "text_value");
+ .contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, "text_value", "text_value");
}
@Test
@@ -403,7 +403,6 @@ public class LiveMeasureDaoTest {
// update
dto.setValue(dto.getValue() + 1);
- dto.setVariation(dto.getVariation() + 10);
dto.setData(dto.getDataAsString() + "_new");
underTest.insertOrUpdate(db.getSession(), dto);
verifyPersisted(dto);
@@ -491,7 +490,6 @@ public class LiveMeasureDaoTest {
// update
dto.setValue(dto.getValue() + 1);
- dto.setVariation(dto.getVariation() + 10);
dto.setData(dto.getDataAsString() + "_new");
count = underTest.upsert(db.getSession(), dto);
assertThat(count).isOne();
@@ -565,54 +563,6 @@ public class LiveMeasureDaoTest {
}
@Test
- public void upsert_updates_row_if_variation_is_changed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setVariation(40.0);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setVariation(50.0);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- public void upsert_updates_row_if_variation_is_removed() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setVariation(40.0);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setVariation(null);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
- public void upsert_updates_row_if_variation_is_added() {
- if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
- return;
- }
- LiveMeasureDto dto = newLiveMeasure().setVariation(null);
- underTest.upsert(db.getSession(), dto);
-
- // update
- dto.setVariation(40.0);
- int count = underTest.upsert(db.getSession(), dto);
- assertThat(count).isOne();
- verifyPersisted(dto);
- verifyTableSize(1);
- }
-
- @Test
public void upsert_updates_row_if_value_is_changed() {
if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) {
return;
@@ -698,7 +648,7 @@ public class LiveMeasureDaoTest {
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", "variation");
+ "componentUuid", "projectUuid", "metricUuid", "value", "textValue", "data");
}
private void setupProjectsWithLoc() {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java
index 1937ea5cff7..3e5fb8c4bbc 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDtoTest.java
@@ -32,12 +32,9 @@ public class MeasureDtoTest {
public void test_getter_and_setter() {
underTest
.setValue(2d)
- .setData("text value")
- .setVariation(1d);
-
+ .setData("text value");
assertThat(underTest.getValue()).isEqualTo(2d);
assertThat(underTest.getData()).isNotNull();
- assertThat(underTest.getVariation()).isEqualTo(1d);
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
index ce4bbe75132..d5de79c7837 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
@@ -113,7 +113,7 @@ public class ProjectMeasuresIndexerIteratorTest {
c -> c.setKey("Project-Key").setName("Project Name"),
p -> p.setTagsString("platform,java"));
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines"));
- dbTester.measures().insertLiveMeasure(project, metric, m -> m.setVariation(10d));
+ dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(10d));
Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
@@ -139,7 +139,7 @@ public class ProjectMeasuresIndexerIteratorTest {
public void does_not_fail_when_quality_gate_has_no_value() {
ComponentDto project = dbTester.components().insertPrivateProject();
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status"));
- dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setVariation(null).setData((String) null));
+ dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData((String) null));
Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
@@ -210,8 +210,8 @@ public class ProjectMeasuresIndexerIteratorTest {
ComponentDto project = dbTester.components().insertPrivateProject();
dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d));
- dbTester.measures().insertLiveMeasure(project, leakMetric, m -> m.setValue(null).setVariation(20d));
- dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(null).setVariation(null));
+ dbTester.measures().insertLiveMeasure(project, leakMetric, m -> m.setValue(20d));
+ dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(null));
Map<String, Double> numericMeasures = createResultSetAndReturnDocsById().get(project.uuid()).getMeasures().getNumericMeasures();
assertThat(numericMeasures).containsOnly(entry(metric1.getKey(), 10d), entry(leakMetric.getKey(), 20d));
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 330f6cbb9e8..45da41f3e73 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
@@ -62,8 +62,7 @@ public class MeasureTesting {
.setComponentUuid(String.valueOf(cursor++))
.setProjectUuid(String.valueOf(cursor++))
.setData(String.valueOf(cursor++))
- .setValue((double) cursor++)
- .setVariation((double) cursor++);
+ .setValue((double) cursor++);
}
public static LiveMeasureDto newLiveMeasure(ComponentDto component, MetricDto metric) {
@@ -72,7 +71,6 @@ public class MeasureTesting {
.setComponentUuid(component.uuid())
.setProjectUuid(component.branchUuid())
.setData(String.valueOf(cursor++))
- .setValue((double) cursor++)
- .setVariation((double) cursor++);
+ .setValue((double) cursor++);
}
}