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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. <insert id="insert" parameterType="Issue" useGeneratedKeys="false">
  64. INSERT INTO issues (kee, rule_uuid, severity, manual_severity,
  65. message, line, locations, gap, effort, status, tags,
  66. resolution, checksum, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date,
  67. issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type)
  68. VALUES (
  69. #{kee,jdbcType=VARCHAR},
  70. #{ruleUuid,jdbcType=VARCHAR},
  71. #{severity,jdbcType=VARCHAR},
  72. #{manualSeverity,jdbcType=BOOLEAN}, #{message,jdbcType=VARCHAR}, #{line,jdbcType=INTEGER},
  73. #{locations,jdbcType=BINARY},
  74. #{gap,jdbcType=DOUBLE}, #{effort,jdbcType=INTEGER}, #{status,jdbcType=VARCHAR},
  75. #{tagsString,jdbcType=VARCHAR}, #{resolution,jdbcType=VARCHAR},
  76. #{checksum,jdbcType=VARCHAR},
  77. #{assigneeUuid,jdbcType=VARCHAR},
  78. #{authorLogin,jdbcType=VARCHAR},
  79. #{issueAttributes,jdbcType=VARCHAR},
  80. #{issueCreationTime,jdbcType=BIGINT},#{issueUpdateTime,jdbcType=BIGINT}, #{issueCloseTime,jdbcType=BIGINT},
  81. #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT},
  82. #{componentUuid,jdbcType=VARCHAR}, #{projectUuid,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER})
  83. </insert>
  84. <!--
  85. IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate()
  86. -->
  87. <update id="update" parameterType="Issue">
  88. update issues set
  89. severity=#{severity,jdbcType=VARCHAR},
  90. manual_severity=#{manualSeverity,jdbcType=BOOLEAN},
  91. message=#{message,jdbcType=VARCHAR},
  92. line=#{line,jdbcType=INTEGER},
  93. locations=#{locations,jdbcType=BINARY},
  94. gap=#{gap,jdbcType=DOUBLE},
  95. effort=#{effort,jdbcType=INTEGER},
  96. status=#{status,jdbcType=VARCHAR},
  97. resolution=#{resolution,jdbcType=VARCHAR},
  98. checksum=#{checksum,jdbcType=VARCHAR},
  99. assignee=#{assigneeUuid,jdbcType=VARCHAR},
  100. author_login=#{authorLogin,jdbcType=VARCHAR},
  101. tags=#{tagsString,jdbcType=VARCHAR},
  102. project_uuid=#{projectUuid,jdbcType=VARCHAR},
  103. issue_attributes=#{issueAttributes,jdbcType=VARCHAR},
  104. issue_creation_date=#{issueCreationTime,jdbcType=BIGINT},
  105. issue_update_date=#{issueUpdateTime,jdbcType=BIGINT},
  106. issue_close_date=#{issueCloseTime,jdbcType=BIGINT},
  107. updated_at=#{updatedAt,jdbcType=BIGINT},
  108. issue_type=#{type,jdbcType=INTEGER}
  109. where kee = #{kee}
  110. </update>
  111. <!--
  112. IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate()
  113. -->
  114. <update id="updateIfBeforeSelectedDate" parameterType="Issue">
  115. update issues set
  116. severity=#{severity,jdbcType=VARCHAR},
  117. manual_severity=#{manualSeverity,jdbcType=BOOLEAN},
  118. message=#{message,jdbcType=VARCHAR},
  119. line=#{line,jdbcType=INTEGER},
  120. locations=#{locations,jdbcType=BINARY},
  121. gap=#{gap,jdbcType=DOUBLE},
  122. effort=#{effort,jdbcType=INTEGER},
  123. status=#{status,jdbcType=VARCHAR},
  124. resolution=#{resolution,jdbcType=VARCHAR},
  125. checksum=#{checksum,jdbcType=VARCHAR},
  126. assignee=#{assigneeUuid,jdbcType=VARCHAR},
  127. author_login=#{authorLogin,jdbcType=VARCHAR},
  128. tags=#{tagsString,jdbcType=VARCHAR},
  129. component_uuid=#{componentUuid,jdbcType=VARCHAR},
  130. project_uuid=#{projectUuid,jdbcType=VARCHAR},
  131. issue_attributes=#{issueAttributes,jdbcType=VARCHAR},
  132. issue_creation_date=#{issueCreationTime,jdbcType=BIGINT},
  133. issue_update_date=#{issueUpdateTime,jdbcType=BIGINT},
  134. issue_close_date=#{issueCloseTime,jdbcType=BIGINT},
  135. updated_at=#{updatedAt,jdbcType=BIGINT},
  136. issue_type=#{type,jdbcType=INTEGER}
  137. where kee = #{kee} and updated_at &lt;= #{selectedAt}
  138. </update>
  139. <select id="selectByKey" parameterType="String" resultType="Issue">
  140. select
  141. <include refid="issueColumns"/>
  142. from issues i
  143. inner join rules r on r.uuid=i.rule_uuid
  144. inner join components p on p.uuid=i.component_uuid
  145. inner join components root on root.uuid=i.project_uuid
  146. where i.kee=#{kee,jdbcType=VARCHAR}
  147. </select>
  148. <select id="scrollNonClosedByComponentUuid" parameterType="String" resultType="Issue" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
  149. select
  150. <include refid="issueColumns"/>
  151. from issues i
  152. inner join rules r on r.uuid=i.rule_uuid
  153. inner join components p on p.uuid=i.component_uuid
  154. inner join components root on root.uuid=i.project_uuid
  155. where
  156. i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
  157. i.status &lt;&gt; 'CLOSED'
  158. </select>
  159. <select id="selectNonClosedByComponentUuidExcludingExternals" parameterType="String" resultType="Issue">
  160. select
  161. <include refid="issueColumns"/>
  162. from issues i
  163. inner join rules r on r.uuid=i.rule_uuid
  164. inner join components p on p.uuid=i.component_uuid
  165. inner join components root on root.uuid=i.project_uuid
  166. where
  167. (r.is_external is NULL or r.is_external = ${_false}) and
  168. i.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
  169. i.status &lt;&gt; 'CLOSED' and
  170. i.issue_type &lt;&gt; 4
  171. </select>
  172. <select id="scrollClosedByComponentUuid" resultType="Issue" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
  173. select
  174. <include refid="issueColumns"/>,
  175. ic.change_data as closedChangeData
  176. from issues i
  177. inner join rules r on
  178. r.uuid = i.rule_uuid
  179. inner join components p on
  180. p.uuid = i.component_uuid
  181. inner join components root on
  182. root.uuid = i.project_uuid
  183. inner join issue_changes ic on
  184. ic.issue_key = i.kee
  185. and ic.change_type = 'diff'
  186. and ic.change_data like '%status=%|CLOSED%'
  187. where
  188. i.component_uuid = #{componentUuid,jdbcType=VARCHAR}
  189. and i.status = 'CLOSED'
  190. and i.issue_close_date is not null
  191. and i.issue_close_date >= #{closeDateAfter,jdbcType=BIGINT}
  192. and i.issue_type &lt;&gt; 4
  193. order by
  194. i.kee, ic.issue_change_creation_date desc
  195. </select>
  196. <select id="selectModuleAndDirComponentUuidsOfOpenIssuesForProjectUuid" parameterType="string" resultType="string">
  197. select
  198. distinct(i.component_uuid)
  199. from issues i
  200. inner join components p on
  201. p.uuid = i.component_uuid
  202. and p.enabled = ${_true}
  203. where
  204. i.project_uuid=#{projectUuid,jdbcType=VARCHAR}
  205. and i.status &lt;&gt; 'CLOSED'
  206. and (p.qualifier = 'DIR' OR p.qualifier = 'BRC')
  207. </select>
  208. <select id="selectComponentUuidsOfOpenIssuesForProjectUuid" parameterType="string" resultType="string">
  209. select distinct(i.component_uuid)
  210. from issues i
  211. where i.project_uuid=#{projectUuid,jdbcType=VARCHAR} and i.status &lt;&gt; 'CLOSED'
  212. </select>
  213. <select id="selectByKeys" parameterType="map" resultType="Issue">
  214. select
  215. <include refid="issueColumns"/>
  216. from issues i
  217. inner join rules r on r.uuid=i.rule_uuid
  218. inner join components p on p.uuid=i.component_uuid
  219. inner join components root on root.uuid=i.project_uuid
  220. where i.kee in
  221. <foreach collection="list" open="(" close=")" item="key" separator=",">
  222. #{key,jdbcType=VARCHAR}
  223. </foreach>
  224. </select>
  225. <select id="selectByKeysIfNotUpdatedAt" parameterType="map" resultType="Issue">
  226. select
  227. <include refid="issueColumns"/>
  228. from issues i
  229. inner join rules r on r.uuid=i.rule_uuid
  230. inner join components p on p.uuid=i.component_uuid
  231. inner join components root on root.uuid=i.project_uuid
  232. where
  233. i.kee in
  234. <foreach collection="keys" open="(" close=")" item="key" separator=",">
  235. #{key,jdbcType=VARCHAR}
  236. </foreach>
  237. and i.updated_at &lt;&gt; #{updatedAt,jdbcType=BIGINT}
  238. </select>
  239. <select id="selectOpenByComponentUuids" parameterType="map" resultType="PrIssue">
  240. select
  241. i.kee as kee,
  242. i.message as message,
  243. i.line as line,
  244. i.status as status,
  245. i.checksum as checksum,
  246. i.issue_update_date as issueUpdateDate,
  247. r.plugin_rule_key as ruleKey,
  248. r.plugin_name as ruleRepo,
  249. b.kee as branchKey,
  250. b.branch_type as branchType
  251. from issues i
  252. inner join rules r on r.uuid = i.rule_uuid
  253. inner join project_branches b on i.project_uuid = b.uuid
  254. where i.component_uuid in
  255. <foreach collection="list" open="(" close=")" item="key" separator=",">
  256. #{key,jdbcType=VARCHAR}
  257. </foreach>
  258. and i.status &lt;&gt; 'CLOSED'
  259. </select>
  260. <select id="selectNonClosedByModuleOrProject" parameterType="map" resultType="Issue">
  261. select
  262. <include refid="issueColumns"/>
  263. from issues i
  264. inner join rules r on r.uuid = i.rule_uuid
  265. inner join components p on p.uuid = i.component_uuid
  266. inner join components root on root.uuid = i.project_uuid
  267. where
  268. (r.is_external is NULL or r.is_external = ${_false}) and
  269. i.project_uuid = #{projectUuid, jdbcType=VARCHAR} and
  270. p.module_uuid_path like #{likeModuleUuidPath, jdbcType=VARCHAR} escape '/' and
  271. i.status &lt;&gt; 'CLOSED' and
  272. i.issue_type &lt;&gt; 4
  273. </select>
  274. <select id="selectIssueGroupsByBaseComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map">
  275. 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
  276. from issues i
  277. inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid
  278. where i.status !='CLOSED'
  279. and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR}
  280. and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR})
  281. group by i.issue_type, i.severity, i.resolution, i.status, inLeak
  282. </select>
  283. <select id="selectIssueGroupsByBaseComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map" databaseId="oracle">
  284. 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
  285. from (
  286. 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
  287. from issues i
  288. inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid
  289. where i.status !='CLOSED'
  290. and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR}
  291. and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR})
  292. ) i2
  293. group by i2.issue_type, i2.severity, i2.resolution, i2.status, i2.inLeak
  294. </select>
  295. <select id="selectIssueGroupsByBaseComponent" resultType="org.sonar.db.issue.IssueGroupDto" parameterType="map" databaseId="mssql">
  296. 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
  297. from (
  298. 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
  299. from issues i
  300. inner join components p on p.uuid = i.component_uuid and p.project_uuid = i.project_uuid
  301. where i.status !='CLOSED'
  302. and i.project_uuid = #{baseComponent.projectUuid,jdbcType=VARCHAR}
  303. and (p.uuid_path like #{baseComponent.uuidPathLikeIncludingSelf,jdbcType=VARCHAR} escape '/' or p.uuid = #{baseComponent.uuid,jdbcType=VARCHAR})
  304. ) i2
  305. group by i2.issue_type, i2.severity, i2.resolution, i2.status, i2.inLeak
  306. </select>
  307. </mapper>