From 12a0704dd3d79fdbc7162b6a4c0a8a2f196b15dc Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 4 Nov 2016 07:28:32 +0100 Subject: SONAR-8325 Use Collection in MeasureQuery and remove useless join on projects --- .../java/org/sonar/db/measure/MeasureQuery.java | 60 +++++++++++----------- .../org/sonar/db/measure/MeasureMapper.xml | 11 ++-- 2 files changed, 35 insertions(+), 36 deletions(-) (limited to 'sonar-db') diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java index 119d197e2d6..382c44f5313 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java @@ -19,29 +19,29 @@ */ package org.sonar.db.measure; -import java.util.List; +import java.util.Collection; import java.util.Objects; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Collections.singletonList; +import static java.util.Collections.singleton; import static java.util.Objects.requireNonNull; public class MeasureQuery { private final String analysisUuid; @CheckForNull - private final List projectUuids; + private final Collection projectUuids; @CheckForNull - private final List componentUuids; + private final Collection componentUuids; @CheckForNull - private final List metricIds; + private final Collection metricIds; @CheckForNull - private final List metricKeys; + private final Collection metricKeys; @CheckForNull private final Long personId; @@ -51,10 +51,10 @@ public class MeasureQuery { } private MeasureQuery(@Nullable String analysisUuid, - @Nullable List projectUuids, - @Nullable List componentUuids, - @Nullable List metricIds, - @Nullable List metricKeys, + @Nullable Collection projectUuids, + @Nullable Collection componentUuids, + @Nullable Collection metricIds, + @Nullable Collection metricKeys, @Nullable Long personId) { checkArgument(metricIds == null || metricKeys == null, "Metric IDs and keys must not be set both"); checkArgument(projectUuids != null || componentUuids != null, "At least one filter on component UUID is expected"); @@ -74,32 +74,32 @@ public class MeasureQuery { } @CheckForNull - public List getProjectUuids() { + public Collection getProjectUuids() { return projectUuids; } @CheckForNull public String getProjectUuid() { - return isOnComponents() ? projectUuids.get(0) : null; + return isOnComponents() ? projectUuids.iterator().next() : null; } @CheckForNull - public List getComponentUuids() { + public Collection getComponentUuids() { return componentUuids; } @CheckForNull public String getComponentUuid() { - return isOnSingleComponent() ? componentUuids.get(0) : null; + return isOnSingleComponent() ? componentUuids.iterator().next() : null; } @CheckForNull - public List getMetricIds() { + public Collection getMetricIds() { return metricIds; } @CheckForNull - public List getMetricKeys() { + public Collection getMetricKeys() { return metricKeys; } @@ -153,20 +153,20 @@ public class MeasureQuery { return new Builder(); } - static MeasureQuery copyWithSubsetOfProjectUuids(MeasureQuery query, List projectUuids) { + static MeasureQuery copyWithSubsetOfProjectUuids(MeasureQuery query, Collection projectUuids) { return new MeasureQuery(query.analysisUuid, projectUuids, query.componentUuids, query.metricIds, query.metricKeys, query.personId); } - static MeasureQuery copyWithSubsetOfComponentUuids(MeasureQuery query, List componentUuids) { + static MeasureQuery copyWithSubsetOfComponentUuids(MeasureQuery query, Collection componentUuids) { return new MeasureQuery(query.analysisUuid, query.projectUuids, componentUuids, query.metricIds, query.metricKeys, query.personId); } public static final class Builder { private String analysisUuid; - private List projectUuids; - private List componentUuids; - private List metricIds; - private List metricKeys; + private Collection projectUuids; + private Collection componentUuids; + private Collection metricIds; + private Collection metricKeys; private Long personId; private Builder() { @@ -181,7 +181,7 @@ public class MeasureQuery { /** * List of projects */ - public Builder setProjectUuids(@Nullable List projectUuids) { + public Builder setProjectUuids(@Nullable Collection projectUuids) { this.projectUuids = projectUuids; return this; } @@ -189,8 +189,8 @@ public class MeasureQuery { /** * List of components of a project */ - public Builder setComponentUuids(String projectUuid, List componentUuids) { - setProjectUuids(singletonList(requireNonNull(projectUuid))); + public Builder setComponentUuids(String projectUuid, Collection componentUuids) { + setProjectUuids(singleton(requireNonNull(projectUuid))); this.componentUuids = componentUuids; return this; } @@ -199,33 +199,33 @@ public class MeasureQuery { * Single component */ public Builder setComponentUuid(String componentUuid) { - this.componentUuids = singletonList(componentUuid); + this.componentUuids = singleton(componentUuid); return this; } /** * All the measures are returned if parameter is {@code null}. */ - public Builder setMetricIds(@Nullable List metricIds) { + public Builder setMetricIds(@Nullable Collection metricIds) { this.metricIds = metricIds; return this; } public Builder setMetricId(int metricId) { - this.metricIds = singletonList(metricId); + this.metricIds = singleton(metricId); return this; } /** * All the measures are returned if parameter is {@code null}. */ - public Builder setMetricKeys(@Nullable List s) { + public Builder setMetricKeys(@Nullable Collection s) { this.metricKeys = s; return this; } public Builder setMetricKey(String s) { - this.metricKeys = singletonList(s); + this.metricKeys = singleton(s); return this; } diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml index 3b12f1552c2..00534d151eb 100644 --- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -27,7 +27,7 @@ select from project_measures pm - - inner join projects p on p.project_uuid=analysis.component_uuid and p.uuid=pm.component_uuid - and p.project_uuid=#{query.projectUuid} + where + and analysis.component_uuid=#{query.projectUuid} and pm.component_uuid in #{componentUuid} @@ -52,7 +51,7 @@ - + inner join snapshots analysis on analysis.uuid = pm.analysis_uuid inner join metrics m on m.id = pm.metric_id -- cgit v1.2.3