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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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.line as line,
  11. i.locations as locations,
  12. i.gap as gap,
  13. i.effort as effort,
  14. i.status as status,
  15. i.resolution as resolution,
  16. i.checksum as checksum,
  17. i.assignee as assigneeUuid,
  18. i.author_login as authorLogin,
  19. i.tags as tagsString,
  20. i.issue_attributes as issueAttributes,
  21. i.issue_creation_date as issueCreationTime,
  22. i.issue_update_date as issueUpdateTime,
  23. i.issue_close_date as issueCloseTime,
  24. i.created_at as createdAt,
  25. i.updated_at as updatedAt,
  26. r.is_external as "isExternal",
  27. r.plugin_rule_key as ruleKey,
  28. r.plugin_name as ruleRepo,
  29. r.language as language,
  30. p.kee as componentKey,
  31. i.component_uuid as componentUuid,
  32. p.module_uuid as moduleUuid,
  33. p.module_uuid_path as moduleUuidPath,
  34. p.path as filePath,
  35. root.kee as projectKey,
  36. i.project_uuid as projectUuid,
  37. i.issue_type as type
  38. </sql>
  39. <sql id="sortColumn">
  40. <if test="query.sort() != null">,
  41. <choose>
  42. <when test="'SEVERITY'.equals(query.sort())">
  43. i.severity as severity
  44. </when>
  45. <when test="'STATUS'.equals(query.sort())">
  46. i.status as status
  47. </when>
  48. <when test="'ASSIGNEE'.equals(query.sort())">
  49. i.assignee as assigneeUuid
  50. </when>
  51. <when test="'CREATION_DATE'.equals(query.sort())">
  52. i.issue_creation_date as issueCreationTime
  53. </when>
  54. <when test="'UPDATE_DATE'.equals(query.sort())">
  55. i.issue_update_date as issueUpdateTime
  56. </when>
  57. <when test="'CLOSE_DATE'.equals(query.sort())">
  58. i.issue_close_date as issueCloseTime
  59. </when>
  60. </choose>
  61. </if>
  62. </sql>
  63. <sql id="issueForIndexingColumns">
  64. i.kee as "key",
  65. root.uuid as "projectUuid",
  66. i.updated_at as "updatedAt",
  67. i.assignee,
  68. i.gap,
  69. i.issue_attributes as "attributes",
  70. i.line,
  71. i.message,
  72. i.resolution,
  73. i.severity,
  74. i.manual_severity as "manualSeverity",
  75. i.checksum,
  76. i.status,
  77. i.effort,
  78. i.author_login as "authorLogin",
  79. i.issue_close_date as "issueCloseDate",
  80. i.issue_creation_date as "issueCreationDate",
  81. i.issue_update_date as "issueUpdateDate",
  82. r.is_external as "isExternal",
  83. r.plugin_name as "pluginName",
  84. r.plugin_rule_key as "pluginRuleKey",
  85. r.language,
  86. p.uuid as "projectUuid",
  87. p.module_uuid_path as "moduleUuidPath",
  88. p.path,
  89. p.scope,
  90. p.organization_uuid as "organizationUuid",
  91. i.tags,
  92. i.issue_type as "issueType"
  93. </sql>
  94. <insert id="insert" parameterType="Issue" useGeneratedKeys="false">
  95. INSERT INTO issues (kee, rule_uuid, severity, manual_severity,
  96. message, line, locations, gap, effort, status, tags,
  97. resolution, checksum, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date,
  98. issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type)
  99. VALUES (
  100. #{kee,jdbcType=VARCHAR},
  101. #{ruleUuid,jdbcType=VARCHAR},
  102. #{severity,jdbcType=VARCHAR},
  103. #{manualSeverity,jdbcType=BOOLEAN}, #{message,jdbcType=VARCHAR}, #{line,jdbcType=INTEGER},
  104. #{locations,jdbcType=BINARY},
  105. #{gap,jdbcType=DOUBLE}, #{effort,jdbcType=INTEGER}, #{status,jdbcType=VARCHAR},
  106. #{tagsString,jdbcType=VARCHAR}, #{resolution,jdbcType=VARCHAR},
  107. #{checksum,jdbcType=VARCHAR},
  108. #{assigneeUuid,jdbcType=VARCHAR},
  109. #{authorLogin,jdbcType=VARCHAR},
  110. #{issueAttributes,jdbcType=VARCHAR},
  111. #{issueCreationTime,jdbcType=BIGINT},#{issueUpdateTime,jdbcType=BIGINT}, #{issueCloseTime,jdbcType=BIGINT},
  112. #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT},
  113. #{componentUuid,jdbcType=VARCHAR}, #{projectUuid,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER})
  114. </insert>
  115. <!--
  116. IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate()
  117. -->
  118. <update id="update" parameterType="Issue">
  119. update issues set
  120. severity=#{severity,jdbcType=VARCHAR},
  121. manual_severity=#{manualSeverity,jdbcType=BOOLEAN},
  122. message=#{message,jdbcType=VARCHAR},
  123. line=#{line,jdbcType=INTEGER},
  124. locations=#{locations,jdbcType=BINARY},
  125. gap=#{gap,jdbcType=DOUBLE},
  126. effort=#{effort,jdbcType=INTEGER},
  127. status=#{status,jdbcType=VARCHAR},
  128. resolution=#{resolution,jdbcType=VARCHAR},
  129. checksum=#{checksum,jdbcType=VARCHAR},
  130. assignee=#{assigneeUuid,jdbcType=VARCHAR},
  131. author_login=#{authorLogin,jdbcType=VARCHAR},
  132. tags=#{tagsString,jdbcType=VARCHAR},
  133. project_uuid=#{projectUuid,jdbcType=VARCHAR},
  134. issue_attributes=#{issueAttributes,jdbcType=VARCHAR},
  135. issue_creation_date=#{issueCreationTime,jdbcType=BIGINT},
  136. issue_update_date=#{issueUpdateTime,jdbcType=BIGINT},
  137. issue_close_date=#{issueCloseTime,jdbcType=BIGINT},
  138. updated_at=#{updatedAt,jdbcType=BIGINT},
  139. issue_type=#{type,jdbcType=INTEGER}
  140. where kee = #{kee}
  141. </update>
  142. <!--
  143. IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate()
  144. -->
  145. <update id="updateIfBeforeSelectedDate" parameterType="Issue">
  146. update issues set
  147. severity=#{severity,jdbcType=VARCHAR},
  148. manual_severity=#{manualSeverity,jdbcType=BOOLEAN},
  149. message=#{message,jdbcType=VARCHAR},
  150. line=#{line,jdbcType=INTEGER},
  151. locations=#{locations,jdbcType=BINARY},
  152. gap=#{gap,jdbcType=DOUBLE},
  153. effort=#{effort,jdbcType=INTEGER},
  154. status=#{status,jdbcType=VARCHAR},
  155. resolution=#{resolution,jdbcType=VARCHAR},
  156. checksum=#{checksum,jdbcType=VARCHAR},
  157. assignee=#{assigneeUuid,jdbcType=VARCHAR},
  158. author_login=#{authorLogin,jdbcType=VARCHAR},
  159. tags=#{tagsString,jdbcType=VARCHAR},
  160. component_uuid=#{componentUuid,jdbcType=VARCHAR},
  161. project_uuid=#{projectUuid,jdbcType=VARCHAR},
  162. issue_attributes=#{issueAttributes,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. where kee = #{kee} and updated_at &lt;= #{selectedAt}
  169. </update>
  170. <select id="selectByKey" parameterType="String" resultType="Issue">
  171. select
  172. <include refid="issueColumns"/>
  173. from issues i
  174. inner join rules r on r.uuid=i.rule_uuid
  175. inner join components p on p.uuid=i.component_uuid
  176. inner join components root on root.uuid=i.project_uuid
  177. where i.kee=#{kee,jdbcType=VARCHAR}
  178. </select>
  179. <select id="scrollNonClosedByComponentUuid" parameterType="String" resultType="Issue" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
  180. select
  181. <include refid="issueColumns"/>
  182. from issues i
  183. inner join rules r on r.uuid=i.rule_uuid
  184. inner join components p on p.uuid=i.component_uuid
  185. inner join components root on root.uuid=i.project_uuid
  186. where
  187. i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
  188. i.status &lt;&gt; 'CLOSED'
  189. </select>
  190. <select id="selectNonClosedByComponentUuidExcludingExternals" parameterType="String" resultType="Issue">
  191. select
  192. <include refid="issueColumns"/>
  193. from issues i
  194. inner join rules r on r.uuid=i.rule_uuid
  195. inner join components p on p.uuid=i.component_uuid
  196. inner join components root on root.uuid=i.project_uuid
  197. where
  198. (r.is_external is NULL or r.is_external = ${_false}) and
  199. i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
  200. i.status &lt;&gt; 'CLOSED' and
  201. i.issue_type &lt;&gt; 4
  202. </select>
  203. <select id="scrollClosedByComponentUuid" resultType="Issue" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
  204. select
  205. <include refid="issueColumns"/>,
  206. ic.change_data as closedChangeData
  207. from issues i
  208. inner join rules r on
  209. r.uuid = i.rule_uuid
  210. inner join components p on
  211. p.uuid = i.component_uuid
  212. inner join components root on
  213. root.uuid = i.project_uuid
  214. inner join issue_changes ic on
  215. ic.issue_key = i.kee
  216. and ic.change_type = 'diff'
  217. and ic.change_data like '%status=%|CLOSED%'
  218. where
  219. i.component_uuid = #{componentUuid,jdbcType=VARCHAR}
  220. and i.status = 'CLOSED'
  221. and i.issue_close_date is not null
  222. and i.issue_close_date >= #{closeDateAfter,jdbcType=BIGINT}
  223. and i.issue_type &lt;&gt; 4
  224. order by
  225. i.kee, ic.issue_change_creation_date desc
  226. </select>
  227. <select id="selectModuleAndDirComponentUuidsOfOpenIssuesForProjectUuid" parameterType="string" resultType="string">
  228. select
  229. distinct(i.component_uuid)
  230. from issues i
  231. inner join components p on
  232. p.uuid = i.component_uuid
  233. and p.enabled = ${_true}
  234. where
  235. i.project_uuid=#{projectUuid,jdbcType=VARCHAR}
  236. and i.status &lt;&gt; 'CLOSED'
  237. and (p.qualifier = 'DIR' OR p.qualifier = 'BRC')
  238. </select>
  239. <select id="selectComponentUuidsOfOpenIssuesForProjectUuid" parameterType="string" resultType="string">
  240. select distinct(i.component_uuid)
  241. from issues i
  242. where i.project_uuid=#{projectUuid,jdbcType=VARCHAR} and i.status &lt;&gt; 'CLOSED'
  243. </select>
  244. <select id="selectByKeys" parameterType="map" resultType="Issue">
  245. select
  246. <include refid="issueColumns"/>
  247. from issues i
  248. inner join rules r on r.uuid=i.rule_uuid
  249. inner join components p on p.uuid=i.component_uuid
  250. inner join components root on root.uuid=i.project_uuid
  251. where i.kee in
  252. <foreach collection="list" open="(" close=")" item="key" separator=",">
  253. #{key,jdbcType=VARCHAR}
  254. </foreach>
  255. </select>
  256. <select id="selectByKeysIfNotUpdatedAt" 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. where
  264. i.kee in
  265. <foreach collection="keys" open="(" close=")" item="key" separator=",">
  266. #{key,jdbcType=VARCHAR}
  267. </foreach>
  268. and i.updated_at &lt;&gt; #{updatedAt,jdbcType=BIGINT}
  269. </select>
  270. <select id="selectOpenByComponentUuids" parameterType="map" resultType="PrIssue">
  271. select
  272. i.kee as kee,
  273. i.message as message,
  274. i.line as line,
  275. i.status as status,
  276. i.checksum as checksum,
  277. i.issue_update_date as issueUpdateDate,
  278. r.plugin_rule_key as ruleKey,
  279. r.plugin_name as ruleRepo,
  280. b.kee as branchKey,
  281. b.key_type as keyType
  282. from issues i
  283. inner join rules r on r.uuid = i.rule_uuid
  284. inner join project_branches b on i.project_uuid = b.uuid
  285. where i.component_uuid in
  286. <foreach collection="list" open="(" close=")" item="key" separator=",">
  287. #{key,jdbcType=VARCHAR}
  288. </foreach>
  289. and i.status &lt;&gt; 'CLOSED'
  290. </select>
  291. <select id="selectNonClosedByModuleOrProject" parameterType="map" resultType="Issue">
  292. select
  293. <include refid="issueColumns"/>
  294. from issues i
  295. inner join rules r on r.uuid = i.rule_uuid
  296. inner join components p on p.uuid = i.component_uuid
  297. inner join components root on root.uuid = i.project_uuid
  298. where
  299. (r.is_external is NULL or r.is_external = ${_false}) and
  300. i.project_uuid = #{projectUuid, jdbcType=VARCHAR} and
  301. p.module_uuid_path like #{likeModuleUuidPath, jdbcType=VARCHAR} escape '/' and
  302. i.status &lt;&gt; 'CLOSED' and
  303. i.issue_type &lt;&gt; 4
  304. </select>
  305. <select id="selectIssueGroupsByBaseComponent" 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", (i.issue_creation_date &gt; #{leakPeriodBeginningDate,jdbcType=BIGINT}) as inLeak
  307. from issues i
  308. inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid
  309. where i.status !='CLOSED'
  310. and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR}
  311. and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR})
  312. group by i.issue_type, i.severity, i.resolution, i.status, inLeak
  313. </select>
  314. <select id="selectIssueGroupsByBaseComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map" databaseId="oracle">
  315. 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
  316. from (
  317. select i.issue_type, i.severity, i.resolution, i.status, i.effort, case when i.issue_creation_date &gt; #{leakPeriodBeginningDate,jdbcType=BIGINT} then 1 else 0 end as inLeak
  318. from issues i
  319. inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid
  320. where i.status !='CLOSED'
  321. and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR}
  322. and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR})
  323. ) i2
  324. group by i2.issue_type, i2.severity, i2.resolution, i2.status, i2.inLeak
  325. </select>
  326. <select id="selectIssueGroupsByBaseComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map" databaseId="mssql">
  327. 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
  328. from (
  329. select i.issue_type, i.severity, i.resolution, i.status, i.effort, case when i.issue_creation_date &gt; #{leakPeriodBeginningDate,jdbcType=BIGINT} then 1 else 0 end as inLeak
  330. from issues i
  331. inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid
  332. where i.status !='CLOSED'
  333. and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR}
  334. and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR})
  335. ) i2
  336. group by i2.issue_type, i2.severity, i2.resolution, i2.status, i2.inLeak
  337. </select>
  338. </mapper>