From: Julien Lancelot Date: Thu, 3 Nov 2016 14:07:44 +0000 (+0100) Subject: SONAR-8325 Refactore MeasureDao#selectByQuery to improve readybility X-Git-Tag: 6.2-RC1~220 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1351%2Fhead;p=sonarqube.git SONAR-8325 Refactore MeasureDao#selectByQuery to improve readybility --- diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java index c298bb18ff1..6d8071926d3 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java @@ -25,12 +25,10 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Optional; -import org.apache.ibatis.session.ResultHandler; import org.sonar.db.Dao; import org.sonar.db.DbSession; import static org.sonar.db.DatabaseUtils.executeLargeInputs; -import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput; public class MeasureDao implements Dao { @@ -59,46 +57,23 @@ public class MeasureDao implements Dao { if (query.returnsEmpty()) { return Collections.emptyList(); } - if (query.getComponentUuids() != null) { + if (query.isOnComponents()) { return executeLargeInputs( query.getComponentUuids(), componentUuids -> { MeasureQuery pageQuery = MeasureQuery.copyWithSubsetOfComponentUuids(query, componentUuids); - return mapper(dbSession).selectByQuery(pageQuery); + return mapper(dbSession).selectByQueryOnComponents(pageQuery); }); - } else if (query.getProjectUuids() != null) { - return executeLargeInputs( - query.getProjectUuids(), - projectUuids -> { - MeasureQuery pageQuery = MeasureQuery.copyWithSubsetOfProjectUuids(query, projectUuids); - return mapper(dbSession).selectByQuery(pageQuery); - }); - } - return mapper(dbSession).selectByQuery(query); - } - - public void selectByQuery(DbSession dbSession, MeasureQuery query, ResultHandler resultHandler) { - if (query.returnsEmpty()) { - return; } - if (query.getComponentUuids() != null) { - executeLargeInputsWithoutOutput( - query.getComponentUuids(), - componentUuids -> { - MeasureQuery pageQuery = MeasureQuery.copyWithSubsetOfComponentUuids(query, componentUuids); - mapper(dbSession).selectByQuery(pageQuery, resultHandler); - return null; - }); - } else if (query.getProjectUuids() != null) { - executeLargeInputsWithoutOutput( + if (query.isOnProjects()) { + return executeLargeInputs( query.getProjectUuids(), projectUuids -> { MeasureQuery pageQuery = MeasureQuery.copyWithSubsetOfProjectUuids(query, projectUuids); - mapper(dbSession).selectByQuery(pageQuery, resultHandler); - return null; + return mapper(dbSession).selectByQueryOnProjects(pageQuery); }); } - mapper(dbSession).selectByQuery(query, resultHandler); + return mapper(dbSession).selectByQueryOnSingleComponent(query); } public List selectPastMeasures(DbSession dbSession, diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java index 68cfe0c2050..e945719372c 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java @@ -26,7 +26,11 @@ import org.apache.ibatis.session.ResultHandler; public interface MeasureMapper { - List selectByQuery(@Param("query") MeasureQuery query); + List selectByQueryOnProjects(@Param("query") MeasureQuery query); + + List selectByQueryOnComponents(@Param("query") MeasureQuery query); + + List selectByQueryOnSingleComponent(@Param("query") MeasureQuery query); void selectByQuery(@Param("query") MeasureQuery query, ResultHandler resultHandler); 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 00b724df175..119d197e2d6 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 @@ -136,7 +136,7 @@ public class MeasureQuery { return false; } MeasureQuery that = (MeasureQuery) o; - return Objects.equals(analysisUuid, that.analysisUuid) && + return analysisUuid.equals(that.analysisUuid) && Objects.equals(projectUuids, that.projectUuids) && Objects.equals(componentUuids, that.componentUuids) && Objects.equals(metricIds, that.metricIds) && 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 0ed2c37a4ed..929ad1c4412 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 @@ -25,41 +25,55 @@ metric.name as metricKey - + select from project_measures pm + + where + + and analysis.component_uuid=pm.component_uuid + and analysis.component_uuid in + + #{projectUuid} + + + + + + + + inner join snapshots analysis on analysis.uuid = pm.analysis_uuid - - inner join projects p on p.project_uuid=analysis.component_uuid and p.uuid=pm.component_uuid - and p.project_uuid=#{query.projectUuid} - and p.uuid in - - #{componentUuid} - - - - inner join projects p on p.project_uuid=analysis.component_uuid and p.uuid=pm.component_uuid - and p.uuid=#{query.componentUuid} - inner join metrics m on m.id = pm.metric_id - where + + + analysis.islast=${_true} analysis.uuid = #{query.analysisUuid} - - and analysis.component_uuid=pm.component_uuid - and analysis.component_uuid in - - #{projectUuid} - - and pm.metric_id in #{metricId} @@ -78,7 +92,7 @@ and person_id is null - +