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.

ComponentMapper.xml 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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.component.ComponentMapper">
  4. <sql id="componentColumns">
  5. p.uuid as uuid,
  6. p.uuid_path as uuidPath,
  7. p.project_uuid as projectUuid,
  8. p.module_uuid as moduleUuid,
  9. p.module_uuid_path as moduleUuidPath,
  10. p.main_branch_project_uuid as mainBranchProjectUuid,
  11. p.kee as kee,
  12. p.name as name,
  13. p.long_name as longName,
  14. p.description as description,
  15. p.qualifier as qualifier,
  16. p.scope as scope,
  17. p.language as language,
  18. p.root_uuid as rootUuid,
  19. p.path as path,
  20. p.enabled as enabled,
  21. p.copy_component_uuid as copyComponentUuid,
  22. p.private as isPrivate,
  23. p.created_at as createdAt
  24. </sql>
  25. <select id="selectByKey" parameterType="String" resultType="Component">
  26. SELECT
  27. <include refid="componentColumns"/>
  28. FROM components p
  29. where
  30. p.kee=#{key,jdbcType=VARCHAR}
  31. </select>
  32. <select id="selectBranchByKeyAndBranchKey" parameterType="String" resultType="Component">
  33. select
  34. <include refid="componentColumns"/>
  35. from components p
  36. inner join project_branches pb on pb.uuid = p.project_uuid
  37. where
  38. (p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR})
  39. and pb.kee=#{branch,jdbcType=VARCHAR}
  40. and (pb.branch_type='BRANCH')
  41. </select>
  42. <select id="selectPrByKeyAndBranchKey" parameterType="String" resultType="Component">
  43. select
  44. <include refid="componentColumns"/>
  45. from components p
  46. inner join project_branches pb on pb.uuid = p.project_uuid
  47. where
  48. (p.kee=#{dbKey,jdbcType=VARCHAR} OR p.kee=#{key,jdbcType=VARCHAR})
  49. and pb.kee=#{branch,jdbcType=VARCHAR}
  50. and pb.branch_type='PULL_REQUEST'
  51. </select>
  52. <select id="selectByUuid" parameterType="String" resultType="Component">
  53. SELECT
  54. <include refid="componentColumns"/>
  55. FROM components p
  56. where
  57. p.uuid=#{uuid,jdbcType=VARCHAR}
  58. </select>
  59. <select id="selectByProjectUuid" parameterType="string" resultType="Component">
  60. select
  61. <include refid="componentColumns"/>
  62. from components root
  63. inner join components p on p.project_uuid=root.uuid
  64. where
  65. root.uuid=#{projectUuid,jdbcType=VARCHAR}
  66. </select>
  67. <select id="selectByKeys" parameterType="String" resultType="Component">
  68. select
  69. <include refid="componentColumns"/>
  70. from components p
  71. where
  72. p.enabled=${_true}
  73. and p.main_branch_project_uuid is null
  74. and p.kee in
  75. <foreach collection="keys" open="(" close=")" item="key" separator=",">
  76. #{key,jdbcType=VARCHAR}
  77. </foreach>
  78. </select>
  79. <select id="selectByDbKeys" parameterType="String" resultType="Component">
  80. select
  81. <include refid="componentColumns"/>
  82. from components p
  83. where
  84. p.enabled=${_true}
  85. and p.kee in
  86. <foreach collection="dbKeys" open="(" close=")" item="key" separator=",">
  87. #{key,jdbcType=VARCHAR}
  88. </foreach>
  89. </select>
  90. <select id="selectByKeysAndBranch" parameterType="String" resultType="Component">
  91. SELECT
  92. <include refid="componentColumns"/>
  93. FROM components p
  94. INNER JOIN project_branches pb on pb.uuid = p.project_uuid
  95. <where>
  96. p.enabled=${_true}
  97. AND p.kee IN
  98. <foreach collection="keys" open="(" close=")" item="key" separator=",">
  99. #{key,jdbcType=VARCHAR}
  100. </foreach>
  101. AND pb.kee=#{branch,jdbcType=VARCHAR}
  102. </where>
  103. </select>
  104. <select id="selectByUuids" parameterType="String" resultType="Component">
  105. select
  106. <include refid="componentColumns"/>
  107. from components p
  108. where
  109. p.uuid in
  110. <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
  111. #{uuid,jdbcType=VARCHAR}
  112. </foreach>
  113. </select>
  114. <select id="selectExistingUuids" parameterType="String" resultType="String">
  115. select p.uuid
  116. from components p
  117. where
  118. p.uuid in
  119. <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
  120. #{uuid,jdbcType=VARCHAR}
  121. </foreach>
  122. </select>
  123. <select id="selectSubProjectsByComponentUuids" parameterType="String" resultType="Component">
  124. SELECT
  125. <include refid="componentColumns"/>
  126. FROM components p
  127. INNER JOIN components child ON
  128. child.root_uuid=p.uuid
  129. and child.enabled=${_true}
  130. where
  131. p.enabled=${_true}
  132. and p.scope='PRJ'
  133. and child.uuid in
  134. <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
  135. #{uuid,jdbcType=VARCHAR}
  136. </foreach>
  137. </select>
  138. <select id="selectDescendantModules" parameterType="map" resultType="Component">
  139. SELECT
  140. <include refid="componentColumns"/>
  141. FROM components p
  142. <include refid="modulesTreeQuery"/>
  143. </select>
  144. <sql id="modulesTreeQuery">
  145. INNER JOIN components module ON
  146. module.project_uuid = p.project_uuid
  147. and module.uuid = #{moduleUuid}
  148. and module.scope='PRJ' AND module.enabled = ${_true}
  149. where
  150. p.scope = #{scope,jdbcType=VARCHAR}
  151. <if test="excludeDisabled">
  152. and p.enabled = ${_true}
  153. </if>
  154. and
  155. <choose>
  156. <when test="_databaseId == 'mssql'">
  157. p.module_uuid_path LIKE module.module_uuid_path + '%'
  158. </when>
  159. <otherwise>
  160. p.module_uuid_path LIKE module.module_uuid_path || '%'
  161. </otherwise>
  162. </choose>
  163. </sql>
  164. <select id="selectEnabledFilesFromProject" parameterType="map" resultType="FilePathWithHash">
  165. SELECT
  166. p.uuid,
  167. p.path,
  168. p.module_uuid as moduleUuid,
  169. fs.src_hash as srcHash,
  170. fs.revision
  171. FROM components root
  172. INNER JOIN components p on
  173. p.project_uuid=root.uuid
  174. and p.enabled=${_true}
  175. and p.scope='FIL'
  176. INNER JOIN file_sources fs ON
  177. fs.file_uuid=p.uuid
  178. where
  179. root.uuid=#{projectUuid,jdbcType=VARCHAR}
  180. </select>
  181. <select id="selectDescendantFiles" parameterType="map" resultType="FilePathWithHash">
  182. SELECT
  183. p.uuid,
  184. p.path,
  185. p.module_uuid as moduleUuid,
  186. fs.src_hash as srcHash,
  187. fs.revision
  188. FROM components p
  189. INNER JOIN file_sources fs ON
  190. fs.file_uuid=p.uuid
  191. <include refid="modulesTreeQuery"/>
  192. </select>
  193. <select id="selectProjects" resultType="Component">
  194. select
  195. <include refid="componentColumns"/>
  196. from components p
  197. where
  198. p.enabled=${_true}
  199. AND p.scope='PRJ'
  200. AND p.qualifier='TRK'
  201. AND p.main_branch_project_uuid IS NULL
  202. </select>
  203. <select id="selectComponentsByQualifiers" resultType="Component">
  204. SELECT
  205. <include refid="componentColumns"/>
  206. FROM components p
  207. where
  208. <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator="OR ">
  209. p.qualifier=#{qualifier,jdbcType=VARCHAR}
  210. </foreach>
  211. </select>
  212. <select id="countEnabledModulesByProjectUuid" resultType="int">
  213. select
  214. count(1)
  215. from components p
  216. where
  217. p.enabled=${_true}
  218. and p.project_uuid = #{projectUuid,jdbcType=VARCHAR}
  219. and p.qualifier = 'BRC'
  220. </select>
  221. <select id="selectByQuery" resultType="Component">
  222. select
  223. <include refid="componentColumns"/>
  224. <include refid="sqlSelectByQuery"/>
  225. ORDER BY LOWER(p.name), p.name, p.created_at
  226. </select>
  227. <select id="countByQuery" resultType="int">
  228. select count(p.uuid)
  229. <include refid="sqlSelectByQuery"/>
  230. </select>
  231. <sql id="sqlSelectByQuery">
  232. from components p
  233. <if test="query.analyzedBefore!=null">
  234. inner join snapshots sa on sa.component_uuid=p.uuid
  235. and sa.status='P' and sa.islast=${_true} and sa.created_at &lt; #{query.analyzedBefore,jdbcType=BIGINT}
  236. </if>
  237. where
  238. p.enabled=${_true}
  239. AND p.main_branch_project_uuid is null
  240. AND p.copy_component_uuid is null
  241. <if test="query.qualifiers!=null">
  242. and p.qualifier in
  243. <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=",">
  244. #{qualifier,jdbcType=VARCHAR}
  245. </foreach>
  246. </if>
  247. <if test="query.componentKeys!=null">
  248. and p.kee in
  249. <foreach collection="query.componentKeys" item="componentKey" open="(" close=")" separator=",">
  250. #{componentKey,jdbcType=BIGINT}
  251. </foreach>
  252. </if>
  253. <if test="query.componentUuids!=null">
  254. and p.uuid in
  255. <foreach collection="query.componentUuids" item="componentUuid" open="(" close=")" separator=",">
  256. #{componentUuid,jdbcType=BIGINT}
  257. </foreach>
  258. </if>
  259. <if test="query.nameOrKeyQuery!=null">
  260. and (
  261. upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/'
  262. or
  263. <choose>
  264. <when test="query.isPartialMatchOnKey()">
  265. upper(p.kee) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/'
  266. </when>
  267. <otherwise>
  268. p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR}
  269. </otherwise>
  270. </choose>
  271. )
  272. </if>
  273. <if test="query.private!=null">
  274. <if test="query.private.equals(true)">
  275. and p.private=${_true}
  276. </if>
  277. <if test="query.private.equals(false)">
  278. and p.private=${_false}
  279. </if>
  280. </if>
  281. <if test="query.isOnProvisionedOnly()">
  282. and not exists(select 1 from snapshots sp where sp.component_uuid=p.uuid)
  283. and not exists(
  284. select 1 from snapshots sp
  285. inner join project_branches pb on sp.component_uuid = pb.uuid
  286. where pb.project_uuid = p.uuid
  287. )
  288. </if>
  289. <if test="query.anyBranchAnalyzedAfter != null">
  290. and (
  291. exists(
  292. -- branches of projects
  293. select 1 from snapshots s
  294. inner join project_branches pb on s.component_uuid = pb.uuid
  295. where pb.project_uuid = p.uuid
  296. and s.status='P'
  297. and s.islast = ${_true}
  298. and s.created_at &gt;= #{query.anyBranchAnalyzedAfter,jdbcType=BIGINT}
  299. )
  300. or exists (
  301. -- applications, portfolios
  302. select 1 from snapshots s
  303. where s.component_uuid = p.uuid
  304. and s.status='P'
  305. and s.islast = ${_true}
  306. and s.created_at &gt;= #{query.anyBranchAnalyzedAfter,jdbcType=BIGINT}
  307. )
  308. )
  309. </if>
  310. <if test="query.anyBranchAnalyzedBefore != null">
  311. and (
  312. exists(
  313. -- branches of projects
  314. select 1 from snapshots s
  315. inner join project_branches pb on s.component_uuid = pb.uuid
  316. where pb.project_uuid = p.uuid
  317. and s.status='P'
  318. and s.islast = ${_true}
  319. and s.created_at &lt; #{query.anyBranchAnalyzedBefore,jdbcType=BIGINT}
  320. )
  321. or exists (
  322. -- applications, portfolios
  323. select 1 from snapshots s
  324. where s.component_uuid = p.uuid
  325. and s.status='P'
  326. and s.islast = ${_true}
  327. and s.created_at &lt; #{query.anyBranchAnalyzedBefore,jdbcType=BIGINT}
  328. )
  329. )
  330. </if>
  331. <if test="query.createdAfter != null">
  332. and p.created_at &gt;= #{query.createdAfter,jdbcType=TIMESTAMP}
  333. </if>
  334. </sql>
  335. <select id="selectDescendants" resultType="Component">
  336. select
  337. <include refid="componentColumns"/>
  338. from components p
  339. <include refid="selectDescendantsJoins"/>
  340. <where>
  341. <include refid="selectDescendantsFilters"/>
  342. </where>
  343. </select>
  344. <sql id="selectDescendantsJoins">
  345. inner join components base on base.project_uuid = p.project_uuid and base.uuid = #{baseUuid}
  346. <choose>
  347. <when test="query.getStrategy().name() == 'CHILDREN'">
  348. and p.uuid_path = #{baseUuidPath,jdbcType=VARCHAR}
  349. </when>
  350. <otherwise>
  351. and p.uuid_path like #{baseUuidPath,jdbcType=VARCHAR} ESCAPE '/'
  352. </otherwise>
  353. </choose>
  354. </sql>
  355. <sql id="selectDescendantsFilters">
  356. and p.enabled = ${_true}
  357. <if test="query.qualifiers != null">
  358. and p.qualifier in
  359. <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=",">
  360. #{qualifier,jdbcType=VARCHAR}
  361. </foreach>
  362. </if>
  363. <if test="query.scopes != null">
  364. and p.scope in
  365. <foreach collection="query.scopes" item="scope" open="(" close=")" separator=",">
  366. #{scope,jdbcType=VARCHAR}
  367. </foreach>
  368. </if>
  369. <if test="query.nameOrKeyQuery != null">
  370. and (
  371. p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR}
  372. or
  373. upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/'
  374. )
  375. </if>
  376. </sql>
  377. <select id="selectUuidsForQualifiers" resultType="UuidWithProjectUuid">
  378. SELECT p.uuid as "uuid", p.project_uuid as "projectUuid" FROM components p
  379. where
  380. <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator="OR ">
  381. p.qualifier=#{qualifier,jdbcType=VARCHAR}
  382. </foreach>
  383. </select>
  384. <select id="selectViewKeysWithEnabledCopyOfProject" resultType="String">
  385. select
  386. distinct p.kee
  387. from components p
  388. inner join components leaf on
  389. leaf.qualifier = 'TRK'
  390. and leaf.scope = 'FIL'
  391. and leaf.enabled = ${_true}
  392. and leaf.copy_component_uuid in
  393. <foreach collection="projectUuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach>
  394. where
  395. p.enabled = ${_true}
  396. and p.uuid = leaf.project_uuid
  397. and p.scope = 'PRJ'
  398. and p.qualifier in ('VW', 'APP')
  399. </select>
  400. <select id="selectProjectsFromView" resultType="String">
  401. select p.copy_component_uuid
  402. from components p
  403. where
  404. p.enabled = ${_true}
  405. and p.project_uuid = #{projectViewUuid,jdbcType=VARCHAR}
  406. and p.module_uuid_path like #{viewUuidLikeQuery,jdbcType=VARCHAR}
  407. and p.qualifier = 'TRK'
  408. and p.copy_component_uuid is not null
  409. </select>
  410. <select id="selectComponentsFromProjectKeyAndScope" parameterType="map" resultType="Component">
  411. SELECT
  412. <include refid="componentColumns"/>
  413. FROM components p
  414. INNER JOIN components root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR}
  415. <where>
  416. <if test="excludeDisabled">
  417. p.enabled = ${_true}
  418. </if>
  419. <if test="scope != null">
  420. AND p.scope=#{scope,jdbcType=VARCHAR}
  421. </if>
  422. </where>
  423. </select>
  424. <select id="selectEnabledComponentsWithModuleUuidFromProjectKey" resultType="ComponentWithModuleUuid">
  425. SELECT
  426. p.uuid as uuid, p.module_uuid as moduleUuid, p.path as path, p.scope as scope
  427. FROM
  428. components p
  429. INNER JOIN
  430. components root ON root.uuid=p.project_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR}
  431. </select>
  432. <select id="selectUuidsByKeyFromProjectKey" parameterType="string" resultType="KeyWithUuid">
  433. SELECT
  434. p.kee, p.uuid
  435. FROM
  436. components p
  437. INNER JOIN
  438. components root ON root.uuid=p.project_uuid AND root.kee=#{projectKey,jdbcType=VARCHAR}
  439. </select>
  440. <select id="scrollForIndexing" parameterType="map" resultType="Component" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
  441. select
  442. <include refid="componentColumns"/>
  443. from components p
  444. where
  445. p.enabled=${_true}
  446. and p.copy_component_uuid is null
  447. and p.main_branch_project_uuid is null
  448. and p.scope = 'PRJ'
  449. and p.qualifier in ('TRK','VW','SVW','APP')
  450. <if test="projectUuid != null">
  451. and p.project_uuid = #{projectUuid,jdbcType=VARCHAR}
  452. </if>
  453. </select>
  454. <select id="scrollAllFilesForFileMove" parameterType="map" resultType="org.sonar.db.component.FileMoveRowDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
  455. select
  456. p.uuid as uuid,
  457. p.kee as kee,
  458. p.path as path,
  459. fs.line_count as lineCount
  460. from components p
  461. inner join file_sources fs on
  462. fs.file_uuid = p.uuid
  463. where
  464. p.project_uuid = #{projectUuid,jdbcType=VARCHAR}
  465. and p.enabled = ${_true}
  466. and p.scope = 'FIL'
  467. and p.qualifier in ('FIL', 'UTS')
  468. and p.path is not null
  469. </select>
  470. <insert id="insert" parameterType="Component">
  471. INSERT INTO components (
  472. kee,
  473. uuid,
  474. uuid_path,
  475. project_uuid,
  476. module_uuid,
  477. module_uuid_path,
  478. main_branch_project_uuid,
  479. name,
  480. long_name,
  481. qualifier,
  482. scope,
  483. language,
  484. description,
  485. private,
  486. root_uuid,
  487. path,
  488. copy_component_uuid,
  489. enabled,
  490. created_at,
  491. b_changed,
  492. deprecated_kee,
  493. b_copy_component_uuid,
  494. b_description,
  495. b_enabled,
  496. b_language,
  497. b_long_name,
  498. b_module_uuid,
  499. b_module_uuid_path,
  500. b_name,
  501. b_path,
  502. b_qualifier
  503. )
  504. VALUES (
  505. #{kee,jdbcType=VARCHAR},
  506. #{uuid,jdbcType=VARCHAR},
  507. #{uuidPath,jdbcType=VARCHAR},
  508. #{projectUuid,jdbcType=VARCHAR},
  509. #{moduleUuid,jdbcType=VARCHAR},
  510. #{moduleUuidPath,jdbcType=VARCHAR},
  511. #{mainBranchProjectUuid, jdbcType=VARCHAR},
  512. #{name,jdbcType=VARCHAR},
  513. #{longName,jdbcType=VARCHAR},
  514. #{qualifier,jdbcType=VARCHAR},
  515. #{scope,jdbcType=VARCHAR},
  516. #{language,jdbcType=VARCHAR},
  517. #{description,jdbcType=VARCHAR},
  518. #{isPrivate,jdbcType=BOOLEAN},
  519. #{rootUuid,jdbcType=VARCHAR},
  520. #{path,jdbcType=VARCHAR},
  521. #{copyComponentUuid,jdbcType=VARCHAR},
  522. #{enabled,jdbcType=BOOLEAN},
  523. #{createdAt,jdbcType=TIMESTAMP},
  524. ${_false},
  525. null,
  526. null,
  527. null,
  528. ${_false},
  529. null,
  530. null,
  531. null,
  532. null,
  533. null,
  534. null,
  535. null
  536. )
  537. </insert>
  538. <update id="update" parameterType="org.sonar.db.component.ComponentUpdateDto" useGeneratedKeys="false">
  539. update components set
  540. b_changed = #{bChanged,jdbcType=BOOLEAN},
  541. <!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules -->
  542. deprecated_kee = #{bKey,jdbcType=VARCHAR},
  543. b_copy_component_uuid = #{bCopyComponentUuid,jdbcType=VARCHAR},
  544. b_description = #{bDescription,jdbcType=VARCHAR},
  545. b_enabled = #{bEnabled,jdbcType=BOOLEAN},
  546. b_uuid_path = #{bUuidPath,jdbcType=VARCHAR},
  547. b_language = #{bLanguage,jdbcType=VARCHAR},
  548. b_long_name = #{bLongName,jdbcType=VARCHAR},
  549. b_module_uuid = #{bModuleUuid,jdbcType=VARCHAR},
  550. b_module_uuid_path = #{bModuleUuidPath,jdbcType=VARCHAR},
  551. b_name = #{bName,jdbcType=VARCHAR},
  552. b_path = #{bPath,jdbcType=VARCHAR},
  553. b_qualifier = #{bQualifier,jdbcType=VARCHAR}
  554. where
  555. uuid = #{uuid,jdbcType=VARCHAR}
  556. </update>
  557. <update id="updateBEnabledToFalse" parameterType="org.sonar.db.component.ComponentUpdateDto" useGeneratedKeys="false">
  558. update components set
  559. b_changed = ${_true},
  560. <!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules -->
  561. deprecated_kee = kee,
  562. b_copy_component_uuid = copy_component_uuid,
  563. b_description = description,
  564. b_enabled = ${_false},
  565. b_uuid_path = uuid_path,
  566. b_language = language,
  567. b_long_name = long_name,
  568. b_module_uuid = module_uuid,
  569. b_module_uuid_path = module_uuid_path,
  570. b_name = name,
  571. b_path = path,
  572. b_qualifier = qualifier
  573. where
  574. uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid,jdbcType=VARCHAR}</foreach>
  575. </update>
  576. <update id="applyBChangesForRootComponentUuid" parameterType="string" useGeneratedKeys="false">
  577. update components set
  578. <!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules -->
  579. kee = deprecated_kee,
  580. copy_component_uuid = b_copy_component_uuid,
  581. description = b_description,
  582. enabled = b_enabled,
  583. uuid_path = b_uuid_path,
  584. language = b_language,
  585. long_name = b_long_name,
  586. module_uuid = b_module_uuid,
  587. module_uuid_path = b_module_uuid_path,
  588. name = b_name,
  589. path = b_path,
  590. qualifier = b_qualifier,
  591. <!-- Try to fix the scope as best as we can -->
  592. scope = (
  593. case
  594. when b_qualifier = 'VW' THEN 'PRJ'
  595. when b_qualifier = 'SVW' THEN 'PRJ'
  596. when b_qualifier = 'APP' THEN 'PRJ'
  597. when b_qualifier = 'DIR' THEN 'DIR'
  598. when b_qualifier = 'FIL' THEN 'FIL'
  599. when b_qualifier = 'UTS' THEN 'FIL'
  600. <!-- For the few cases where qualifier is not enough to guess the scope (like TRK), just assume the scope remains unchanged -->
  601. else scope
  602. end
  603. ),
  604. b_changed = ${_false},
  605. <!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules -->
  606. deprecated_kee = null,
  607. b_copy_component_uuid = null,
  608. b_description = null,
  609. b_enabled = ${_false},
  610. b_language = null,
  611. b_long_name = null,
  612. b_module_uuid = null,
  613. b_module_uuid_path = null,
  614. b_name = null,
  615. b_path = null,
  616. b_qualifier = null
  617. where
  618. project_uuid = #{projectUuid,jdbcType=VARCHAR} and
  619. b_changed = ${_true}
  620. </update>
  621. <update id="resetBChangedForRootComponentUuid" parameterType="map" >
  622. update components
  623. set b_changed = ${_false},
  624. <!-- Component key is normally immutable, but since 7.6 deprecated_kee is used as a b_kee to migrate component keys after the drop of modules -->
  625. deprecated_kee = kee
  626. where
  627. project_uuid = #{projectUuid,jdbcType=VARCHAR} and
  628. b_changed = ${_true}
  629. </update>
  630. <update id="setPrivateForRootComponentUuid" parameterType="map" >
  631. update components set
  632. private = #{isPrivate,jdbcType=BOOLEAN}
  633. where
  634. project_uuid = #{projectUuid,jdbcType=VARCHAR}
  635. and private &lt;&gt; #{isPrivate,jdbcType=BOOLEAN}
  636. </update>
  637. <delete id="delete" parameterType="String">
  638. DELETE FROM components WHERE uuid=#{componentUuid,jdbcType=VARCHAR}
  639. </delete>
  640. <select id="selectAllSiblingComponentKeysHavingOpenIssues" resultType="KeyWithUuid">
  641. SELECT DISTINCT p.kee as kee, p.uuid as uuid FROM components p
  642. JOIN issues i
  643. ON p.uuid = i.component_uuid
  644. JOIN project_branches b
  645. ON i.project_uuid = b.uuid
  646. AND b.branch_type = 'PULL_REQUEST'
  647. AND b.merge_branch_uuid = #{referenceBranchUuid,jdbcType=VARCHAR}
  648. AND b.uuid != #{currentBranchUuid,jdbcType=VARCHAR}
  649. AND i.status != 'CLOSED'
  650. </select>
  651. <select id="selectPrivateProjectsWithNcloc" resultType="org.sonar.db.component.ProjectNclocDistributionDto">
  652. select p.kee as kee, p.name as name, max(lm.value) as ncloc
  653. from live_measures lm
  654. inner join metrics m on m.uuid = lm.metric_uuid
  655. inner join project_branches b on b.uuid = lm.component_uuid
  656. inner join components p on b.project_uuid = p.uuid
  657. where
  658. m.name = 'ncloc'
  659. and b.branch_type = 'BRANCH'
  660. and p.enabled = ${_true}
  661. and p.private = ${_true}
  662. and p.scope = 'PRJ'
  663. and p.qualifier = 'TRK'
  664. and p.copy_component_uuid is null
  665. group by p.kee, p.name
  666. order by ncloc desc
  667. </select>
  668. <sql id="checkIfAnyOfComponentsWithQualifiersSql">
  669. select
  670. case when exists
  671. (
  672. select c.uuid from components c
  673. where c.kee in
  674. <foreach collection="componentKeys" open="(" close=")" item="componentKey" separator=",">
  675. #{componentKey,jdbcType=VARCHAR}
  676. </foreach>
  677. and c.scope = 'PRJ'
  678. and c.qualifier in
  679. <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator=",">
  680. #{qualifier,jdbcType=VARCHAR}
  681. </foreach>
  682. )
  683. then 1
  684. else 0
  685. end
  686. </sql>
  687. <select id="checkIfAnyOfComponentsWithQualifiers" resultType="short">
  688. <include refid="checkIfAnyOfComponentsWithQualifiersSql"/>
  689. </select>
  690. <select id="checkIfAnyOfComponentsWithQualifiers" resultType="short" databaseId="oracle">
  691. <include refid="checkIfAnyOfComponentsWithQualifiersSql"/>
  692. from dual
  693. </select>
  694. </mapper>