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

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