]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9040 CeQueueDao#selectEligibleForPeek returns executionCount
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 27 Mar 2017 10:43:06 +0000 (12:43 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Thu, 27 Apr 2017 07:23:18 +0000 (09:23 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/EligibleTaskDto.java [new file with mode: 0644]
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml

index d85b5e82ef7a1cce9a07cd701629cf93bc7b8188..2489f33ca055f2c72000bfdcab2273179d5e3d79 100644 (file)
@@ -110,24 +110,24 @@ public class CeQueueDao implements Dao {
   }
 
   public Optional<CeQueueDto> peek(DbSession session) {
-    List<String> taskUuids = mapper(session).selectEligibleForPeek(ONE_ROW_LIMIT);
-    if (taskUuids.isEmpty()) {
+    List<EligibleTaskDto> eligibles = mapper(session).selectEligibleForPeek(ONE_ROW_LIMIT);
+    if (eligibles.isEmpty()) {
       return Optional.absent();
     }
 
-    String taskUuid = taskUuids.get(0);
-    return tryToPeek(session, taskUuid);
+    EligibleTaskDto eligible = eligibles.get(0);
+    return tryToPeek(session, eligible);
   }
 
-  private Optional<CeQueueDto> tryToPeek(DbSession session, String taskUuid) {
-    int touchedRows = mapper(session).updateIf(taskUuid,
+  private Optional<CeQueueDto> tryToPeek(DbSession session, EligibleTaskDto eligible) {
+    int touchedRows = mapper(session).updateIf(eligible.getUuid(),
       new UpdateIf.NewProperties(IN_PROGRESS, system2.now(), system2.now()),
       new UpdateIf.OldProperties(PENDING));
     if (touchedRows != 1) {
       return Optional.absent();
     }
 
-    CeQueueDto result = mapper(session).selectByUuid(taskUuid);
+    CeQueueDto result = mapper(session).selectByUuid(eligible.getUuid());
     session.commit();
     return Optional.of(result);
   }
index ecaaa0c9130d99f12c9c2b5c6cb9095abe7b695d..b89569f01f4093244daf330362b83b994bbab556 100644 (file)
@@ -35,7 +35,7 @@ public interface CeQueueMapper {
 
   int countByQuery(@Param("query") CeTaskQuery query);
 
-  List<String> selectEligibleForPeek(RowBounds rowBounds);
+  List<EligibleTaskDto> selectEligibleForPeek(RowBounds rowBounds);
 
   @CheckForNull
   CeQueueDto selectByUuid(@Param("uuid") String uuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/EligibleTaskDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/EligibleTaskDto.java
new file mode 100644 (file)
index 0000000..fb43fcd
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.ce;
+
+public class EligibleTaskDto {
+  private String uuid;
+  private int executionCount;
+
+  public String getUuid() {
+    return uuid;
+  }
+
+  public EligibleTaskDto setUuid(String uuid) {
+    this.uuid = uuid;
+    return this;
+  }
+
+  public int getExecutionCount() {
+    return executionCount;
+  }
+
+  public EligibleTaskDto setExecutionCount(int executionCount) {
+    this.executionCount = executionCount;
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    return "EligibleTaskDto{" +
+        "uuid='" + uuid + '\'' +
+        ", executionCount=" + executionCount +
+        '}';
+  }
+}
index b7fa15219e137f1a2fe188479789c54f432aff27..9c36c58406784012b800d18f17814df502d202b7 100644 (file)
     </where>
   </sql>
 
-  <select id="selectEligibleForPeek" resultType="String">
+  <select id="selectEligibleForPeek" resultType="org.sonar.db.ce.EligibleTaskDto">
     select
-      cq.uuid
+      cq.uuid as "uuid",
+      cq.execution_count as "executionCount"
     from
       ce_queue cq
     where