]> source.dussan.org Git - sonarqube.git/commitdiff
Fix oracle selects with case for issue sync progress
authorJacek <jacek.poreda@sonarsource.com>
Mon, 29 Jun 2020 08:04:59 +0000 (10:04 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 30 Jun 2020 20:05:41 +0000 (20:05 +0000)
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/resources/org/sonar/db/ce/CeActivityMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java

index 8b396644d2bee1f7cc04673070a58d9bbfbb9c1d..2cd18110226c727fb664a41e1c8f30a194d3a852 100644 (file)
@@ -191,7 +191,7 @@ public class CeQueueDao implements Dao {
   }
 
   public boolean hasAnyIssueSyncTaskPendingOrInProgress(DbSession dbSession) {
-    return mapper(dbSession).hasAnyIssueSyncTaskPendingOrInProgress() > 0;
+    return mapper(dbSession).hasAnyIssueSyncTaskPendingOrInProgress();
   }
 
   private static CeQueueMapper mapper(DbSession session) {
index 8483d81a10918ee8c0093c8431ceba7c35783a44..aa3b5f5206ff3e1368b7c0c45b12649b37cbf6f8 100644 (file)
@@ -85,6 +85,6 @@ public interface CeQueueMapper {
 
   int deleteByUuid(@Param("uuid") String uuid, @Nullable @Param("deleteIf") DeleteIf deleteIf);
 
-  short hasAnyIssueSyncTaskPendingOrInProgress();
+  boolean hasAnyIssueSyncTaskPendingOrInProgress();
 
 }
index 1cf33d044f39896ac7bc6d87fbeb6734dd8d940c..cc24d1b5dab2c3aff11375f9d684c97d5e91c336 100644 (file)
     and ca.is_last = ${_true}
   </select>
 
-  <select id="hasAnyFailedIssueSyncTask" parameterType="map" resultType="short">
+  <sql id="hasAnyFailedIssueSyncTaskSql">
     select
     case when exists
     (
-    select ca.uuid from ce_activity ca where ca.task_type = 'ISSUE_SYNC' and status = 'FAILED'
-    and exists(select pb.uuid from project_branches pb where ca.component_uuid = pb.uuid and pb.need_issue_sync = ${_true})
+    select ca.uuid from ce_activity ca inner join project_branches pb on ca.component_uuid = pb.uuid
+    where ca.task_type = 'ISSUE_SYNC'
+    and ca.status = 'FAILED'
+    and pb.need_issue_sync = ${_true}
     )
     then 1
     else 0
     end
+  </sql>
+
+  <select id="hasAnyFailedIssueSyncTask" parameterType="map" resultType="short" >
+    <include refid="hasAnyFailedIssueSyncTaskSql"/>
+  </select>
+
+  <select id="hasAnyFailedIssueSyncTask" parameterType="map" resultType="short" databaseId="oracle">
+    <include refid="hasAnyFailedIssueSyncTaskSql"/>
+    from dual
   </select>
 
   <select id="selectByTaskType" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto">
index d4b115258dcdedbe46abfb664d8a00469114868c..92003dda714b9f9ed7b9238c83f8da6a4e147e71 100644 (file)
     ) as query
     where
     query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
-    <include refid="orderBySelectEligibleForPeek"/>
+    order by number asc
   </select>
 
   <select id="selectEligibleForPeek" parameterType="map" resultType="String" databaseId="oracle">
       status = 'IN_PROGRESS'
   </update>
 
-  <select id="hasAnyIssueSyncTaskPendingOrInProgress" parameterType="map" resultType="short">
+  <sql id="hasAnyIssueSyncTaskPendingOrInProgressSql">
     select
     case when exists
     (
     then 1
     else 0
     end
+  </sql>
+
+  <select id="hasAnyIssueSyncTaskPendingOrInProgress" parameterType="map" resultType="boolean">
+    <include refid="hasAnyIssueSyncTaskPendingOrInProgressSql"/>
+  </select>
+
+  <select id="hasAnyIssueSyncTaskPendingOrInProgress" parameterType="map" resultType="boolean" databaseId="oracle">
+    <include refid="hasAnyIssueSyncTaskPendingOrInProgressSql"/>
+    from dual
   </select>
 
 </mapper>
index e94c442cdf2ef0c2e08cec52c809704279bc69ed..af4785fd8d97c0ea0a0b61e3d0d5dc9e24e0d2e4 100644 (file)
     and pb.created_at &gt;= #{sinceDate, jdbcType=BIGINT}
   </select>
 
-  <select id="hasAnyBranchWhereNeedIssueSync" parameterType="map" resultType="short">
+  <sql id="hasAnyBranchWhereNeedIssueSyncSql">
     select
     case when exists
     (
     then 1
     else 0
     end
+  </sql>
+
+  <select id="hasAnyBranchWhereNeedIssueSync" parameterType="map" resultType="short">
+    <include refid="hasAnyBranchWhereNeedIssueSyncSql"/>
+  </select>
+
+  <select id="hasAnyBranchWhereNeedIssueSync" parameterType="map" resultType="short" databaseId="oracle">
+    <include refid="hasAnyBranchWhereNeedIssueSyncSql"/>
+    from dual
   </select>
 
   <select id="countByNeedIssueSync" parameterType="map" resultType="int">
       uuid = #{uuid, jdbcType=VARCHAR}
   </update>
 
-  <select id="doAnyOfComponentsNeedIssueSync" parameterType="map" resultType="short">
+  <sql id="doAnyOfComponentsNeedIssueSyncSql">
     select
     case when exists
     (
     then 1
     else 0
     end
+  </sql>
+
+  <select id="doAnyOfComponentsNeedIssueSync" parameterType="map" resultType="short">
+    <include refid="doAnyOfComponentsNeedIssueSyncSql"/>
+  </select>
+
+  <select id="doAnyOfComponentsNeedIssueSync" parameterType="map" resultType="short" databaseId="oracle">
+    <include refid="doAnyOfComponentsNeedIssueSyncSql"/>
+    from dual
   </select>
 
 </mapper>
index 0254590f60ab83997b2e6758f7d3f5820c73eae8..1694f814ea0827f126ca0de3d35ba0aaae76b27e 100644 (file)
     order by ncloc desc
   </select>
 
-  <select id="checkIfAnyOfComponentsWithQualifiers" resultType="short">
+  <sql id="checkIfAnyOfComponentsWithQualifiersSql">
     select
     case when exists
     (
     then 1
     else 0
     end
+  </sql>
+
+  <select id="checkIfAnyOfComponentsWithQualifiers" resultType="short">
+    <include refid="checkIfAnyOfComponentsWithQualifiersSql"/>
+  </select>
+
+  <select id="checkIfAnyOfComponentsWithQualifiers" resultType="short" databaseId="oracle">
+    <include refid="checkIfAnyOfComponentsWithQualifiersSql"/>
+    from dual
   </select>
 </mapper>
index f6b86a5d3ad80f3a34bb71270e1713ca4f54f5d8..21b8b38be47af8dff724fe68409da5a855d71103 100644 (file)
@@ -688,6 +688,7 @@ public class CeQueueDaoTest {
   private void insertView(String view_uuid) {
     ComponentDto view = new ComponentDto();
     view.setQualifier("VW");
+    view.setDbKey(view_uuid + "_key");
     view.setUuid(view_uuid);
     view.setOrganizationUuid("org_uuid");
     view.setPrivate(false);
@@ -701,6 +702,7 @@ public class CeQueueDaoTest {
   private void insertBranch(String uuid) {
     ComponentDto branch = new ComponentDto();
     branch.setQualifier("TRK");
+    branch.setDbKey(uuid + "_key");
     branch.setUuid(uuid);
     branch.setOrganizationUuid("org_uuid");
     branch.setPrivate(false);