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.

IssueMapper.xml 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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.issue.IssueMapper">
  4. <sql id="issueColumns">
  5. i.kee as kee,
  6. i.rule_uuid as ruleUuid,
  7. i.severity as severity,
  8. i.manual_severity as manualSeverity,
  9. i.message as message,
  10. i.message_formattings as messageFormattings,
  11. i.line as line,
  12. i.locations as locations,
  13. i.gap as gap,
  14. i.effort as effort,
  15. i.status as status,
  16. i.resolution as resolution,
  17. i.checksum as checksum,
  18. i.assignee as assigneeUuid,
  19. i.author_login as authorLogin,
  20. i.tags as tagsString,
  21. i.rule_description_context_key as ruleDescriptionContextKey,
  22. i.issue_creation_date as issueCreationTime,
  23. i.issue_update_date as issueUpdateTime,
  24. i.issue_close_date as issueCloseTime,
  25. i.created_at as createdAt,
  26. i.updated_at as updatedAt,
  27. r.is_external as "isExternal",
  28. r.plugin_rule_key as ruleKey,
  29. r.plugin_name as ruleRepo,
  30. r.language as language,
  31. r.security_standards as securityStandards,
  32. p.kee as componentKey,
  33. i.component_uuid as componentUuid,
  34. p.path as filePath,
  35. root.kee as projectKey,
  36. i.project_uuid as projectUuid,
  37. i.issue_type as type,
  38. i.quick_fix_available as quickFixAvailable,
  39. i.code_variants as codeVariantsString,
  40. <include refid="isNewCodeReferenceIssue"/>
  41. </sql>
  42. <sql id="issueColumnsInInnerQuery">
  43. i.kee,
  44. i.rule_uuid,
  45. i.severity,
  46. i.manual_severity,
  47. i.message,
  48. i.message_formattings,
  49. i.line,
  50. i.locations,
  51. i.gap,
  52. i.effort,
  53. i.status,
  54. i.resolution,
  55. i.checksum,
  56. i.assignee,
  57. i.author_login,
  58. i.tags,
  59. i.rule_description_context_key,
  60. i.issue_creation_date,
  61. i.issue_update_date,
  62. i.issue_close_date,
  63. i.created_at,
  64. i.updated_at,
  65. i.component_uuid,
  66. i.project_uuid,
  67. i.issue_type,
  68. i.quick_fix_available,
  69. i.code_variants
  70. </sql>
  71. <sql id="isNewCodeReferenceIssue" databaseId="mssql">
  72. cast(case when n.uuid is null then 0 else 1 end as bit) as isNewCodeReferenceIssue
  73. </sql>
  74. <sql id="isNewCodeReferenceIssue" databaseId="oracle">
  75. case when n.uuid is null then 0 else 1 end as isNewCodeReferenceIssue
  76. </sql>
  77. <sql id="isNewCodeReferenceIssue">
  78. n.uuid is not null as isNewCodeReferenceIssue
  79. </sql>
  80. <sql id="sortColumn">
  81. <if test="query.sort() != null">,
  82. <choose>
  83. <when test="'SEVERITY'.equals(query.sort())">
  84. i.severity as severity
  85. </when>
  86. <when test="'STATUS'.equals(query.sort())">
  87. i.status as status
  88. </when>
  89. <when test="'ASSIGNEE'.equals(query.sort())">
  90. i.assignee as assigneeUuid
  91. </when>
  92. <when test="'CREATION_DATE'.equals(query.sort())">
  93. i.issue_creation_date as issueCreationTime
  94. </when>
  95. <when test="'UPDATE_DATE'.equals(query.sort())">
  96. i.issue_update_date as issueUpdateTime
  97. </when>
  98. <when test="'CLOSE_DATE'.equals(query.sort())">
  99. i.issue_close_date as issueCloseTime
  100. </when>
  101. </choose>
  102. </if>
  103. </sql>
  104. <insert id="insert" parameterType="Issue" useGeneratedKeys="false">
  105. INSERT INTO issues (kee, rule_uuid, severity, manual_severity,
  106. message, message_formattings, line, locations, gap, effort, status, tags, rule_description_context_key,
  107. resolution, checksum, assignee, author_login, issue_creation_date, issue_update_date,
  108. issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type, quick_fix_available, code_variants)
  109. VALUES (
  110. #{kee,jdbcType=VARCHAR},
  111. #{ruleUuid,jdbcType=VARCHAR},
  112. #{severity,jdbcType=VARCHAR},
  113. #{manualSeverity,jdbcType=BOOLEAN},
  114. #{message,jdbcType=VARCHAR},
  115. #{messageFormattings,jdbcType=BINARY},
  116. #{line,jdbcType=INTEGER},
  117. #{locations,jdbcType=BINARY},
  118. #{gap,jdbcType=DOUBLE}, #{effort,jdbcType=INTEGER}, #{status,jdbcType=VARCHAR},
  119. #{tagsString,jdbcType=VARCHAR},
  120. #{ruleDescriptionContextKey,jdbcType=VARCHAR},
  121. #{resolution,jdbcType=VARCHAR},
  122. #{checksum,jdbcType=VARCHAR},
  123. #{assigneeUuid,jdbcType=VARCHAR},
  124. #{authorLogin,jdbcType=VARCHAR},
  125. #{issueCreationTime,jdbcType=BIGINT},#{issueUpdateTime,jdbcType=BIGINT}, #{issueCloseTime,jdbcType=BIGINT},
  126. #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT},
  127. #{componentUuid,jdbcType=VARCHAR}, #{projectUuid,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER},
  128. #{quickFixAvailable, jdbcType=BOOLEAN},
  129. #{codeVariantsString,jdbcType=VARCHAR})
  130. </insert>
  131. <insert id="insertAsNewCodeOnReferenceBranch" parameterType="NewCodeReferenceIssue" useGeneratedKeys="false">
  132. INSERT INTO new_code_reference_issues (uuid, issue_key, created_at)
  133. VALUES (
  134. #{uuid,jdbcType=VARCHAR},
  135. #{issueKey,jdbcType=VARCHAR},
  136. #{createdAt,jdbcType=BIGINT})
  137. </insert>
  138. <insert id="deleteAsNewCodeOnReferenceBranch" parameterType="String" useGeneratedKeys="false">
  139. DELETE FROM new_code_reference_issues
  140. where issue_key = #{issueKey, jdbcType=VARCHAR}
  141. </insert>
  142. <!--
  143. IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate()
  144. -->
  145. <update id="update" parameterType="Issue">
  146. update issues set
  147. severity=#{severity,jdbcType=VARCHAR},
  148. manual_severity=#{manualSeverity,jdbcType=BOOLEAN},
  149. message=#{message,jdbcType=VARCHAR},
  150. message_formattings=#{messageFormattings,jdbcType=BINARY},
  151. line=#{line,jdbcType=INTEGER},
  152. locations=#{locations,jdbcType=BINARY},
  153. gap=#{gap,jdbcType=DOUBLE},
  154. effort=#{effort,jdbcType=INTEGER},
  155. status=#{status,jdbcType=VARCHAR},
  156. resolution=#{resolution,jdbcType=VARCHAR},
  157. checksum=#{checksum,jdbcType=VARCHAR},
  158. assignee=#{assigneeUuid,jdbcType=VARCHAR},
  159. author_login=#{authorLogin,jdbcType=VARCHAR},
  160. tags=#{tagsString,jdbcType=VARCHAR},
  161. rule_description_context_key=#{ruleDescriptionContextKey,jdbcType=VARCHAR},
  162. project_uuid=#{projectUuid,jdbcType=VARCHAR},
  163. issue_creation_date=#{issueCreationTime,jdbcType=BIGINT},
  164. issue_update_date=#{issueUpdateTime,jdbcType=BIGINT},
  165. issue_close_date=#{issueCloseTime,jdbcType=BIGINT},
  166. updated_at=#{updatedAt,jdbcType=BIGINT},
  167. issue_type=#{type,jdbcType=INTEGER},
  168. code_variants=#{codeVariantsString,jdbcType=VARCHAR}
  169. where kee = #{kee}
  170. </update>
  171. <!--
  172. IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate()
  173. -->
  174. <update id="updateIfBeforeSelectedDate" parameterType="Issue">
  175. update issues set
  176. severity=#{severity,jdbcType=VARCHAR},
  177. manual_severity=#{manualSeverity,jdbcType=BOOLEAN},
  178. message=#{message,jdbcType=VARCHAR},
  179. message_formattings=#{messageFormattings,jdbcType=BINARY},
  180. line=#{line,jdbcType=INTEGER},
  181. locations=#{locations,jdbcType=BINARY},
  182. gap=#{gap,jdbcType=DOUBLE},
  183. effort=#{effort,jdbcType=INTEGER},
  184. status=#{status,jdbcType=VARCHAR},
  185. resolution=#{resolution,jdbcType=VARCHAR},
  186. checksum=#{checksum,jdbcType=VARCHAR},
  187. assignee=#{assigneeUuid,jdbcType=VARCHAR},
  188. author_login=#{authorLogin,jdbcType=VARCHAR},
  189. tags=#{tagsString,jdbcType=VARCHAR},
  190. rule_description_context_key=#{ruleDescriptionContextKey,jdbcType=VARCHAR},
  191. component_uuid=#{componentUuid,jdbcType=VARCHAR},
  192. project_uuid=#{projectUuid,jdbcType=VARCHAR},
  193. issue_creation_date=#{issueCreationTime,jdbcType=BIGINT},
  194. issue_update_date=#{issueUpdateTime,jdbcType=BIGINT},
  195. issue_close_date=#{issueCloseTime,jdbcType=BIGINT},
  196. updated_at=#{updatedAt,jdbcType=BIGINT},
  197. issue_type=#{type,jdbcType=INTEGER},
  198. code_variants=#{codeVariantsString,jdbcType=VARCHAR}
  199. where kee = #{kee} and updated_at &lt;= #{selectedAt}
  200. </update>
  201. <select id="selectByKey" parameterType="String" resultType="Issue">
  202. select
  203. <include refid="issueColumns"/>,
  204. u.login as assigneeLogin
  205. from issues i
  206. inner join rules r on r.uuid=i.rule_uuid
  207. inner join components p on p.uuid=i.component_uuid
  208. inner join components root on root.uuid=i.project_uuid
  209. left join users u on i.assignee = u.uuid
  210. left join new_code_reference_issues n on i.kee = n.issue_key
  211. where i.kee=#{kee,jdbcType=VARCHAR}
  212. </select>
  213. <select id="scrollNonClosedByComponentUuid" parameterType="String" resultType="Issue" fetchSize="${_scrollFetchSize}"
  214. resultSetType="FORWARD_ONLY">
  215. select
  216. <include refid="issueColumns"/>
  217. from issues i
  218. inner join rules r on r.uuid=i.rule_uuid
  219. inner join components p on p.uuid=i.component_uuid
  220. inner join components root on root.uuid=i.project_uuid
  221. left join new_code_reference_issues n on i.kee = n.issue_key
  222. where
  223. i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
  224. i.status &lt;&gt; 'CLOSED'
  225. </select>
  226. <select id="scrollClosedByComponentUuid" resultType="Issue" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
  227. select
  228. <include refid="issueColumns"/>,
  229. ic.change_data as closedChangeData
  230. from issues i
  231. inner join rules r on
  232. r.uuid = i.rule_uuid
  233. inner join components p on
  234. p.uuid = i.component_uuid
  235. inner join components root on
  236. root.uuid = i.project_uuid
  237. inner join issue_changes ic on
  238. ic.issue_key = i.kee
  239. and ic.change_type = 'diff'
  240. and ic.change_data like '%status=%|CLOSED%'
  241. left join new_code_reference_issues n on
  242. i.kee = n.issue_key
  243. where
  244. i.component_uuid = #{componentUuid,jdbcType=VARCHAR}
  245. and i.status = 'CLOSED'
  246. and i.issue_close_date is not null
  247. and i.issue_close_date &gt;= #{closeDateAfter,jdbcType=BIGINT}
  248. order by
  249. i.kee, ic.issue_change_creation_date desc
  250. </select>
  251. <select id="selectComponentUuidsOfOpenIssuesForProjectUuid" parameterType="string" resultType="string">
  252. select distinct(i.component_uuid)
  253. from issues i
  254. where i.project_uuid=#{projectUuid,jdbcType=VARCHAR} and i.status &lt;&gt; 'CLOSED'
  255. </select>
  256. <select id="selectByKeys" parameterType="map" resultType="Issue">
  257. select
  258. <include refid="issueColumns"/>
  259. from issues i
  260. inner join rules r on r.uuid=i.rule_uuid
  261. inner join components p on p.uuid=i.component_uuid
  262. inner join components root on root.uuid=i.project_uuid
  263. left join new_code_reference_issues n on i.kee = n.issue_key
  264. where i.kee in
  265. <foreach collection="list" open="(" close=")" item="key" separator=",">
  266. #{key,jdbcType=VARCHAR}
  267. </foreach>
  268. </select>
  269. <select id="selectByKeysIfNotUpdatedAt" parameterType="map" resultType="Issue">
  270. select
  271. <include refid="issueColumns"/>
  272. from issues i
  273. inner join rules r on r.uuid=i.rule_uuid
  274. inner join components p on p.uuid=i.component_uuid
  275. inner join components root on root.uuid=i.project_uuid
  276. left join new_code_reference_issues n on i.kee = n.issue_key
  277. where
  278. i.kee in
  279. <foreach collection="keys" open="(" close=")" item="key" separator=",">
  280. #{key,jdbcType=VARCHAR}
  281. </foreach>
  282. and i.updated_at &lt;&gt; #{updatedAt,jdbcType=BIGINT}
  283. </select>
  284. <select id="selectOpenByComponentUuids" parameterType="map" resultType="PrIssue">
  285. select
  286. i.kee as kee,
  287. i.message as message,
  288. i.line as line,
  289. i.status as status,
  290. i.checksum as checksum,
  291. i.issue_update_date as issueUpdateDate,
  292. r.plugin_rule_key as ruleKey,
  293. r.plugin_name as ruleRepo,
  294. b.kee as branchKey,
  295. b.branch_type as branchType
  296. from issues i
  297. inner join rules r on r.uuid = i.rule_uuid
  298. inner join project_branches b on i.project_uuid = b.uuid
  299. where i.component_uuid in
  300. <foreach collection="list" open="(" close=")" item="key" separator=",">
  301. #{key,jdbcType=VARCHAR}
  302. </foreach>
  303. and i.status &lt;&gt; 'CLOSED'
  304. </select>
  305. <select id="selectIssueGroupsByComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map">
  306. select i.issue_type as ruleType, i.severity as severity, i.resolution as resolution, i.status as status, sum(i.effort) as effort, count(i.issue_type) as "count",
  307. <if test="leakPeriodBeginningDate &gt;= 0">
  308. (i.issue_creation_date &gt; #{leakPeriodBeginningDate,jdbcType=BIGINT}) as inLeak
  309. </if>
  310. <if test="leakPeriodBeginningDate &lt; 0">
  311. CASE WHEN n.uuid is null THEN false ELSE true END as inLeak
  312. </if>
  313. from issues i
  314. <if test="leakPeriodBeginningDate &lt; 0">
  315. left join new_code_reference_issues n on n.issue_key = i.kee
  316. </if>
  317. where i.status !='CLOSED'
  318. and i.component_uuid = #{component.uuid,jdbcType=VARCHAR}
  319. group by i.issue_type, i.severity, i.resolution, i.status, inLeak
  320. </select>
  321. <select id="selectIssueGroupsByComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map" databaseId="oracle">
  322. select i2.issue_type as ruleType, i2.severity as severity, i2.resolution as resolution, i2.status as status, sum(i2.effort) as effort, count(i2.issue_type) as "count", i2.inLeak as inLeak
  323. from (
  324. select i.issue_type, i.severity, i.resolution, i.status, i.effort,
  325. <if test="leakPeriodBeginningDate &gt;= 0">
  326. case when i.issue_creation_date &gt; #{leakPeriodBeginningDate,jdbcType=BIGINT} then 1 else 0 end as inLeak
  327. </if>
  328. <if test="leakPeriodBeginningDate &lt; 0">
  329. case when n.uuid is null then 0 else 1 end as inLeak
  330. </if>
  331. from issues i
  332. <if test="leakPeriodBeginningDate &lt; 0">
  333. left join new_code_reference_issues n on n.issue_key = i.kee
  334. </if>
  335. where i.status !='CLOSED'
  336. and i.component_uuid = #{component.uuid,jdbcType=VARCHAR}
  337. ) i2
  338. group by i2.issue_type, i2.severity, i2.resolution, i2.status, i2.inLeak
  339. </select>
  340. <select id="selectIssueGroupsByComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map" databaseId="mssql">
  341. select i2.issue_type as ruleType, i2.severity as severity, i2.resolution as resolution, i2.status as status, sum(i2.effort) as effort, count(i2.issue_type) as "count", i2.inLeak as inLeak
  342. from (
  343. select i.issue_type, i.severity, i.resolution, i.status, i.effort,
  344. <if test="leakPeriodBeginningDate &gt;= 0">
  345. case when i.issue_creation_date &gt; #{leakPeriodBeginningDate,jdbcType=BIGINT} then 1 else 0 end as inLeak
  346. </if>
  347. <if test="leakPeriodBeginningDate &lt; 0">
  348. case when n.uuid is null then 0 else 1 end as inLeak
  349. </if>
  350. from issues i
  351. <if test="leakPeriodBeginningDate &lt; 0">
  352. left join new_code_reference_issues n on n.issue_key = i.kee
  353. </if>
  354. where i.status !='CLOSED'
  355. and i.component_uuid = #{component.uuid,jdbcType=VARCHAR}
  356. ) i2
  357. group by i2.issue_type, i2.severity, i2.resolution, i2.status, i2.inLeak
  358. </select>
  359. <select id="selectIssueKeysByComponentUuid" parameterType="string" resultType="string">
  360. select
  361. i.kee
  362. from issues i
  363. where
  364. i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  365. </select>
  366. <select id="selectIssueKeysByComponentUuidWithFilters" parameterType="string" resultType="string">
  367. select
  368. i.kee
  369. from rules r
  370. inner join issues i on i.rule_uuid = r.uuid
  371. where
  372. i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  373. AND i.status &lt;&gt; 'CLOSED'
  374. <if test="includingRepositories.size() > 0">
  375. AND r.plugin_name IN
  376. <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
  377. #{ruleRepository}
  378. </foreach>
  379. </if>
  380. <if test="excludingRepositories.size() > 0">
  381. AND r.plugin_name NOT IN
  382. <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
  383. #{ruleRepository}
  384. </foreach>
  385. </if>
  386. <if test="languages.size() > 0">
  387. AND r.language IN
  388. <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
  389. #{language}
  390. </foreach>
  391. </if>
  392. order by i.kee
  393. limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
  394. </select>
  395. <select id="selectIssueKeysByComponentUuidWithFilters" parameterType="map" resultType="string" databaseId="mssql">
  396. select
  397. i.kee
  398. from
  399. (select
  400. row_number() over(order by i.kee ASC) as row_number,
  401. i.kee
  402. from rules r
  403. inner join issues i on i.rule_uuid = r.uuid
  404. where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  405. AND i.status &lt;&gt; 'CLOSED'
  406. <if test="includingRepositories.size() > 0">
  407. AND r.plugin_name IN
  408. <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
  409. #{ruleRepository}
  410. </foreach>
  411. </if>
  412. <if test="excludingRepositories.size() > 0">
  413. AND r.plugin_name NOT IN
  414. <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
  415. #{ruleRepository}
  416. </foreach>
  417. </if>
  418. <if test="languages.size() > 0">
  419. AND r.language IN
  420. <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
  421. #{language}
  422. </foreach>
  423. </if>
  424. order by row_number asc
  425. offset #{pagination.offset} rows
  426. fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only) i
  427. </select>
  428. <select id="selectIssueKeysByComponentUuidWithFilters" parameterType="map" resultType="string" databaseId="oracle">
  429. select
  430. i.kee
  431. from (
  432. select rownum as rn, t.* from (
  433. select
  434. i.kee
  435. from rules r
  436. inner join issues i on i.rule_uuid = r.uuid
  437. where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  438. AND i.status &lt;&gt; 'CLOSED'
  439. <if test="includingRepositories.size() > 0">
  440. AND r.plugin_name IN
  441. <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
  442. #{ruleRepository}
  443. </foreach>
  444. </if>
  445. <if test="excludingRepositories.size() > 0">
  446. AND r.plugin_name NOT IN
  447. <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
  448. #{ruleRepository}
  449. </foreach>
  450. </if>
  451. <if test="languages.size() > 0">
  452. AND r.language IN
  453. <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
  454. #{language}
  455. </foreach>
  456. </if>
  457. order by i.kee ASC
  458. ) t ) i
  459. where
  460. i.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
  461. order by i.rn asc
  462. </select>
  463. <select id="selectIssueKeysByComponentUuidAndChangedSinceDate" parameterType="map" resultType="string">
  464. select
  465. i.kee
  466. from rules r
  467. inner join issues i on i.rule_uuid = r.uuid
  468. where
  469. i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  470. AND i.issue_update_date &gt;= #{changedSince,jdbcType=BIGINT}
  471. AND i.status &lt;&gt; 'CLOSED'
  472. <if test="includingRepositories.size() > 0">
  473. AND r.plugin_name IN
  474. <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
  475. #{ruleRepository}
  476. </foreach>
  477. </if>
  478. <if test="excludingRepositories.size() > 0">
  479. AND r.plugin_name NOT IN
  480. <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
  481. #{ruleRepository}
  482. </foreach>
  483. </if>
  484. <if test="languages.size() > 0">
  485. AND r.language IN
  486. <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
  487. #{language}
  488. </foreach>
  489. </if>
  490. order by i.kee
  491. limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
  492. </select>
  493. <select id="selectIssueKeysByComponentUuidAndChangedSinceDate" parameterType="map" resultType="string" databaseId="mssql">
  494. select
  495. i.kee
  496. from
  497. (select
  498. row_number() over(order by i.kee ASC) as row_number,
  499. i.kee
  500. from rules r
  501. inner join issues i on i.rule_uuid = r.uuid
  502. where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  503. AND i.issue_update_date &gt;= #{changedSince,jdbcType=BIGINT}
  504. AND i.status &lt;&gt; 'CLOSED'
  505. <if test="includingRepositories.size() > 0">
  506. AND r.plugin_name IN
  507. <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
  508. #{ruleRepository}
  509. </foreach>
  510. </if>
  511. <if test="excludingRepositories.size() > 0">
  512. AND r.plugin_name NOT IN
  513. <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
  514. #{ruleRepository}
  515. </foreach>
  516. </if>
  517. <if test="languages.size() > 0">
  518. AND r.language IN
  519. <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
  520. #{language}
  521. </foreach>
  522. </if>
  523. order by row_number asc
  524. offset #{pagination.offset} rows
  525. fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only) i
  526. </select>
  527. <select id="selectIssueKeysByComponentUuidAndChangedSinceDate" parameterType="map" resultType="string" databaseId="oracle">
  528. select
  529. i.kee
  530. from
  531. (select rownum as rn, t.* from (
  532. select
  533. i.kee
  534. from rules r
  535. inner join issues i on i.rule_uuid = r.uuid
  536. where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  537. AND i.issue_update_date &gt;= #{changedSince,jdbcType=BIGINT}
  538. AND i.status &lt;&gt; 'CLOSED'
  539. <if test="includingRepositories.size() > 0">
  540. AND r.plugin_name IN
  541. <foreach item="ruleRepository" index="index" collection="includingRepositories" open="(" separator="," close=")">
  542. #{ruleRepository}
  543. </foreach>
  544. </if>
  545. <if test="excludingRepositories.size() > 0">
  546. AND r.plugin_name NOT IN
  547. <foreach item="ruleRepository" index="index" collection="excludingRepositories" open="(" separator="," close=")">
  548. #{ruleRepository}
  549. </foreach>
  550. </if>
  551. <if test="languages.size() > 0">
  552. AND r.language IN
  553. <foreach item="language" index="index" collection="languages" open="(" separator="," close=")">
  554. #{language}
  555. </foreach>
  556. </if>
  557. order by i.kee ASC
  558. ) t
  559. ) i
  560. where
  561. i.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
  562. order by i.rn asc
  563. </select>
  564. <select id="selectByComponentUuidPaginated" parameterType="map" resultType="Issue">
  565. select
  566. <include refid="issueColumns"/>,
  567. u.login as assigneeLogin
  568. from issues i
  569. inner join rules r on r.uuid=i.rule_uuid
  570. inner join components p on p.uuid=i.component_uuid
  571. inner join components root on root.uuid=i.project_uuid
  572. left join users u on i.assignee = u.uuid
  573. left join new_code_reference_issues n on i.kee = n.issue_key
  574. where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  575. order by i.issue_creation_date ASC
  576. limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
  577. </select>
  578. <select id="selectByComponentUuidPaginated" parameterType="map" resultType="Issue" databaseId="mssql">
  579. select
  580. <include refid="issueColumns"/>,
  581. u.login as assigneeLogin
  582. from
  583. (select
  584. row_number() over(order by i.issue_creation_date ASC) as row_number,
  585. <include refid="issueColumnsInInnerQuery"/>
  586. from issues i
  587. where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  588. order by row_number asc
  589. offset #{pagination.offset} rows
  590. fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only) i
  591. inner join rules r on r.uuid=i.rule_uuid
  592. inner join components p on p.uuid=i.component_uuid
  593. inner join components root on root.uuid=i.project_uuid
  594. left join users u on i.assignee = u.uuid
  595. left join new_code_reference_issues n on i.kee = n.issue_key
  596. </select>
  597. <select id="selectByComponentUuidPaginated" parameterType="map" resultType="Issue" databaseId="oracle">
  598. select
  599. <include refid="issueColumns"/>,
  600. u.login as assigneeLogin
  601. from
  602. (select <include refid="issueColumnsInInnerQuery"/> from (
  603. select rownum as rn, t.* from (
  604. select
  605. <include refid="issueColumnsInInnerQuery"/>
  606. from issues i
  607. where i.project_uuid=#{componentUuid,jdbcType=VARCHAR}
  608. order by i.issue_creation_date ASC
  609. ) t
  610. ) i
  611. where
  612. i.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
  613. order by i.rn asc) i
  614. inner join rules r on r.uuid=i.rule_uuid
  615. inner join components p on p.uuid=i.component_uuid
  616. inner join components root on root.uuid=i.project_uuid
  617. left join users u on i.assignee = u.uuid
  618. left join new_code_reference_issues n on i.kee = n.issue_key
  619. </select>
  620. <sql id="selectByBranchColumns">
  621. i.kee as kee,
  622. i.rule_uuid as ruleUuid,
  623. i.created_at as createdAt,
  624. i.status as status,
  625. i.resolution as resolution,
  626. r.rule_type as ruleType,
  627. r.plugin_name as ruleRepo,
  628. r.plugin_rule_key as ruleKey,
  629. i.message as message,
  630. i.message_formattings as messageFormattings,
  631. i.severity as severity,
  632. i.manual_severity as manualSeverity,
  633. i.issue_type as type,
  634. i.locations as locations,
  635. i.component_uuid as component_uuid,
  636. i.assignee as assigneeUuid,
  637. u.login as assigneeLogin,
  638. i.rule_description_context_key as ruleDescriptionContextKey
  639. </sql>
  640. <select id="selectByBranch" parameterType="map" resultType="Issue">
  641. select
  642. <include refid="selectByBranchColumns"/>
  643. , p.path as filePath
  644. from issues i
  645. inner join rules r on r.uuid = i.rule_uuid
  646. inner join components p on p.uuid=i.component_uuid
  647. left join users u on i.assignee = u.uuid
  648. where
  649. <if test="keys.size() > 0">
  650. i.kee IN
  651. <foreach collection="keys" open="(" close=")" item="key" separator=",">
  652. #{key,jdbcType=VARCHAR}
  653. </foreach>
  654. </if>
  655. <if test="changedSince != null">
  656. AND i.issue_update_date &gt;= #{changedSince,jdbcType=BIGINT}
  657. </if>
  658. </select>
  659. <select id="selectRecentlyClosedIssues" resultType="string">
  660. select i.kee
  661. from rules r
  662. inner join issues i on r.uuid = i.rule_uuid
  663. where
  664. i.project_uuid = #{queryParams.branchUuid}
  665. AND issue_update_date &gt;= #{queryParams.changedSince}
  666. AND i.status = 'CLOSED'
  667. <if test="queryParams.ruleRepositories.size() > 0">
  668. AND r.plugin_name IN
  669. <foreach item="ruleRepository" index="index" collection="queryParams.ruleRepositories" open="(" separator="," close=")">
  670. #{ruleRepository}
  671. </foreach>
  672. </if>
  673. <if test="queryParams.excludingRuleRepositories.size() > 0">
  674. AND r.plugin_name NOT IN
  675. <foreach item="ruleRepository" index="index" collection="queryParams.excludingRuleRepositories" open="(" separator="," close=")">
  676. #{ruleRepository}
  677. </foreach>
  678. </if>
  679. <if test="queryParams.languages.size() > 0">
  680. AND r.language IN
  681. <foreach item="language" index="index" collection="queryParams.languages" open="(" separator="," close=")">
  682. #{language}
  683. </foreach>
  684. </if>
  685. </select>
  686. <select id="selectByQuery" parameterType="map" resultType="Issue">
  687. select
  688. <include refid="issueColumns"/>
  689. from issues i
  690. inner join rules r on r.uuid=i.rule_uuid
  691. inner join components p on p.uuid=i.component_uuid
  692. inner join components root on root.uuid=i.project_uuid
  693. inner join project_branches pb on pb.uuid=i.project_uuid
  694. left join new_code_reference_issues n on i.kee = n.issue_key
  695. <where>
  696. <if test="query.project != null">
  697. root.kee = #{query.project,jdbcType=VARCHAR}
  698. </if>
  699. <if test="query.component != null">
  700. AND p.kee = #{query.component,jdbcType=VARCHAR}
  701. </if>
  702. <if test="query.branch != null">
  703. AND pb.kee = #{query.branch,jdbcType=VARCHAR}
  704. </if>
  705. <if test="query.pullRequest != null">
  706. AND pb.kee = #{query.pullRequest,jdbcType=VARCHAR}
  707. </if>
  708. <if test="query.types.size() > 0">
  709. AND i.issue_type IN
  710. <foreach collection="query.types" open="(" close=")" item="type" separator=",">
  711. #{type,jdbcType=VARCHAR}
  712. </foreach>
  713. </if>
  714. <if test="query.statuses.size() > 0">
  715. AND i.status IN
  716. <foreach collection="query.statuses" open="(" close=")" item="status" separator=",">
  717. #{status,jdbcType=VARCHAR}
  718. </foreach>
  719. </if>
  720. <if test="query.resolved != null">
  721. AND i.resolution is <if test="query.resolved">not</if> null
  722. </if>
  723. <if test="query.resolutions.size() > 0">
  724. AND i.resolution IN
  725. <foreach collection="query.resolutions" open="(" close=")" item="resolution" separator=",">
  726. #{resolution,jdbcType=VARCHAR}
  727. </foreach>
  728. </if>
  729. <if test="query.newCodeOnReference == true">
  730. AND n.uuid IS NOT NULL
  731. </if>
  732. <if test="query.createdAfter != null">
  733. AND i.issue_creation_date &gt;= #{query.createdAfter,jdbcType=BIGINT}
  734. </if>
  735. </where>
  736. order by i.kee asc
  737. offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
  738. </select>
  739. </mapper>