]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7683 add SnapshotDao#selectByUuids
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 6 Jul 2016 13:58:13 +0000 (15:58 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 7 Jul 2016 15:07:00 +0000 (17:07 +0200)
sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java
sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java
sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml

index f9240f3a0a136e3e2b15bdbb82ae92d3bfbe003d..ae5f5a881c70446f5e0bfafdb1814e98155c18e2 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.db.component;
 
 import com.google.common.collect.Lists;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import javax.annotation.CheckForNull;
@@ -66,6 +67,18 @@ public class SnapshotDao implements Dao {
     return executeLargeInputs(snapshotIds, mapper(dbSession)::selectByIds);
   }
 
+  public Optional<SnapshotDto> selectByUuid(DbSession dbSession, String analysisUuid) {
+    List<SnapshotDto> dtos = mapper(dbSession).selectByUuids(Collections.singletonList(analysisUuid));
+    if (dtos.isEmpty()) {
+      return Optional.empty();
+    }
+    return Optional.of(dtos.iterator().next());
+  }
+
+  public List<SnapshotDto> selectByUuids(DbSession dbSession, Collection<String> analysisUuids) {
+    return executeLargeInputs(analysisUuids, mapper(dbSession)::selectByUuids);
+  }
+
   public Optional<SnapshotDto> selectLastAnalysisByComponentUuid(DbSession session, String componentUuid) {
     return Optional.ofNullable(mapper(session).selectLastSnapshotByComponentUuid(componentUuid));
   }
@@ -108,10 +121,6 @@ public class SnapshotDao implements Dao {
     return snapshotDtos.isEmpty() ? null : snapshotDtos.get(0);
   }
 
-  public Optional<SnapshotDto> selectByUuid(DbSession dbSession, String analysisUuid) {
-    return Optional.ofNullable(mapper(dbSession).selectByUuid(analysisUuid));
-  }
-
   public void switchIsLastFlagAndSetProcessedStatus(DbSession dbSession, String componentUuid, String analysisUuid) {
     SnapshotMapper mapper = mapper(dbSession);
     mapper.unsetIsLastFlagForComponentUuid(componentUuid);
index b235f4f8dc020b946e6a2fdaf7912594f2d27d82..c5c7aef8f5cd5ad6a637ebc58840136b00dd2df8 100644 (file)
@@ -32,6 +32,8 @@ public interface SnapshotMapper {
 
   List<SnapshotDto> selectByIds(@Param("ids") List<Long> ids);
 
+  List<SnapshotDto> selectByUuids(@Param("uuids") List<String> uuids);
+
   void insert(SnapshotDto snapshot);
 
   @CheckForNull
@@ -50,9 +52,6 @@ public interface SnapshotMapper {
 
   List<ViewsSnapshotDto> selectSnapshotBefore(@Param("componentUuid") String componentUuid, @Param("date") long date);
 
-  @CheckForNull
-  SnapshotDto selectByUuid(String analysisUuid);
-
   void unsetIsLastFlagForComponentUuid(@Param("componentUuid") String componentUuid);
 
   void setIsLastFlagForAnalysisUuid(@Param("analysisUuid") String analysisUuid);
index c5e7f2e283ce7b44bb21954931963391c1b7c353..98166bd23c14e44350e39b7ed176bd6ca23e25ad 100644 (file)
     </where>
   </select>
 
-  <select id="selectByUuid" parameterType="String" resultType="Snapshot">
+  <select id="selectByIds" parameterType="Long" resultType="Snapshot">
     SELECT
-    <include refid="snapshotColumns"/>
-    FROM snapshots s
-    WHERE s.uuid=#{uuid}
+      <include refid="snapshotColumns" />
+    FROM
+      snapshots s
+    WHERE
+      s.id in
+      <foreach collection="ids" item="id" separator="," open="(" close=")">
+        #{id}
+      </foreach>
   </select>
 
-  <select id="selectByIds" parameterType="Long" resultType="Snapshot">
+  <select id="selectByUuids" parameterType="List" resultType="Snapshot">
     SELECT
-    <include refid="snapshotColumns" />
-    FROM snapshots s
+      <include refid="snapshotColumns"/>
+    FROM
+      snapshots s
     WHERE
-    s.id in
-    <foreach collection="ids" item="id" separator="," open="(" close=")">
-      #{id}
-    </foreach>
+      s.uuid in
+      <foreach collection="uuids" item="uuid" separator="," open="(" close=")">
+        #{uuid}
+      </foreach>
   </select>
 
   <select id="selectLastSnapshotByComponentUuid" resultType="Snapshot">