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

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