You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CeQueueMapper.xml 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
  3. <mapper namespace="org.sonar.db.ce.CeQueueMapper">
  4. <sql id="columns">
  5. cq.uuid,
  6. cq.task_type as taskType,
  7. cq.component_uuid as componentUuid,
  8. cq.main_component_uuid as mainComponentUuid,
  9. cq.status as status,
  10. cq.submitter_uuid as submitterUuid,
  11. cq.worker_uuid as workerUuid,
  12. cq.started_at as startedAt,
  13. cq.created_at as createdAt,
  14. cq.updated_at as updatedAt
  15. </sql>
  16. <sql id="orderByDateAndId">
  17. order by
  18. cq.created_at asc,
  19. cq.id asc
  20. </sql>
  21. <sql id="orderByDescDateAndId">
  22. order by
  23. cq.created_at desc,
  24. cq.id desc
  25. </sql>
  26. <select id="selectByUuid" parameterType="String" resultType="org.sonar.db.ce.CeQueueDto">
  27. select
  28. <include refid="columns"/>
  29. from
  30. ce_queue cq
  31. where
  32. cq.uuid=#{uuid,jdbcType=VARCHAR}
  33. </select>
  34. <select id="countByStatusAndMainComponentUuid" parameterType="map" resultType="int">
  35. select
  36. count(1)
  37. from
  38. ce_queue
  39. where
  40. status=#{status,jdbcType=VARCHAR}
  41. <if test="mainComponentUuid!=null">
  42. and main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
  43. </if>
  44. </select>
  45. <select id="selectCreationDateOfOldestPendingByMainComponentUuid" parameterType="map" resultType="Long">
  46. select
  47. min(created_at)
  48. from
  49. ce_queue
  50. where
  51. status='PENDING'
  52. <if test="mainComponentUuid!=null">
  53. and main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
  54. </if>
  55. </select>
  56. <select id="countByStatusAndMainComponentUuids" resultType="org.sonar.db.ce.QueueCount">
  57. select
  58. main_component_uuid as mainComponentUuid,
  59. count(1) as total
  60. from
  61. ce_queue
  62. where
  63. status=#{status,jdbcType=VARCHAR}
  64. and main_component_uuid in
  65. <foreach collection="mainComponentUuids" open="(" close=")" item="mainComponentUuid" separator=",">
  66. #{mainComponentUuid,jdbcType=VARCHAR}
  67. </foreach>
  68. group by main_component_uuid
  69. </select>
  70. <select id="countAll" resultType="int">
  71. select
  72. count(1)
  73. from
  74. ce_queue
  75. </select>
  76. <select id="selectByMainComponentUuid" parameterType="String" resultType="org.sonar.db.ce.CeQueueDto">
  77. select
  78. <include refid="columns"/>
  79. from
  80. ce_queue cq
  81. where
  82. cq.main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
  83. <include refid="orderByDateAndId"/>
  84. </select>
  85. <select id="selectAllInAscOrder" resultType="org.sonar.db.ce.CeQueueDto">
  86. select
  87. <include refid="columns"/>
  88. from
  89. ce_queue cq
  90. <include refid="orderByDateAndId"/>
  91. </select>
  92. <select id="selectByQueryInDescOrder" resultType="org.sonar.db.ce.CeQueueDto">
  93. select
  94. <include refid="columns"/>
  95. <include refid="sqlSelectByQuery"/>
  96. <include refid="orderByDescDateAndId"/>
  97. </select>
  98. <select id="countByQuery" resultType="int">
  99. select
  100. count(1)
  101. <include refid="sqlSelectByQuery"/>
  102. </select>
  103. <sql id="sqlSelectByQuery">
  104. from
  105. ce_queue cq
  106. <where>
  107. <if test="query.mainComponentUuids != null and query.mainComponentUuids.size()>0">
  108. and cq.main_component_uuid in
  109. <foreach collection="query.mainComponentUuids" open="(" close=")" item="mainComponentUuid" separator=",">
  110. #{mainComponentUuid,jdbcType=VARCHAR}
  111. </foreach>
  112. </if>
  113. <if test="query.statuses != null">
  114. and cq.status in
  115. <foreach collection="query.statuses" open="(" close=")" item="status" separator=",">
  116. #{status,jdbcType=VARCHAR}
  117. </foreach>
  118. </if>
  119. <if test="query.type != null">
  120. and cq.task_type=#{query.type,jdbcType=VARCHAR}
  121. </if>
  122. <if test="query.minSubmittedAt != null">
  123. and cq.created_at &gt;= #{query.minSubmittedAt,jdbcType=BIGINT}
  124. </if>
  125. </where>
  126. </sql>
  127. <select id="selectEligibleForPeek" resultType="String">
  128. select cq.uuid
  129. <include refid="sqlSelectEligibleForPeek"/>
  130. <include refid="orderBySelectEligibleForPeek"/>
  131. limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
  132. </select>
  133. <select id="selectEligibleForPeek" parameterType="map" resultType="String" databaseId="mssql">
  134. select query.uuid from (
  135. select
  136. row_number() over(<include refid="orderBySelectEligibleForPeek"/>) as number,
  137. <include refid="columnsSelectEligibleForPeek"/>
  138. <include refid="sqlSelectEligibleForPeek"/>
  139. ) as query
  140. where
  141. query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
  142. <include refid="orderBySelectEligibleForPeek"/>
  143. </select>
  144. <select id="selectEligibleForPeek" parameterType="map" resultType="String" databaseId="oracle">
  145. select taskuuid from (
  146. select rownum as rn, t."uuid" as taskuuid from (
  147. select
  148. <include refid="columnsSelectEligibleForPeek"/>
  149. <include refid="sqlSelectEligibleForPeek" />
  150. <include refid="orderBySelectEligibleForPeek"/>
  151. ) t
  152. ) t
  153. where
  154. t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
  155. </select>
  156. <sql id="columnsSelectEligibleForPeek">
  157. cq.uuid as "uuid",
  158. cq.created_at as "created_at",
  159. cq.id as "id"
  160. </sql>
  161. <sql id="sqlSelectEligibleForPeek">
  162. from
  163. ce_queue cq
  164. where
  165. cq.status='PENDING'
  166. and cq.started_at is null
  167. and not exists (
  168. select
  169. 1
  170. from
  171. ce_queue cq2
  172. where
  173. cq.main_component_uuid=cq2.main_component_uuid
  174. and cq2.status &lt;&gt; 'PENDING'
  175. )
  176. </sql>
  177. <sql id="orderBySelectEligibleForPeek">
  178. order by
  179. created_at asc,
  180. id asc
  181. </sql>
  182. <select id="selectPending" resultType="org.sonar.db.ce.CeQueueDto">
  183. select
  184. <include refid="columns"/>
  185. from
  186. ce_queue cq
  187. where
  188. cq.status = 'PENDING'
  189. </select>
  190. <select id="selectWornout" resultType="org.sonar.db.ce.CeQueueDto">
  191. select
  192. <include refid="columns"/>
  193. from
  194. ce_queue cq
  195. where
  196. cq.status = 'PENDING'
  197. and cq.started_at is not null
  198. </select>
  199. <select id="selectInProgressStartedBefore" resultType="org.sonar.db.ce.CeQueueDto">
  200. select
  201. <include refid="columns"/>
  202. from
  203. ce_queue cq
  204. where
  205. cq.status = 'IN_PROGRESS'
  206. and cq.started_at is not null
  207. and cq.started_at &lt; #{date,jdbcType=BIGINT}
  208. </select>
  209. <insert id="insert" parameterType="org.sonar.db.ce.CeQueueDto" useGeneratedKeys="false">
  210. insert into ce_queue
  211. (
  212. uuid,
  213. task_type,
  214. component_uuid,
  215. main_component_uuid,
  216. status,
  217. submitter_uuid,
  218. worker_uuid,
  219. execution_count,
  220. created_at,
  221. updated_at,
  222. started_at
  223. )
  224. values (
  225. #{uuid,jdbcType=VARCHAR},
  226. #{taskType,jdbcType=VARCHAR},
  227. #{componentUuid,jdbcType=VARCHAR},
  228. #{mainComponentUuid,jdbcType=VARCHAR},
  229. #{status,jdbcType=VARCHAR},
  230. #{submitterUuid,jdbcType=VARCHAR},
  231. #{workerUuid,jdbcType=VARCHAR},
  232. 0,
  233. #{createdAt,jdbcType=BIGINT},
  234. #{updatedAt,jdbcType=BIGINT},
  235. #{startedAt,jdbcType=BIGINT}
  236. )
  237. </insert>
  238. <update id="resetToPendingForWorker">
  239. update ce_queue set
  240. status='PENDING',
  241. updated_at=#{updatedAt,jdbcType=BIGINT}
  242. where
  243. status &lt;&gt; 'PENDING'
  244. and worker_uuid = #{workerUuid,jdbcType=VARCHAR}
  245. </update>
  246. <update id="updateIf" parameterType="map">
  247. update ce_queue set
  248. status=#{new.status,jdbcType=VARCHAR},
  249. worker_uuid=#{new.workerUuid,jdbcType=VARCHAR},
  250. started_at=#{new.startedAt,jdbcType=BIGINT},
  251. updated_at=#{new.updatedAt,jdbcType=BIGINT}
  252. where
  253. uuid=#{uuid,jdbcType=VARCHAR}
  254. and status=#{old.status,jdbcType=VARCHAR}
  255. </update>
  256. <delete id="deleteByUuid">
  257. delete from
  258. ce_queue
  259. where
  260. uuid=#{uuid,jdbcType=VARCHAR}
  261. <if test="deleteIf != null">
  262. and status = #{deleteIf.expectedStatus,jdbcType=VARCHAR}
  263. </if>
  264. </delete>
  265. <update id="resetTasksWithUnknownWorkerUUIDs">
  266. update ce_queue set
  267. status='PENDING',
  268. worker_uuid=NULL,
  269. updated_at=#{updatedAt,jdbcType=BIGINT}
  270. where
  271. status = 'IN_PROGRESS'
  272. and (
  273. worker_uuid is NULL
  274. or worker_uuid not in
  275. <foreach collection="knownWorkerUUIDs" open="(" close=")" item="workerUUID" separator=",">
  276. #{workerUUID,jdbcType=VARCHAR}
  277. </foreach>
  278. )
  279. </update>
  280. <update id="resetAllInProgressTasks">
  281. update ce_queue set
  282. status='PENDING',
  283. worker_uuid=NULL,
  284. updated_at=#{updatedAt,jdbcType=BIGINT}
  285. where
  286. status = 'IN_PROGRESS'
  287. </update>
  288. </mapper>