diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2020-04-27 12:42:10 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-05-25 20:05:20 +0000 |
commit | 6b41a01454b98c413889dc2400a9cddb3b390847 (patch) | |
tree | 6ccca99e10d77b453abc252835d6c70cfdb41d6c /server/sonar-db-dao/src | |
parent | 65e12a8ca01341c1ad00809d807bb8db0f5bf4b2 (diff) | |
download | sonarqube-6b41a01454b98c413889dc2400a9cddb3b390847.tar.gz sonarqube-6b41a01454b98c413889dc2400a9cddb3b390847.zip |
SONAR-13221 Metrics
Diffstat (limited to 'server/sonar-db-dao/src')
39 files changed, 295 insertions, 289 deletions
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 index 6e27c71e54f..71b33d8bf62 100644 --- 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 @@ -30,6 +30,6 @@ public enum LiveMeasureComparator implements Comparator<LiveMeasureDto> { if (componentUuidComp != 0) { return componentUuidComp; } - return Integer.compare(o1.getMetricId(), o2.getMetricId()); + 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 index a28d7f829ec..f84dce60a4f 100644 --- 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 @@ -44,23 +44,23 @@ public class LiveMeasureDao implements Dao { this.system2 = system2; } - public List<LiveMeasureDto> selectByComponentUuidsAndMetricIds(DbSession dbSession, Collection<String> largeComponentUuids, Collection<Integer> metricIds) { - if (largeComponentUuids.isEmpty() || metricIds.isEmpty()) { + public List<LiveMeasureDto> selectByComponentUuidsAndMetricUuids(DbSession dbSession, Collection<String> largeComponentUuids, Collection<String> metricUuis) { + if (largeComponentUuids.isEmpty() || metricUuis.isEmpty()) { return Collections.emptyList(); } return executeLargeInputs( largeComponentUuids, - componentUuids -> mapper(dbSession).selectByComponentUuidsAndMetricIds(componentUuids, metricIds)); + componentUuids -> mapper(dbSession).selectByComponentUuidsAndMetricUuids(componentUuids, metricUuis)); } - public void scrollSelectByComponentUuidAndMetricKeys(DbSession dbSession, String componentUuid, Collection<String> metricIds, + public void scrollSelectByComponentUuidAndMetricKeys(DbSession dbSession, String componentUuid, Collection<String> metricKeys, ResultHandler<LiveMeasureDto> handler) { - if (metricIds.isEmpty()) { + if (metricKeys.isEmpty()) { return; } - mapper(dbSession).scrollSelectByComponentUuidAndMetricKeys(componentUuid, metricIds, handler); + mapper(dbSession).scrollSelectByComponentUuidAndMetricKeys(componentUuid, metricKeys, handler); } public List<LiveMeasureDto> selectByComponentUuidsAndMetricKeys(DbSession dbSession, Collection<String> largeComponentUuids, Collection<String> metricKeys) { @@ -134,8 +134,8 @@ public class LiveMeasureDao implements Dao { return mapper(dbSession).upsert(dto, system2.now()); } - public void deleteByComponentUuidExcludingMetricIds(DbSession dbSession, String componentUuid, List<Integer> excludedMetricIds) { - mapper(dbSession).deleteByComponentUuidExcludingMetricIds(componentUuid, excludedMetricIds); + public void deleteByComponentUuidExcludingMetricUuids(DbSession dbSession, String componentUuid, List<String> excludedMetricUuids) { + mapper(dbSession).deleteByComponentUuidExcludingMetricUuids(componentUuid, excludedMetricUuids); } private static LiveMeasureMapper mapper(DbSession dbSession) { 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 e0b61db1025..87dc889c4a5 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 @@ -37,7 +37,7 @@ public class LiveMeasureDto { private String componentUuid; private String projectUuid; - private int metricId; + private String metricUuid; @Nullable private Double value; @Nullable @@ -69,12 +69,12 @@ public class LiveMeasureDto { return this; } - public int getMetricId() { - return metricId; + public String getMetricUuid() { + return metricUuid; } - public LiveMeasureDto setMetricId(int i) { - this.metricId = i; + public LiveMeasureDto setMetricUuid(String uuid) { + this.metricUuid = uuid; return this; } @@ -141,7 +141,7 @@ public class LiveMeasureDto { StringBuilder sb = new StringBuilder("LiveMeasureDto{"); sb.append("componentUuid='").append(componentUuid).append('\''); sb.append(", projectUuid='").append(projectUuid).append('\''); - sb.append(", metricId=").append(metricId); + sb.append(", metricUuid=").append(metricUuid); sb.append(", value=").append(value); sb.append(", variation=").append(variation); sb.append(", textValue='").append(textValue).append('\''); 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 index 3b26e2fdbcc..c0d88340ddd 100644 --- 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 @@ -29,9 +29,9 @@ import org.sonar.db.component.KeyType; public interface LiveMeasureMapper { - List<LiveMeasureDto> selectByComponentUuidsAndMetricIds( + List<LiveMeasureDto> selectByComponentUuidsAndMetricUuids( @Param("componentUuids") Collection<String> componentUuids, - @Param("metricIds") Collection<Integer> metricIds); + @Param("metricUuids") Collection<String> metricUuids); List<LiveMeasureDto> selectByComponentUuidsAndMetricKeys( @Param("componentUuids") Collection<String> componentUuids, @@ -77,9 +77,9 @@ public interface LiveMeasureMapper { @Param("dto") LiveMeasureDto dto, @Param("now") long now); - void deleteByComponentUuidExcludingMetricIds( + void deleteByComponentUuidExcludingMetricUuids( @Param("componentUuid") String componentUuid, - @Param("excludedMetricIds") List<Integer> excludedMetricIds); + @Param("excludedMetricUuids") List<String> excludedMetricUuids); void deleteByComponent(@Param("componentUuid") String componentUuid); 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 cd3f006f86f..9c460bbc0b3 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 @@ -36,7 +36,7 @@ public class MeasureDto { private String alertText; private String componentUuid; private String analysisUuid; - private int metricId; + private String metricUuid; public String getUuid() { return uuid; @@ -118,12 +118,12 @@ public class MeasureDto { return this; } - public int getMetricId() { - return metricId; + public String getMetricUuid() { + return metricUuid; } - public MeasureDto setMetricId(int metricId) { - this.metricId = metricId; + public MeasureDto setMetricUuid(String metricUuid) { + this.metricUuid = metricUuid; return this; } @@ -147,7 +147,7 @@ public class MeasureDto { .add("alertText", alertText) .add("componentUuid", componentUuid) .add("analysisUuid", analysisUuid) - .add("metricId", metricId) + .add("metricUuid", metricUuid) .toString(); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java index e9bd9a254cb..1a6fda6cdce 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java @@ -45,13 +45,13 @@ public class MeasureTreeQuery { private final Strategy strategy; @CheckForNull - private final Collection<Integer> metricIds; + private final Collection<String> metricUuids; private MeasureTreeQuery(Builder builder) { this.nameOrKeyQuery = builder.nameOrKeyQuery; this.qualifiers = builder.qualifiers == null ? null : newArrayList(builder.qualifiers); this.strategy = requireNonNull(builder.strategy); - this.metricIds = builder.metricIds; + this.metricUuids = builder.metricUuids; } @CheckForNull @@ -77,8 +77,8 @@ public class MeasureTreeQuery { } @CheckForNull - public Collection<Integer> getMetricIds() { - return metricIds; + public Collection<String> getMetricUuids() { + return metricUuids; } public String getUuidPath(ComponentDto component) { @@ -93,7 +93,7 @@ public class MeasureTreeQuery { } public boolean returnsEmpty() { - return (metricIds != null && metricIds.isEmpty()) || (qualifiers != null && qualifiers.isEmpty()); + return (metricUuids != null && metricUuids.isEmpty()) || (qualifiers != null && qualifiers.isEmpty()); } public static Builder builder() { @@ -109,7 +109,7 @@ public class MeasureTreeQuery { private Strategy strategy; @CheckForNull - private Collection<Integer> metricIds; + private Collection<String> metricUuids; private Builder() { } @@ -132,8 +132,8 @@ public class MeasureTreeQuery { /** * All the measures are returned if parameter is {@code null}. */ - public Builder setMetricIds(@Nullable Collection<Integer> metricIds) { - this.metricIds = metricIds; + public Builder setMetricUuids(@Nullable Collection<String> metricUuids) { + this.metricUuids = metricUuids; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java index 9ef4c4bb964..570ff3fca91 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java @@ -26,7 +26,7 @@ import static java.util.Objects.requireNonNull; public class PastMeasureDto { - private int metricId; + private String metricUuid; @CheckForNull private Double value; @@ -45,12 +45,12 @@ public class PastMeasureDto { return value != null; } - public int getMetricId() { - return metricId; + public String getMetricUuid() { + return metricUuid; } - PastMeasureDto setMetricId(int i) { - this.metricId = i; + PastMeasureDto setMetricUuid(String i) { + this.metricUuid = i; return this; } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java index 3089e1feb03..e30faebf81d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java @@ -28,14 +28,14 @@ import static java.util.Objects.requireNonNull; public class PastMeasureQuery { private final String componentUuid; - private final List<Integer> metricIds; + private final List<String> metricUuids; private final Long from; private final Long to; private final String status; - public PastMeasureQuery(String componentUuid, List<Integer> metricIds, @Nullable Long from, @Nullable Long to) { + public PastMeasureQuery(String componentUuid, List<String> metricUuids, @Nullable Long from, @Nullable Long to) { this.componentUuid = requireNonNull(componentUuid); - this.metricIds = requireNonNull(metricIds); + this.metricUuids = requireNonNull(metricUuids); this.from = from; this.to = to; this.status = SnapshotDto.STATUS_PROCESSED; @@ -45,8 +45,8 @@ public class PastMeasureQuery { return componentUuid; } - public List<Integer> getMetricIds() { - return metricIds; + public List<String> getMetricUuids() { + return metricUuids; } @CheckForNull 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 18daceed44b..a0a3d30d390 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 @@ -80,7 +80,7 @@ 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 " + - "INNER JOIN metrics m ON m.id = pm.metric_id " + + "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) " + diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java index b34ff180819..de33aa34361 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java @@ -49,20 +49,20 @@ public class CustomMeasureDao implements Dao { mapper(session).delete(uuid); } - public void deleteByMetricIds(DbSession session, List<Integer> metricIds) { - DatabaseUtils.executeLargeInputsWithoutOutput(metricIds, input -> mapper(session).deleteByMetricIds(metricIds)); + public void deleteByMetricUuids(DbSession session, List<String> metricUuids) { + DatabaseUtils.executeLargeInputsWithoutOutput(metricUuids, input -> mapper(session).deleteByMetricUuids(metricUuids)); } public Optional<CustomMeasureDto> selectByUuid(DbSession session, String uuid) { return ofNullable(mapper(session).selectByUuid(uuid)); } - public List<CustomMeasureDto> selectByMetricId(DbSession session, int metricId) { - return mapper(session).selectByMetricId(metricId); + public List<CustomMeasureDto> selectByMetricUuid(DbSession session, String metricUuid) { + return mapper(session).selectByMetricUuid(metricUuid); } - public int countByComponentIdAndMetricId(DbSession session, String componentUuid, int metricId) { - return mapper(session).countByComponentIdAndMetricId(componentUuid, metricId); + public int countByComponentIdAndMetricUuid(DbSession session, String componentUuid, String metricUuid) { + return mapper(session).countByComponentIdAndMetricUuid(componentUuid, metricUuid); } public List<CustomMeasureDto> selectByComponentUuid(DbSession session, String componentUuid, int offset, int limit) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java index b989a60ace4..da5c5643ac2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java @@ -24,7 +24,7 @@ import javax.annotation.Nullable; public class CustomMeasureDto { private String uuid = null; - private int metricId = 0; + private String metricUuid = null; private String componentUuid = null; private double value = 0.0D; private String textValue = null; @@ -37,8 +37,9 @@ public class CustomMeasureDto { return uuid; } - public void setUuid(String uuid) { + public CustomMeasureDto setUuid(String uuid) { this.uuid = uuid; + return this; } @CheckForNull @@ -79,12 +80,12 @@ public class CustomMeasureDto { return this; } - public int getMetricId() { - return metricId; + public String getMetricUuid() { + return metricUuid; } - public CustomMeasureDto setMetricId(int metricId) { - this.metricId = metricId; + public CustomMeasureDto setMetricUuid(String metricUuid) { + this.metricUuid = metricUuid; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java index f78faa88439..8081a413fae 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java @@ -30,11 +30,11 @@ public interface CustomMeasureMapper { void delete(String uuid); - void deleteByMetricIds(@Param("metricIds") List<Integer> metricIds); + void deleteByMetricUuids(@Param("metricUuids") List<String> metricUuids); CustomMeasureDto selectByUuid(String uuid); - List<CustomMeasureDto> selectByMetricId(int id); + List<CustomMeasureDto> selectByMetricUuid(String uuid); List<CustomMeasureDto> selectByComponentUuid(String s); @@ -44,5 +44,5 @@ public interface CustomMeasureMapper { int countByComponentUuid(String componentUuid); - int countByComponentIdAndMetricId(@Param("componentUuid") String componentUuid, @Param("metricId") int metricId); + int countByComponentIdAndMetricUuid(@Param("componentUuid") String componentUuid, @Param("metricUuid") String metricUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java index 9d021c02098..da78e49ff14 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java @@ -106,8 +106,8 @@ public class MetricDao implements Dao { return mapper(session).selectAvailableCustomMetricsByComponentUuid(projectUuid); } - public List<MetricDto> selectByIds(DbSession session, Set<Integer> idsSet) { - return executeLargeInputs(new ArrayList<>(idsSet), mapper(session)::selectByIds); + public List<MetricDto> selectByUuids(DbSession session, Set<String> uuidsSet) { + return executeLargeInputs(new ArrayList<>(uuidsSet), mapper(session)::selectByUuids); } private static class NotEmptyPredicate implements Predicate<String> { @@ -122,8 +122,8 @@ public class MetricDao implements Dao { return session.getMapper(MetricMapper.class); } - public void disableCustomByIds(final DbSession session, List<Integer> ids) { - executeLargeInputsWithoutOutput(ids, input -> mapper(session).disableByIds(input)); + public void disableCustomByUuids(final DbSession session, List<String> uuids) { + executeLargeInputsWithoutOutput(uuids, input -> mapper(session).disableByUuids(input)); } /** @@ -139,8 +139,8 @@ public class MetricDao implements Dao { } @CheckForNull - public MetricDto selectById(DbSession session, long id) { - return mapper(session).selectById(id); + public MetricDto selectByUuid(DbSession session, String uuid) { + return mapper(session).selectByUuid(uuid); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java index a211bd5098d..27cfe59c42a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java @@ -29,7 +29,7 @@ import static org.sonar.db.metric.MetricValidator.checkMetricName; public class MetricDto { - private Integer id; + private String uuid; private String kee; @@ -61,12 +61,12 @@ public class MetricDto { private Integer decimalScale; - public Integer getId() { - return id; + public String getUuid() { + return uuid; } - public MetricDto setId(Integer id) { - this.id = id; + public MetricDto setUuid(String uuid) { + this.uuid = uuid; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java index 6ef14a6cd65..c9656af8c16 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java @@ -27,9 +27,9 @@ import org.apache.ibatis.session.RowBounds; public interface MetricMapper { - MetricDto selectById(long id); + MetricDto selectByUuid(String uuid); - List<MetricDto> selectByIds(@Param("ids") List<Integer> ids); + List<MetricDto> selectByUuids(@Param("uuids") List<String> uuids); MetricDto selectByKey(@Param("key") String key); @@ -45,7 +45,7 @@ public interface MetricMapper { List<String> selectDomains(); - void disableByIds(@Param("ids") List<Integer> ids); + void disableByUuids(@Param("uuids") List<String> uuids); int disableByKey(@Param("key") String key); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java index b21fcc53532..ed191d46639 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java @@ -35,7 +35,7 @@ public class QualityGateConditionDto { private long qualityGateId; - private long metricId; + private String metricUuid; private String metricKey; @@ -65,12 +65,12 @@ public class QualityGateConditionDto { return this; } - public long getMetricId() { - return metricId; + public String getMetricUuid() { + return metricUuid; } - public QualityGateConditionDto setMetricId(long metricId) { - this.metricId = metricId; + public QualityGateConditionDto setMetricUuid(String metricUuid) { + this.metricUuid = metricUuid; return this; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index ebaec604d12..5e69f21aec5 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -732,7 +732,7 @@ <select id="selectPrivateProjectsWithNcloc" resultType="org.sonar.db.component.ProjectNclocDistributionDto"> select p.kee as kee, p.name as name, max(lm.value) as ncloc from live_measures lm - inner join metrics m on m.id = lm.metric_id + inner join metrics m on m.uuid = lm.metric_uuid inner join project_branches b on b.uuid = lm.component_uuid inner join components p on b.project_uuid = p.uuid where 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 cbc469e82db..33da39db11c 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 @@ -6,17 +6,17 @@ <sql id="columns"> lm.component_uuid as componentUuid, lm.project_uuid as projectUuid, - lm.metric_id as metricId, + lm.metric_uuid as metricUuid, lm.value as value, lm.text_value as textValue, lm.measure_data as data, lm.variation as variation </sql> - <select id="selectByComponentUuidsAndMetricIds" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto"> + <select id="selectByComponentUuidsAndMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto"> select <include refid="columns"/> from live_measures lm where - lm.metric_id in <foreach item="metricId" collection="metricIds" open="(" separator="," close=")">#{metricId, jdbcType=INTEGER}</foreach> + 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} @@ -25,7 +25,7 @@ <select id="selectByComponentUuidsAndMetricKeys" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto"> select <include refid="columns"/> from live_measures lm - inner join metrics m on m.id = lm.metric_id + inner join metrics m on m.uuid = lm.metric_uuid where m.name in <foreach item="metricKey" collection="metricKeys" open="(" separator="," close=")">#{metricKey, jdbcType=VARCHAR}</foreach> and lm.component_uuid in @@ -36,7 +36,7 @@ <select id="selectByComponentUuidAndMetricKeys" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto"> select <include refid="columns"/> from live_measures lm - inner join metrics m on m.id = lm.metric_id + inner join metrics m on m.uuid = lm.metric_uuid where m.name in <foreach item="metricKey" collection="metricKeys" open="(" separator="," close=")">#{metricKey, jdbcType=VARCHAR}</foreach> and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR} @@ -44,7 +44,7 @@ <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.id = lm.metric_id + inner join metrics m on m.uuid = lm.metric_uuid where m.name = #{metricKey, jdbcType=VARCHAR} and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR} @@ -54,7 +54,7 @@ select sum(sumncloc.maxncloc) from ( select b.project_uuid as projectUuid, max(lm.value) as maxncloc from live_measures lm - inner join metrics m on m.id = lm.metric_id + inner join metrics m on m.uuid = lm.metric_uuid inner join components p on p.uuid = lm.component_uuid inner join project_branches b on b.uuid = p.uuid <where> @@ -82,7 +82,7 @@ uuid, component_uuid, project_uuid, - metric_id, + metric_uuid, value, text_value, variation, @@ -93,7 +93,7 @@ #{uuid, jdbcType=VARCHAR}, #{dto.componentUuid, jdbcType=VARCHAR}, #{dto.projectUuid, jdbcType=VARCHAR}, - #{dto.metricId, jdbcType=INTEGER}, + #{dto.metricUuid, jdbcType=VARCHAR}, #{dto.value, jdbcType=DOUBLE}, #{dto.textValue, jdbcType=VARCHAR}, #{dto.variation, jdbcType=DOUBLE}, @@ -112,7 +112,7 @@ updated_at = #{now, jdbcType=BIGINT} where component_uuid = #{dto.componentUuid, jdbcType=VARCHAR} - and metric_id = #{dto.metricId, jdbcType=INTEGER} + and metric_uuid = #{dto.metricUuid, jdbcType=VARCHAR} </update> <delete id="deleteByComponent" parameterType="map"> @@ -126,7 +126,7 @@ uuid, component_uuid, project_uuid, - metric_id, + metric_uuid, value, text_value, variation, @@ -137,7 +137,7 @@ #{dto.uuidForUpsert, jdbcType=VARCHAR}, #{dto.componentUuid, jdbcType=VARCHAR}, #{dto.projectUuid, jdbcType=VARCHAR}, - #{dto.metricId, jdbcType=INTEGER}, + #{dto.metricUuid, jdbcType=VARCHAR}, #{dto.value, jdbcType=DOUBLE}, #{dto.textValue, jdbcType=VARCHAR}, #{dto.variation, jdbcType=DOUBLE}, @@ -145,7 +145,7 @@ #{now, jdbcType=BIGINT}, #{now, jdbcType=BIGINT} ) - on conflict(component_uuid, metric_id) do update set + on conflict(component_uuid, metric_uuid) do update set value = excluded.value, variation = excluded.variation, text_value = excluded.text_value, @@ -158,23 +158,23 @@ live_measures.measure_data is distinct from excluded.measure_data </update> - <delete id="deleteByComponentUuidExcludingMetricIds" parameterType="map"> - <include refid="sql_deleteByComponentUuidExcludingMetricIds"/> + <delete id="deleteByComponentUuidExcludingMetricUuids" parameterType="map"> + <include refid="sql_deleteByComponentUuidExcludingMetricUuids"/> </delete> - <sql id="sql_deleteByComponentUuidExcludingMetricIds"> + <sql id="sql_deleteByComponentUuidExcludingMetricUuids"> delete from live_measures where component_uuid = #{componentUuid, jdbcType=VARCHAR} - <if test="!excludedMetricIds.isEmpty()"> - and metric_id not in <foreach collection="excludedMetricIds" item="metricId" open="(" close=")" separator=",">#{metricId,jdbcType=INTEGER}</foreach> + <if test="!excludedMetricUuids.isEmpty()"> + and metric_uuid not in <foreach collection="excludedMetricUuids" item="metricUuid" open="(" close=")" separator=",">#{metricUuid,jdbcType=VARCHAR}</foreach> </if> </sql> <select id="scrollSelectByComponentUuidAndMetricKeys" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> select <include refid="columns"/> from live_measures lm - inner join metrics m on m.id = lm.metric_id + inner join metrics m on m.uuid = lm.metric_uuid where m.name in <foreach item="metricKey" collection="metricKeys" open="(" separator="," close=")">#{metricKey, jdbcType=VARCHAR}</foreach> and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR} @@ -186,9 +186,9 @@ <!-- TODO do we really need another join on components ? Using lm.project_uuid should be enough --> <include refid="org.sonar.db.component.ComponentMapper.selectDescendantsJoins"/> <where> - <if test="query.getMetricIds() != null"> - lm.metric_id in - <foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId,jdbcType=INTEGER}</foreach> + <if test="query.getMetricUuids() != null"> + lm.metric_uuid in + <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," close=")">#{metricUuid,jdbcType=VARCHAR}</foreach> </if> and p.enabled = ${_true} <if test="query.qualifiers != null"> @@ -211,9 +211,9 @@ select <include refid="columns"/> from live_measures lm inner join components p on p.uuid = lm.component_uuid and lm.component_uuid = #{baseUuid, jdbcType=VARCHAR} <where> - <if test="query.getMetricIds() != null"> - lm.metric_id in - <foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId,jdbcType=INTEGER}</foreach> + <if test="query.getMetricUuids() != null"> + lm.metric_uuid in + <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," close=")">#{metricUuid,jdbcType=VARCHAR}</foreach> </if> and p.enabled = ${_true} <if test="query.qualifiers != null"> 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 6eb7c3a238d..4aec1f108ad 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 @@ -5,7 +5,7 @@ <sql id="measureColumns"> pm.uuid as uuid, - pm.metric_id as metricId, + pm.metric_uuid as metricUuid, pm.component_uuid as componentUuid, pm.analysis_uuid as analysisUuid, pm.value as value, @@ -19,7 +19,7 @@ <select id="selectLastMeasure" parameterType="map" resultType="Measure"> select <include refid="measureColumns"/> from project_measures pm - inner join metrics m on m.id = pm.metric_id + inner join metrics m on m.uuid = pm.metric_uuid inner join snapshots s on s.uuid = pm.analysis_uuid where pm.component_uuid = #{componentUuid,jdbcType=VARCHAR} and @@ -30,7 +30,7 @@ <select id="selectMeasure" parameterType="map" resultType="Measure"> select <include refid="measureColumns"/> from project_measures pm - inner join metrics m on m.id = pm.metric_id + inner join metrics m on m.uuid = pm.metric_uuid inner join snapshots s on s.uuid = pm.analysis_uuid where pm.component_uuid = #{componentUuid,jdbcType=VARCHAR} and @@ -41,7 +41,7 @@ <sql id="selectByQueryCommonJoins"> inner join snapshots analysis on analysis.uuid = pm.analysis_uuid <if test="query.getMetricKeys() != null"> - inner join metrics m on m.id = pm.metric_id + inner join metrics m on m.uuid = pm.metric_uuid </if> </sql> @@ -57,7 +57,7 @@ <if test="query.to!=null"> and analysis.created_at<#{query.to, jdbcType=BIGINT} </if> - and pm.metric_id in <foreach item="metricId" collection="query.metricIds" open="(" separator="," close=")">#{metricId, jdbcType=VARCHAR}</foreach> + and pm.metric_uuid in <foreach item="metricUuid" collection="query.metricUuids" open="(" separator="," close=")">#{metricUuid, jdbcType=VARCHAR}</foreach> and analysis.status=#{query.status, jdbcType=VARCHAR} </select> @@ -65,7 +65,7 @@ insert into project_measures ( uuid, value, - metric_id, + metric_uuid, component_uuid, analysis_uuid, text_value, @@ -76,7 +76,7 @@ VALUES ( #{uuid, jdbcType=VARCHAR}, #{value, jdbcType=DOUBLE}, - #{metricId, jdbcType=INTEGER}, + #{metricUuid, jdbcType=VARCHAR}, #{componentUuid, jdbcType=VARCHAR}, #{analysisUuid, jdbcType=VARCHAR}, #{textValue, jdbcType=VARCHAR}, diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml index 1f57484d562..c2dc6a9be5b 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml @@ -4,7 +4,7 @@ <mapper namespace="org.sonar.db.measure.custom.CustomMeasureMapper"> <sql id="selectColumns"> m.uuid, - m.metric_id as metricId, + m.metric_uuid as metricUuid, m.component_uuid as componentUuid, m.value, m.text_value as textValue, @@ -21,11 +21,11 @@ where m.uuid=#{uuid} </select> - <select id="selectByMetricId" resultType="CustomMeasure"> + <select id="selectByMetricUuid" resultType="CustomMeasure"> select <include refid="selectColumns"/> from manual_measures m - where m.metric_id=#{metricId} + where m.metric_uuid=#{metricUuid} </select> <select id="selectByComponentUuid" resultType="CustomMeasure"> @@ -39,7 +39,7 @@ SELECT <include refid="selectColumns"/> FROM manual_measures m - INNER JOIN metrics metric ON metric.id=m.metric_id AND metric.name=#{metricKey} + INNER JOIN metrics metric ON metric.uuid=m.metric_uuid AND metric.name=#{metricKey} <where> m.text_value=#{textValue} </where> @@ -47,11 +47,11 @@ <insert id="insert" parameterType="CustomMeasure" useGeneratedKeys="false"> INSERT INTO manual_measures ( - uuid, metric_id, component_uuid, value, text_value, user_uuid, description, created_at, updated_at + uuid, metric_uuid, component_uuid, value, text_value, user_uuid, description, created_at, updated_at ) VALUES ( #{uuid, jdbcType=VARCHAR}, - #{metricId, jdbcType=INTEGER}, + #{metricUuid, jdbcType=VARCHAR}, #{componentUuid, jdbcType=VARCHAR}, #{value, jdbcType=DOUBLE}, #{textValue, jdbcType=VARCHAR}, @@ -72,11 +72,11 @@ where uuid = #{uuid} </update> - <delete id="deleteByMetricIds"> + <delete id="deleteByMetricUuids"> delete from manual_measures - where metric_id in - <foreach collection="metricIds" item="metricId" open="(" close=")" separator=","> - #{metricId} + where metric_uuid in + <foreach collection="metricUuids" item="metricUuid" open="(" close=")" separator=","> + #{metricUuid} </foreach> </delete> @@ -91,9 +91,9 @@ where m.component_uuid=#{componentUuid} </select> - <select id="countByComponentIdAndMetricId" resultType="Integer"> + <select id="countByComponentIdAndMetricUuid" resultType="Integer"> select count(1) from manual_measures m - where m.metric_id=#{metricId} and m.component_uuid=#{componentUuid} + where m.metric_uuid=#{metricUuid} and m.component_uuid=#{componentUuid} </select> </mapper> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml index 52b95a7179e..acd5b2ea81d 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml @@ -4,7 +4,7 @@ <mapper namespace="org.sonar.db.metric.MetricMapper"> <sql id="metricColumns"> - m.id, + m.uuid, m.name as kee, m.description, m.direction, @@ -60,7 +60,7 @@ select <include refid="metricColumns"/> from metrics m - left join manual_measures mm on mm.metric_id = m.id and mm.component_uuid=#{componentUuid} + left join manual_measures mm on mm.metric_uuid = m.uuid and mm.component_uuid=#{componentUuid} where m.enabled=${_true} and m.user_managed=${_true} and mm.uuid is null @@ -83,13 +83,12 @@ </where> </select> - <insert id="insert" parameterType="org.sonar.db.metric.MetricDto" useGeneratedKeys="true" keyColumn="id" - keyProperty="id"> + <insert id="insert" parameterType="org.sonar.db.metric.MetricDto" useGeneratedKeys="false"> INSERT INTO metrics ( - name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, worst_value, + uuid, name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, worst_value, best_value, optimized_best_value, hidden, delete_historical_data, decimal_scale) VALUES ( - #{kee, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER}, + #{uuid, jdbcType=VARCHAR}, #{kee, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER}, #{domain, jdbcType=VARCHAR}, #{shortName, jdbcType=VARCHAR}, #{qualitative, jdbcType=BOOLEAN}, #{valueType, jdbcType=VARCHAR}, #{userManaged, jdbcType=BOOLEAN}, #{enabled, jdbcType=BOOLEAN}, #{worstValue, jdbcType=DOUBLE}, #{bestValue, jdbcType=DOUBLE}, @@ -111,7 +110,7 @@ hidden=#{hidden, jdbcType=BOOLEAN}, qualitative=#{qualitative, jdbcType=BOOLEAN}, decimal_scale=#{decimalScale, jdbcType=INTEGER} - where id=#{id} + where uuid=#{uuid} </update> <select id="selectDomains" resultType="String"> @@ -120,14 +119,14 @@ where m.domain is not null and m.enabled=${_true} </select> - <update id="disableByIds"> + <update id="disableByUuids"> update metrics set enabled=${_false} <where> AND user_managed=${_true} - AND id in - <foreach item="id" collection="ids" open="(" separator="," close=")"> - #{id} + AND uuid in + <foreach item="uuid" collection="uuids" open="(" separator="," close=")"> + #{uuid} </foreach> </where> </update> @@ -151,24 +150,24 @@ </where> </select> - <select id="selectByIds" resultType="org.sonar.db.metric.MetricDto"> + <select id="selectByUuids" resultType="org.sonar.db.metric.MetricDto"> SELECT <include refid="metricColumns"/> FROM metrics m <where> - AND m.id in - <foreach item="id" collection="ids" open="(" separator="," close=")"> - #{id} + AND m.uuid in + <foreach item="uuid" collection="uuids" open="(" separator="," close=")"> + #{uuid} </foreach> </where> </select> - <select id="selectById" resultType="org.sonar.db.metric.MetricDto"> + <select id="selectByUuid" resultType="org.sonar.db.metric.MetricDto"> SELECT <include refid="metricColumns"/> FROM metrics m <where> - AND m.id=#{id} + AND m.uuid=#{uuid} </where> </select> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml index 47a12351ea4..e8bda0081ec 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml @@ -191,7 +191,7 @@ select orgUuid, sum(sumncloc.maxncloc) as ncloc from ( select b.project_uuid, p.organization_uuid as orgUuid, max(lm.value) as maxncloc from live_measures lm - inner join metrics m on m.id = lm.metric_id + inner join metrics m on m.uuid = lm.metric_uuid inner join components p on p.uuid = lm.component_uuid inner join project_branches b on b.uuid = p.uuid where diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml index c7b3c7099e3..9f3da11eb10 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml @@ -4,12 +4,12 @@ <mapper namespace="org.sonar.db.qualitygate.QualityGateConditionMapper"> <insert id="insert" parameterType="QualityGateCondition"> - insert into quality_gate_conditions (uuid, qgate_id, metric_id, operator, value_error, created_at, updated_at) - values (#{uuid}, #{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt}) + insert into quality_gate_conditions (uuid, qgate_id, metric_uuid, operator, value_error, created_at, updated_at) + values (#{uuid}, #{qualityGateId}, #{metricUuid}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt}) </insert> <sql id="conditionColumns"> - uuid, qgate_id as qualityGateId, metric_id as metricId, operator, value_error as errorThreshold, + uuid, qgate_id as qualityGateId, metric_uuid as metricUuid, operator, value_error as errorThreshold, created_at as createdAt, updated_at as updatedAt </sql> @@ -32,7 +32,7 @@ <update id="update" parameterType="QualityGateCondition"> update quality_gate_conditions set - metric_id=#{metricId}, + metric_uuid=#{metricUuid}, operator=#{operator}, value_error=#{errorThreshold}, updated_at=#{updatedAt} @@ -41,7 +41,7 @@ <delete id="deleteConditionsWithInvalidMetrics"> delete from quality_gate_conditions - where not exists (select 1 from metrics m where m.enabled=${_true} and m.id = metric_id) + where not exists (select 1 from metrics m where m.enabled=${_true} and m.uuid = metric_uuid) </delete> </mapper> diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index bd57c4aec5d..22a331ae4ab 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -418,21 +418,20 @@ CREATE TABLE "LIVE_MEASURES"( "UUID" VARCHAR(40) NOT NULL, "PROJECT_UUID" VARCHAR(50) NOT NULL, "COMPONENT_UUID" VARCHAR(50) NOT NULL, - "METRIC_ID" INTEGER NOT NULL, "VALUE" DOUBLE, "TEXT_VALUE" VARCHAR(4000), "VARIATION" DOUBLE, "MEASURE_DATA" BLOB, "UPDATE_MARKER" VARCHAR(40), "CREATED_AT" BIGINT NOT NULL, - "UPDATED_AT" BIGINT NOT NULL + "UPDATED_AT" BIGINT NOT NULL, + "METRIC_UUID" VARCHAR(40) NOT NULL ); ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID"); CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID"); -CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID"); +CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_UUID"); CREATE TABLE "MANUAL_MEASURES"( - "METRIC_ID" INTEGER NOT NULL, "VALUE" DOUBLE, "TEXT_VALUE" VARCHAR(4000), "USER_UUID" VARCHAR(255), @@ -440,13 +439,13 @@ CREATE TABLE "MANUAL_MEASURES"( "CREATED_AT" BIGINT, "UPDATED_AT" BIGINT, "COMPONENT_UUID" VARCHAR(50) NOT NULL, - "UUID" VARCHAR(40) NOT NULL + "UUID" VARCHAR(40) NOT NULL, + "METRIC_UUID" VARCHAR(40) NOT NULL ); ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID"); CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES"("COMPONENT_UUID"); CREATE TABLE "METRICS"( - "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), "NAME" VARCHAR(64) NOT NULL, "DESCRIPTION" VARCHAR(255), "DIRECTION" INTEGER DEFAULT 0 NOT NULL, @@ -461,9 +460,10 @@ CREATE TABLE "METRICS"( "OPTIMIZED_BEST_VALUE" BOOLEAN, "HIDDEN" BOOLEAN, "DELETE_HISTORICAL_DATA" BOOLEAN, - "DECIMAL_SCALE" INTEGER + "DECIMAL_SCALE" INTEGER, + "UUID" VARCHAR(40) NOT NULL ); -ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID"); +ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("UUID"); CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME"); CREATE TABLE "NEW_CODE_PERIODS"( @@ -674,7 +674,6 @@ CREATE INDEX "PROJECT_UUID" ON "PROJECT_MAPPINGS"("PROJECT_UUID"); CREATE TABLE "PROJECT_MEASURES"( "VALUE" DOUBLE, - "METRIC_ID" INTEGER NOT NULL, "ANALYSIS_UUID" VARCHAR(50) NOT NULL, "COMPONENT_UUID" VARCHAR(50) NOT NULL, "TEXT_VALUE" VARCHAR(4000), @@ -688,11 +687,12 @@ CREATE TABLE "PROJECT_MEASURES"( "VARIATION_VALUE_4" DOUBLE, "VARIATION_VALUE_5" DOUBLE, "MEASURE_DATA" BLOB, - "UUID" VARCHAR(40) NOT NULL + "UUID" VARCHAR(40) NOT NULL, + "METRIC_UUID" VARCHAR(40) NOT NULL ); ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID"); -CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID"); CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID"); +CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_UUID"); CREATE TABLE "PROJECT_QGATES"( "PROJECT_UUID" VARCHAR(40) NOT NULL, @@ -771,14 +771,14 @@ CREATE UNIQUE INDEX "QPROFILE_EDIT_USERS_UNIQUE" ON "QPROFILE_EDIT_USERS"("USER_ CREATE TABLE "QUALITY_GATE_CONDITIONS"( "QGATE_ID" INTEGER, - "METRIC_ID" INTEGER, "PERIOD" INTEGER, "OPERATOR" VARCHAR(3), "VALUE_ERROR" VARCHAR(64), "VALUE_WARNING" VARCHAR(64), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP, - "UUID" VARCHAR(40) NOT NULL + "UUID" VARCHAR(40) NOT NULL, + "METRIC_UUID" VARCHAR(40) NOT NULL ); ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID"); 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 5b0acf9ca51..83299dde0eb 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 @@ -64,30 +64,30 @@ public class LiveMeasureDaoTest { @Test public void selectByComponentUuidsAndMetricIds() { - LiveMeasureDto measure1 = newLiveMeasure().setMetricId(metric.getId()); - LiveMeasureDto measure2 = newLiveMeasure().setMetricId(metric.getId()); + 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.selectByComponentUuidsAndMetricIds(db.getSession(), - asList(measure1.getComponentUuid(), measure2.getComponentUuid()), singletonList(metric.getId())); + List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), + asList(measure1.getComponentUuid(), measure2.getComponentUuid()), singletonList(metric.getUuid())); assertThat(selected) - .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricId, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString) + .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString) .containsExactlyInAnyOrder( - tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricId(), measure1.getValue(), measure1.getDataAsString()), - tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricId(), measure2.getValue(), measure2.getDataAsString())); + tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricUuid(), measure1.getValue(), measure1.getDataAsString()), + tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricUuid(), measure2.getValue(), measure2.getDataAsString())); - assertThat(underTest.selectByComponentUuidsAndMetricIds(db.getSession(), emptyList(), singletonList(metric.getId()))).isEmpty(); - assertThat(underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(measure1.getComponentUuid()), emptyList())).isEmpty(); + assertThat(underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), emptyList(), singletonList(metric.getUuid()))).isEmpty(); + assertThat(underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList(measure1.getComponentUuid()), emptyList())).isEmpty(); } @Test public void selectByComponentUuidsAndMetricIds_returns_empty_list_if_metric_does_not_match() { - LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), measure); - int otherMetricId = metric.getId() + 100; - List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(measure.getComponentUuid()), singletonList(otherMetricId)); + String otherMetricUuid = metric.getUuid() + "other"; + List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList(measure.getComponentUuid()), singletonList(otherMetricUuid)); assertThat(selected).isEmpty(); } @@ -97,25 +97,25 @@ public class LiveMeasureDaoTest { LiveMeasureDto measure = newLiveMeasure(); underTest.insert(db.getSession(), measure); - List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList("_missing_"), singletonList(measure.getMetricId())); + List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList("_missing_"), singletonList(measure.getMetricUuid())); assertThat(selected).isEmpty(); } @Test public void selectByComponentUuidsAndMetricKeys() { - LiveMeasureDto measure1 = newLiveMeasure().setMetricId(metric.getId()); - LiveMeasureDto measure2 = newLiveMeasure().setMetricId(metric.getId()); + 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.selectByComponentUuidsAndMetricKeys(db.getSession(), asList(measure1.getComponentUuid(), measure2.getComponentUuid()), singletonList(metric.getKey())); assertThat(selected) - .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricId, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString) + .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString) .containsExactlyInAnyOrder( - tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricId(), measure1.getValue(), measure1.getDataAsString()), - tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricId(), measure2.getValue(), measure2.getDataAsString())); + tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricUuid(), measure1.getValue(), measure1.getDataAsString()), + tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricUuid(), measure2.getValue(), measure2.getDataAsString())); assertThat(underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), emptyList(), singletonList(metric.getKey()))).isEmpty(); assertThat(underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), singletonList(measure1.getComponentUuid()), emptyList())).isEmpty(); @@ -123,7 +123,7 @@ public class LiveMeasureDaoTest { @Test public void selectByComponentUuidsAndMetricKeys_returns_empty_list_if_metric_does_not_match() { - LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), measure); List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), singletonList(measure.getComponentUuid()), singletonList("_other_")); @@ -133,7 +133,7 @@ public class LiveMeasureDaoTest { @Test public void selectByComponentUuidsAndMetricKeys_returns_empty_list_if_component_does_not_match() { - LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), measure); List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), singletonList("_missing_"), singletonList(metric.getKey())); @@ -143,7 +143,7 @@ public class LiveMeasureDaoTest { @Test public void selectByComponentUuidAndMetricKey() { - LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), measure); Optional<LiveMeasureDto> selected = underTest.selectMeasure(db.getSession(), measure.getComponentUuid(), metric.getKey()); @@ -154,7 +154,7 @@ public class LiveMeasureDaoTest { @Test public void selectByComponentUuidAndMetricKey_return_empty_if_component_does_not_match() { - LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), measure); assertThat(underTest.selectMeasure(db.getSession(), "_missing_", metric.getKey())).isEmpty(); @@ -162,7 +162,7 @@ public class LiveMeasureDaoTest { @Test public void selectByComponentUuidAndMetricKey_return_empty_if_metric_does_not_match() { - LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), measure); assertThat(underTest.selectMeasure(db.getSession(), measure.getComponentUuid(), "_missing_")).isEmpty(); @@ -172,8 +172,8 @@ public class LiveMeasureDaoTest { public void selectByComponentUuidAndMetricKeys() { MetricDto metric2 = db.measures().insertMetric(); - LiveMeasureDto measure1 = newLiveMeasure().setMetricId(metric.getId()).setValue(1.0).setComponentUuid("uuid"); - LiveMeasureDto measure2 = newLiveMeasure().setMetricId(metric2.getId()).setValue(2.0).setComponentUuid("uuid"); + LiveMeasureDto measure1 = newLiveMeasure().setMetricUuid(metric.getUuid()).setValue(1.0).setComponentUuid("uuid"); + LiveMeasureDto measure2 = newLiveMeasure().setMetricUuid(metric2.getUuid()).setValue(2.0).setComponentUuid("uuid"); underTest.insert(db.getSession(), measure1); underTest.insert(db.getSession(), measure2); @@ -181,13 +181,13 @@ public class LiveMeasureDaoTest { List<LiveMeasureDto> selected = underTest.selectByComponentUuidAndMetricKeys(db.getSession(), "uuid", asList(metric.getKey(), metric2.getKey())); assertThat(selected).hasSize(2); - assertThat(selected).extracting(LiveMeasureDto::getMetricId, LiveMeasureDto::getValue) - .containsExactlyInAnyOrder(tuple(metric.getId(), measure1.getValue()), tuple(metric2.getId(), measure2.getValue())); + assertThat(selected).extracting(LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue) + .containsExactlyInAnyOrder(tuple(metric.getUuid(), measure1.getValue()), tuple(metric2.getUuid(), measure2.getValue())); } @Test public void selectByComponentUuidAndMetricKeys_return_empty_if_component_does_not_match() { - LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), measure); assertThat(underTest.selectByComponentUuidAndMetricKeys(db.getSession(), "_missing_", singletonList(metric.getKey()))).isEmpty(); @@ -195,7 +195,7 @@ public class LiveMeasureDaoTest { @Test public void selectByComponentUuidAndMetricKeys_return_empty_if_no_metric_matches() { - LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), measure); assertThat(underTest.selectByComponentUuidAndMetricKeys(db.getSession(), measure.getComponentUuid(), singletonList("_missing_"))).isEmpty(); @@ -204,7 +204,7 @@ public class LiveMeasureDaoTest { @Test public void selectMeasure() { MetricDto metric = db.measures().insertMetric(); - LiveMeasureDto stored = newLiveMeasure().setMetricId(metric.getId()); + LiveMeasureDto stored = newLiveMeasure().setMetricUuid(metric.getUuid()); underTest.insert(db.getSession(), stored); // metric exists but not component @@ -231,14 +231,14 @@ public class LiveMeasureDaoTest { underTest.selectTreeByQuery(db.getSession(), project, MeasureTreeQuery.builder() - .setMetricIds(singleton(metric.getId())) + .setMetricUuids(singleton(metric.getUuid())) .setStrategy(MeasureTreeQuery.Strategy.LEAVES).build(), context -> results.add(context.getResultObject())); assertThat(results).hasSize(1); LiveMeasureDto result = results.get(0); assertThat(result.getComponentUuid()).isEqualTo(file.uuid()); - assertThat(result.getMetricId()).isEqualTo(metric.getId()); + assertThat(result.getMetricUuid()).isEqualTo(metric.getUuid()); assertThat(result.getValue()).isEqualTo(3.14); } @@ -256,13 +256,13 @@ public class LiveMeasureDaoTest { context -> results.add(context.getResultObject())); assertThat(results).hasSize(2); - LiveMeasureDto result = results.stream().filter(lm -> lm.getMetricId() == metric.getId()).findFirst().get(); + LiveMeasureDto result = results.stream().filter(lm -> lm.getMetricUuid().equals(metric.getUuid())).findFirst().get(); assertThat(result.getComponentUuid()).isEqualTo(project.uuid()); - assertThat(result.getMetricId()).isEqualTo(metric.getId()); + assertThat(result.getMetricUuid()).isEqualTo(metric.getUuid()); assertThat(result.getValue()).isEqualTo(3.14); - LiveMeasureDto result2 = results.stream().filter(lm -> lm.getMetricId() == metric2.getId()).findFirst().get(); + LiveMeasureDto result2 = results.stream().filter(lm -> lm.getMetricUuid().equals(metric2.getUuid())).findFirst().get(); assertThat(result2.getComponentUuid()).isEqualTo(project.uuid()); - assertThat(result2.getMetricId()).isEqualTo(metric2.getId()); + assertThat(result2.getMetricUuid()).isEqualTo(metric2.getUuid()); assertThat(result2.getValue()).isEqualTo(4.54); } @@ -296,9 +296,9 @@ public class LiveMeasureDaoTest { 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::getMetricId, LiveMeasureDto::getValue, LiveMeasureDto::getVariation, + LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getVariation, LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue) - .contains(project.uuid(), file.uuid(), metric.getId(), 3.14, 0.1, "text_value", "text_value"); + .contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, 0.1, "text_value", "text_value"); } @Test @@ -403,16 +403,16 @@ public class LiveMeasureDaoTest { @Test public void deleteByComponentUuidExcludingMetricIds() { - LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); - LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); - LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricId(3); - LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(3); + 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.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Arrays.asList(1, 2)); + underTest.deleteByComponentUuidExcludingMetricUuids(db.getSession(), "C1", Arrays.asList("1", "2")); verifyTableSize(3); verifyPersisted(measure1); @@ -422,10 +422,10 @@ public class LiveMeasureDaoTest { @Test public void deleteByComponentUuid() { - LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); - LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); - LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricId(3); - LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(3); + 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); @@ -439,14 +439,14 @@ public class LiveMeasureDaoTest { @Test public void deleteByComponentUuidExcludingMetricIds_with_empty_metrics() { - LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); - LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); - LiveMeasureDto measureOnOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(2); + 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.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Collections.emptyList()); + underTest.deleteByComponentUuidExcludingMetricUuids(db.getSession(), "C1", Collections.emptyList()); verifyTableSize(1); verifyPersisted(measureOnOtherComponent); @@ -670,10 +670,10 @@ public class LiveMeasureDaoTest { } private void verifyPersisted(LiveMeasureDto dto) { - List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(dto.getComponentUuid()), singletonList(dto.getMetricId())); + 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", "metricId", "value", "textValue", "data", "variation"); + "componentUuid", "projectUuid", "metricUuid", "value", "textValue", "data", "variation"); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index a2f66a36cb9..8d7f8c17857 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -123,18 +123,18 @@ public class MeasureDaoTest { SnapshotDto project2LastAnalysis = insertAnalysis(project2.uuid(), true); // project 1 - insertMeasure("P1_M1", lastAnalysis.getUuid(), project1.uuid(), ncloc.getId()); - insertMeasure("P1_M2", lastAnalysis.getUuid(), project1.uuid(), coverage.getId()); - insertMeasure("P1_M3", pastAnalysis.getUuid(), project1.uuid(), ncloc.getId()); + insertMeasure("P1_M1", lastAnalysis.getUuid(), project1.uuid(), ncloc.getUuid()); + insertMeasure("P1_M2", lastAnalysis.getUuid(), project1.uuid(), coverage.getUuid()); + insertMeasure("P1_M3", pastAnalysis.getUuid(), project1.uuid(), ncloc.getUuid()); // project 2 - insertMeasure("P2_M1", project2LastAnalysis.getUuid(), project2.uuid(), ncloc.getId()); - insertMeasure("P2_M2", project2LastAnalysis.getUuid(), project2.uuid(), coverage.getId()); + insertMeasure("P2_M1", project2LastAnalysis.getUuid(), project2.uuid(), ncloc.getUuid()); + insertMeasure("P2_M2", project2LastAnalysis.getUuid(), project2.uuid(), coverage.getUuid()); // component C1 - insertMeasure("M1", pastAnalysis.getUuid(), "C1", ncloc.getId()); - insertMeasure("M2", lastAnalysis.getUuid(), "C1", ncloc.getId()); - insertMeasure("M3", lastAnalysis.getUuid(), "C1", coverage.getId()); + insertMeasure("M1", pastAnalysis.getUuid(), "C1", ncloc.getUuid()); + insertMeasure("M2", lastAnalysis.getUuid(), "C1", ncloc.getUuid()); + insertMeasure("M3", lastAnalysis.getUuid(), "C1", coverage.getUuid()); // component C2 - insertMeasure("M6", lastAnalysis.getUuid(), "C2", ncloc.getId()); + insertMeasure("M6", lastAnalysis.getUuid(), "C2", ncloc.getUuid()); db.commit(); verifyNoMeasure("C1", ncloc.getKey(), "invalid_analysis"); @@ -176,14 +176,14 @@ public class MeasureDaoTest { db.commit(); // project - insertMeasure("PROJECT_M1", lastAnalysis.getUuid(), project.uuid(), ncloc.getId()); - insertMeasure("PROJECT_M2", pastAnalysis.getUuid(), project.uuid(), ncloc.getId()); - insertMeasure("PROJECT_M3", "OLD_ANALYSIS_UUID", project.uuid(), ncloc.getId()); + insertMeasure("PROJECT_M1", lastAnalysis.getUuid(), project.uuid(), ncloc.getUuid()); + insertMeasure("PROJECT_M2", pastAnalysis.getUuid(), project.uuid(), ncloc.getUuid()); + insertMeasure("PROJECT_M3", "OLD_ANALYSIS_UUID", project.uuid(), ncloc.getUuid()); db.commit(); // Measures of project for last and previous analyses List<MeasureDto> result = underTest.selectPastMeasures(db.getSession(), - new PastMeasureQuery(project.uuid(), singletonList(ncloc.getId()), previousAnalysisDate, lastAnalysisDate + 1_000L)); + new PastMeasureQuery(project.uuid(), singletonList(ncloc.getUuid()), previousAnalysisDate, lastAnalysisDate + 1_000L)); assertThat(result).hasSize(2).extracting(MeasureDto::getData).containsOnly("PROJECT_M1", "PROJECT_M2"); } @@ -208,11 +208,11 @@ public class MeasureDaoTest { assertThat(underTest.selectLastMeasure(db.getSession(), componentUuid, metricKey)).isEmpty(); } - private void insertMeasure(String value, String analysisUuid, String componentUuid, int metricId) { + private void insertMeasure(String value, String analysisUuid, String componentUuid, String metricUuid) { MeasureDto measure = MeasureTesting.newMeasure() .setAnalysisUuid(analysisUuid) .setComponentUuid(componentUuid) - .setMetricId(metricId) + .setMetricUuid(metricUuid) // as ids can't be forced when inserting measures, the field "data" // is used to store a virtual value. It is used then in assertions. .setData(value); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java index 515dbc5d8b6..66349c17b66 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java @@ -42,13 +42,13 @@ public class MeasureTreeQueryTest { .setStrategy(CHILDREN) .setQualifiers(asList("FIL", "DIR")) .setNameOrKeyQuery("teSt") - .setMetricIds(asList(10, 11)) + .setMetricUuids(asList("10", "11")) .build(); assertThat(query.getStrategy()).isEqualTo(CHILDREN); assertThat(query.getQualifiers()).containsOnly("FIL", "DIR"); assertThat(query.getNameOrKeyQuery()).isEqualTo("teSt"); - assertThat(query.getMetricIds()).containsOnly(10, 11); + assertThat(query.getMetricUuids()).containsOnly("10", "11"); } @Test @@ -60,7 +60,7 @@ public class MeasureTreeQueryTest { assertThat(query.getStrategy()).isEqualTo(CHILDREN); assertThat(query.getQualifiers()).isNull(); assertThat(query.getNameOrKeyQuery()).isNull(); - assertThat(query.getMetricIds()).isNull(); + assertThat(query.getMetricUuids()).isNull(); } @Test @@ -88,12 +88,12 @@ public class MeasureTreeQueryTest { public void return_empty_when_metrics_is_empty() { assertThat(MeasureTreeQuery.builder() .setStrategy(CHILDREN) - .setMetricIds(Collections.emptyList()) + .setMetricUuids(Collections.emptyList()) .build().returnsEmpty()).isTrue(); assertThat(MeasureTreeQuery.builder() .setStrategy(CHILDREN) - .setMetricIds(null) + .setMetricUuids(null) .build().returnsEmpty()).isFalse(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java index 98e04654871..94fb6644954 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java @@ -29,22 +29,22 @@ public class PastMeasureDtoTest { public void test_getter_and_setter() { PastMeasureDto dto = new PastMeasureDto() .setValue(1d) - .setMetricId(2); + .setMetricUuid("2"); assertThat(dto.hasValue()).isTrue(); assertThat(dto.getValue()).isEqualTo(1d); - assertThat(dto.getMetricId()).isEqualTo(2); + assertThat(dto.getMetricUuid()).isEqualTo("2"); } @Test public void test_has_value() { PastMeasureDto measureWithValue = new PastMeasureDto() .setValue(1d) - .setMetricId(2); + .setMetricUuid("2"); assertThat(measureWithValue.hasValue()).isTrue(); PastMeasureDto measureWithoutValue = new PastMeasureDto() - .setMetricId(2); + .setMetricUuid("2"); assertThat(measureWithoutValue.hasValue()).isFalse(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java index 366b64d412b..44499e01c68 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java @@ -54,7 +54,7 @@ public class CustomMeasureDaoTest { MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true)); CustomMeasureDto measure = newCustomMeasureDto() .setComponentUuid(project.uuid()) - .setMetricId(metric.getId()) + .setMetricUuid(metric.getUuid()) .setUserUuid(user.getUuid()); underTest.insert(session, measure); @@ -63,7 +63,7 @@ public class CustomMeasureDaoTest { assertThat(optionalResult).isNotEmpty(); CustomMeasureDto result = optionalResult.get(); assertThat(result.getUuid()).isEqualTo(measure.getUuid()); - assertThat(result.getMetricId()).isEqualTo(metric.getId()); + assertThat(result.getMetricUuid()).isEqualTo(metric.getUuid()); assertThat(result.getComponentUuid()).isEqualTo(project.uuid()); assertThat(result.getUserUuid()).isEqualTo(user.getUuid()); assertThat(result.getDescription()).isEqualTo(measure.getDescription()); @@ -80,7 +80,7 @@ public class CustomMeasureDaoTest { MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true)); CustomMeasureDto measure = db.measures().insertCustomMeasure(user, project, metric); - underTest.deleteByMetricIds(session, singletonList(measure.getMetricId())); + underTest.deleteByMetricUuids(session, singletonList(measure.getMetricUuid())); assertThat(underTest.selectByUuid(session, measure.getUuid())).isEmpty(); } @@ -151,20 +151,20 @@ public class CustomMeasureDaoTest { @Test public void select_by_metric_id() { - underTest.insert(session, newCustomMeasureDto().setMetricId(123)); - underTest.insert(session, newCustomMeasureDto().setMetricId(123)); + underTest.insert(session, newCustomMeasureDto().setMetricUuid("metric")); + underTest.insert(session, newCustomMeasureDto().setMetricUuid("metric")); - List<CustomMeasureDto> result = underTest.selectByMetricId(session, 123); + List<CustomMeasureDto> result = underTest.selectByMetricUuid(session, "metric"); assertThat(result).hasSize(2); } @Test public void count_by_component_uuid_and_metric_id() { - underTest.insert(session, newCustomMeasureDto().setMetricId(123).setComponentUuid("123")); - underTest.insert(session, newCustomMeasureDto().setMetricId(123).setComponentUuid("123")); + underTest.insert(session, newCustomMeasureDto().setMetricUuid("metric").setComponentUuid("123")); + underTest.insert(session, newCustomMeasureDto().setMetricUuid("metric").setComponentUuid("123")); - int count = underTest.countByComponentIdAndMetricId(session, "123", 123); + int count = underTest.countByComponentIdAndMetricUuid(session, "123", "metric"); assertThat(count).isEqualTo(2); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java index 13299a342d8..3654ce60937 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java @@ -30,6 +30,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.utils.System2; +import org.sonar.core.util.Uuids; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.RowNotFoundException; @@ -93,8 +94,8 @@ public class MetricDaoTest { db.getSession().commit(); assertThat(underTest.selectEnabled(dbSession)) - .extracting(MetricDto::getId) - .containsOnly(enabledMetrics.stream().map(MetricDto::getId).toArray(Integer[]::new)); + .extracting(MetricDto::getUuid) + .containsOnly(enabledMetrics.stream().map(MetricDto::getUuid).toArray(String[]::new)); } @Test @@ -113,13 +114,14 @@ public class MetricDaoTest { db.getSession().commit(); assertThat(underTest.selectEnabled(dbSession)) - .extracting(MetricDto::getId) - .containsOnly(enabledMetrics.stream().map(MetricDto::getId).toArray(Integer[]::new)); + .extracting(MetricDto::getUuid) + .containsOnly(enabledMetrics.stream().map(MetricDto::getUuid).toArray(String[]::new)); } @Test public void insert() { underTest.insert(dbSession, new MetricDto() + .setUuid(Uuids.createFast()) .setKey("coverage") .setShortName("Coverage") .setDescription("Coverage by unit tests") @@ -136,7 +138,7 @@ public class MetricDaoTest { .setEnabled(true)); MetricDto result = underTest.selectByKey(dbSession, "coverage"); - assertThat(result.getId()).isNotNull(); + assertThat(result.getUuid()).isNotNull(); assertThat(result.getKey()).isEqualTo("coverage"); assertThat(result.getShortName()).isEqualTo("Coverage"); assertThat(result.getDescription()).isEqualTo("Coverage by unit tests"); @@ -156,6 +158,7 @@ public class MetricDaoTest { @Test public void insert_metrics() { underTest.insert(dbSession, new MetricDto() + .setUuid(Uuids.createFast()) .setKey("coverage") .setShortName("Coverage") .setDescription("Coverage by unit tests") @@ -171,6 +174,7 @@ public class MetricDaoTest { .setDeleteHistoricalData(true) .setEnabled(true), new MetricDto() + .setUuid(Uuids.createFast()) .setKey("ncloc") .setShortName("ncloc") .setDescription("ncloc") @@ -191,20 +195,20 @@ public class MetricDaoTest { } @Test - public void selectById() { + public void selectByUuid() { MetricDto metric = underTest.insert(dbSession, newMetricDto()); - MetricDto result = underTest.selectById(dbSession, metric.getId()); + MetricDto result = underTest.selectByUuid(dbSession, metric.getUuid()); assertThat(result).isNotNull(); } @Test - public void selectByIds() { + public void selectByUuids() { MetricDto metric1 = underTest.insert(dbSession, newMetricDto()); MetricDto metric2 = underTest.insert(dbSession, newMetricDto()); - List<MetricDto> result = underTest.selectByIds(dbSession, newHashSet(metric1.getId(), metric2.getId())); + List<MetricDto> result = underTest.selectByUuids(dbSession, newHashSet(metric1.getUuid(), metric2.getUuid())); assertThat(result).hasSize(2); } @@ -255,13 +259,13 @@ public class MetricDaoTest { } @Test - public void disableByIds() { + public void disableByUuids() { MetricDto metric1 = underTest.insert(dbSession, newMetricDto().setEnabled(true).setUserManaged(true)); MetricDto metric2 = underTest.insert(dbSession, newMetricDto().setEnabled(true).setUserManaged(true)); - underTest.disableCustomByIds(dbSession, Arrays.asList(metric1.getId(), metric2.getId())); + underTest.disableCustomByUuids(dbSession, Arrays.asList(metric1.getUuid(), metric2.getUuid())); - List<MetricDto> result = underTest.selectByIds(dbSession, newHashSet(metric1.getId(), metric2.getId())); + List<MetricDto> result = underTest.selectByUuids(dbSession, newHashSet(metric1.getUuid(), metric2.getUuid())); assertThat(result).hasSize(2); assertThat(result).extracting("enabled").containsOnly(false); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java index a3974e3cd8d..1f3c0506289 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java @@ -35,7 +35,7 @@ public class MetricDtoTest { @Test public void getters_and_setters() { MetricDto metricDto = new MetricDto() - .setId(1) + .setUuid("1") .setKey("coverage") .setShortName("Coverage") .setDescription("Coverage by unit tests") @@ -51,7 +51,7 @@ public class MetricDtoTest { .setDeleteHistoricalData(true) .setEnabled(true); - assertThat(metricDto.getId()).isEqualTo(1); + assertThat(metricDto.getUuid()).isEqualTo("1"); assertThat(metricDto.getKey()).isEqualTo("coverage"); assertThat(metricDto.getShortName()).isEqualTo("Coverage"); assertThat(metricDto.getDescription()).isEqualTo("Coverage by unit tests"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java index 2634468b5f4..717f259e0b3 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java @@ -622,7 +622,7 @@ public class PurgeCommandsTest { } private int countMeasures(SnapshotDto analysis, MetricDto metric) { - return dbTester.countSql("select count(*) from project_measures where analysis_uuid='" + analysis.getUuid() + "' and metric_id=" + metric.getId()); + return dbTester.countSql("select count(*) from project_measures where analysis_uuid='" + analysis.getUuid() + "' and metric_id=" + metric.getUuid()); } private int countComponentOfRoot(ComponentDto projectOrView) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 6ef1af9804d..de9d82c07bd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -285,14 +285,14 @@ public class PurgeDaoTest { // deletes live measure of selected assertThat(db.countRowsOfTable("live_measures")).isEqualTo(4); List<LiveMeasureDto> liveMeasureDtos = db.getDbClient().liveMeasureDao() - .selectByComponentUuidsAndMetricIds(dbSession, ImmutableSet.of(srcFile.uuid(), dir.uuid(), project.uuid(), enabledFile.uuid()), - ImmutableSet.of(metric1.getId(), metric2.getId())); + .selectByComponentUuidsAndMetricUuids(dbSession, ImmutableSet.of(srcFile.uuid(), dir.uuid(), project.uuid(), enabledFile.uuid()), + ImmutableSet.of(metric1.getUuid(), metric2.getUuid())); assertThat(liveMeasureDtos) .extracting(LiveMeasureDto::getComponentUuid) .containsOnly(enabledFile.uuid(), project.uuid()); assertThat(liveMeasureDtos) - .extracting(LiveMeasureDto::getMetricId) - .containsOnly(metric1.getId(), metric2.getId()); + .extracting(LiveMeasureDto::getMetricUuid) + .containsOnly(metric1.getUuid(), metric2.getUuid()); } @Test @@ -1272,8 +1272,8 @@ public class PurgeDaoTest { underTest.deleteProject(dbSession, project1.uuid()); - assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, asList(project1.uuid(), module1.uuid()), asList(metric.getId()))).isEmpty(); - assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, asList(project2.uuid(), module2.uuid()), asList(metric.getId()))).hasSize(2); + assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, asList(project1.uuid(), module1.uuid()), asList(metric.getUuid()))).isEmpty(); + assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, asList(project2.uuid(), module2.uuid()), asList(metric.getUuid()))).hasSize(2); } private void verifyNoEffect(ComponentDto firstRoot, ComponentDto... otherRoots) { @@ -1525,7 +1525,7 @@ public class PurgeDaoTest { private void insertManualMeasureFor(ComponentDto... componentDtos) { Arrays.stream(componentDtos).forEach(componentDto -> dbClient.customMeasureDao().insert(dbSession, new CustomMeasureDto() .setComponentUuid(componentDto.uuid()) - .setMetricId(new Random().nextInt()))); + .setMetricUuid(randomAlphabetic(3)))); dbSession.commit(); } @@ -1553,7 +1553,7 @@ public class PurgeDaoTest { private void insertMeasureFor(ComponentDto... components) { Arrays.stream(components).forEach(componentDto -> db.getDbClient().measureDao().insert(dbSession, new MeasureDto() - .setMetricId(new Random().nextInt()) + .setMetricUuid(randomAlphabetic(3)) .setComponentUuid(componentDto.uuid()) .setAnalysisUuid(randomAlphabetic(3)))); dbSession.commit(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java index 658a7077aa6..3c94e1d57d3 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java @@ -44,7 +44,7 @@ public class QualityGateConditionDaoTest { @Test public void testInsert() { - QualityGateConditionDto newCondition = insertQGCondition(1L, 2L, "GT", "20"); + QualityGateConditionDto newCondition = insertQGCondition(1L, "2", "GT", "20"); assertThat(newCondition.getUuid()).isNotNull(); QualityGateConditionDto actual = underTest.selectByUuid(newCondition.getUuid(), dbSession); @@ -83,7 +83,7 @@ public class QualityGateConditionDaoTest { @Test public void testSelectByUuid() { - QualityGateConditionDto condition = insertQGCondition(1L, 2L, "GT", "20"); + QualityGateConditionDto condition = insertQGCondition(1L, "2", "GT", "20"); assertEquals(underTest.selectByUuid(condition.getUuid(), dbSession), condition); assertThat(underTest.selectByUuid("uuid1", dbSession)).isNull(); @@ -109,7 +109,7 @@ public class QualityGateConditionDaoTest { QualityGateConditionDto newCondition1 = new QualityGateConditionDto() .setUuid(condition1.getUuid()) .setQualityGateId(condition1.getQualityGateId()) - .setMetricId(7L) + .setMetricUuid("7") .setOperator(">") .setErrorThreshold("80"); underTest.update(newCondition1, dbSession); @@ -124,9 +124,9 @@ public class QualityGateConditionDaoTest { public void shouldCleanConditions() { MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true)); MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false)); - QualityGateConditionDto condition1 = insertQGCondition(1L, enabledMetric.getId()); - QualityGateConditionDto condition2 = insertQGCondition(1L, disabledMetric.getId()); - QualityGateConditionDto condition3 = insertQGCondition(1L, 299); + QualityGateConditionDto condition1 = insertQGCondition(1L, enabledMetric.getUuid()); + QualityGateConditionDto condition2 = insertQGCondition(1L, disabledMetric.getUuid()); + QualityGateConditionDto condition3 = insertQGCondition(1L, "299"); underTest.deleteConditionsWithInvalidMetrics(dbTester.getSession()); dbTester.commit(); @@ -138,18 +138,18 @@ public class QualityGateConditionDaoTest { } private QualityGateConditionDto insertQGCondition(long qualityGateId) { - return insertQGCondition(qualityGateId, new Random().nextInt(100)); + return insertQGCondition(qualityGateId, randomAlphabetic(2)); } - private QualityGateConditionDto insertQGCondition(long qualityGateId, int metricId) { - return insertQGCondition(qualityGateId, metricId, randomAlphabetic(2), randomAlphabetic(3)); + private QualityGateConditionDto insertQGCondition(long qualityGateId, String metricUuid) { + return insertQGCondition(qualityGateId, metricUuid, randomAlphabetic(2), randomAlphabetic(3)); } - private QualityGateConditionDto insertQGCondition(long qualityGateId, long metricId, String operator, String threshold) { + private QualityGateConditionDto insertQGCondition(long qualityGateId, String metricUuid, String operator, String threshold) { QualityGateConditionDto res = new QualityGateConditionDto() .setUuid(Uuids.create()) .setQualityGateId(qualityGateId) - .setMetricId(metricId) + .setMetricUuid(metricUuid) .setOperator(operator) .setErrorThreshold(threshold); underTest.insert(res, dbTester.getSession()); @@ -159,7 +159,7 @@ public class QualityGateConditionDaoTest { private void assertEquals(QualityGateConditionDto actual, QualityGateConditionDto expected) { assertThat(actual.getQualityGateId()).isEqualTo(expected.getQualityGateId()); - assertThat(actual.getMetricId()).isEqualTo(expected.getMetricId()); + assertThat(actual.getMetricUuid()).isEqualTo(expected.getMetricUuid()); assertThat(actual.getOperator()).isEqualTo(expected.getOperator()); assertThat(actual.getErrorThreshold()).isEqualTo(expected.getErrorThreshold()); } 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 770ac10bba0..553e7252db8 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 @@ -69,7 +69,7 @@ public class MeasureDbTester { Preconditions.checkArgument(metricDto.isUserManaged(),"Custom measure must be created from a custom metric"); CustomMeasureDto dto = newCustomMeasureDto() .setComponentUuid(component.uuid()) - .setMetricId(metricDto.getId()); + .setMetricUuid(metricDto.getUuid()); if (user != null) { dto.setUserUuid(user.getUuid()); } 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 8e371c93692..b4cd54ea09b 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 @@ -35,19 +35,19 @@ public class MeasureTesting { } public static MeasureDto newMeasureDto(MetricDto metricDto, ComponentDto component, SnapshotDto analysis) { - checkNotNull(metricDto.getId()); + checkNotNull(metricDto.getUuid()); checkNotNull(metricDto.getKey()); checkNotNull(component.uuid()); checkNotNull(analysis.getUuid()); return new MeasureDto() - .setMetricId(metricDto.getId()) + .setMetricUuid(metricDto.getUuid()) .setComponentUuid(component.uuid()) .setAnalysisUuid(analysis.getUuid()); } public static MeasureDto newMeasure() { return new MeasureDto() - .setMetricId(cursor++) + .setMetricUuid(String.valueOf(cursor++)) .setComponentUuid(String.valueOf(cursor++)) .setAnalysisUuid(String.valueOf(cursor++)) .setData(String.valueOf(cursor++)) @@ -58,7 +58,7 @@ public class MeasureTesting { public static LiveMeasureDto newLiveMeasure() { return new LiveMeasureDto() - .setMetricId(cursor++) + .setMetricUuid(String.valueOf(cursor++)) .setComponentUuid(String.valueOf(cursor++)) .setProjectUuid(String.valueOf(cursor++)) .setData(String.valueOf(cursor++)) @@ -68,7 +68,7 @@ public class MeasureTesting { public static LiveMeasureDto newLiveMeasure(ComponentDto component, MetricDto metric) { return new LiveMeasureDto() - .setMetricId(metric.getId()) + .setMetricUuid(metric.getUuid()) .setComponentUuid(component.uuid()) .setProjectUuid(component.projectUuid()) .setData(String.valueOf(cursor++)) diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java index 3b53e9c0a3e..9ce908c5891 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java @@ -22,6 +22,7 @@ package org.sonar.db.measure.custom; import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.math.RandomUtils; import org.sonar.api.utils.System2; +import org.sonar.core.util.Uuids; public class CustomMeasureTesting { private CustomMeasureTesting() { @@ -30,11 +31,12 @@ public class CustomMeasureTesting { public static CustomMeasureDto newCustomMeasureDto() { return new CustomMeasureDto() + .setUuid(Uuids.createFast()) .setDescription(RandomStringUtils.randomAlphanumeric(255)) .setTextValue(RandomStringUtils.randomAlphanumeric(255)) .setUserUuid("userUuid" + RandomStringUtils.randomAlphanumeric(100)) .setValue(RandomUtils.nextDouble()) - .setMetricId(RandomUtils.nextInt()) + .setMetricUuid(RandomStringUtils.randomAlphanumeric(40)) .setComponentUuid(RandomStringUtils.randomAlphanumeric(50)) .setCreatedAt(System2.INSTANCE.now()) .setUpdatedAt(System2.INSTANCE.now()); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java index 7c35222e23d..a1a65259f77 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java @@ -31,7 +31,7 @@ public class MetricTesting { public static MetricDto newMetricDto() { Metric.ValueType[] metricTypes = Metric.ValueType.values(); return new MetricDto() - .setId(RandomUtils.nextInt()) + .setUuid(RandomStringUtils.randomAlphanumeric(40)) .setKey(RandomStringUtils.randomAlphanumeric(64)) .setShortName(RandomStringUtils.randomAlphanumeric(64)) .setValueType(metricTypes[RandomUtils.nextInt(metricTypes.length - 1)].name()) diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java index 1f49d797efb..68150491124 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java @@ -95,7 +95,7 @@ public class QualityGateDbTester { public final QualityGateConditionDto addCondition(QualityGateDto qualityGate, MetricDto metric, Consumer<QualityGateConditionDto>... dtoPopulators) { QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId()) .setUuid(Uuids.createFast()) - .setMetricId(metric.getId()) + .setMetricUuid(metric.getUuid()) .setOperator("GT") .setErrorThreshold(randomNumeric(10)); Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(condition)); |