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.

ProjectMapper.xml 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.project.ProjectMapper">
  4. <sql id="projectColumns">
  5. p.uuid as uuid,
  6. p.kee as kee,
  7. p.qualifier as qualifier,
  8. p.name as name,
  9. p.description as description,
  10. p.tags as tagsString,
  11. p.private as isPrivate,
  12. p.created_at as createdAt,
  13. p.updated_at as updatedAt,
  14. p.initial_perm_sync as initialPermSync
  15. </sql>
  16. <select id="selectAllProjectUuids" resultType="String">
  17. SELECT
  18. p.uuid as uuid
  19. FROM projects p
  20. where p.qualifier = 'TRK'
  21. </select>
  22. <select id="selectByUuid" parameterType="String" resultType="Project">
  23. SELECT
  24. <include refid="projectColumns"/>
  25. FROM projects p
  26. where
  27. p.uuid=#{uuid,jdbcType=VARCHAR}
  28. </select>
  29. <select id="selectByUuids" resultType="Project">
  30. select
  31. <include refid="projectColumns"/>
  32. from projects p
  33. where
  34. p.uuid in
  35. <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
  36. #{uuid,jdbcType=VARCHAR}
  37. </foreach>
  38. </select>
  39. <select id="selectByUuidsWithPagination" resultType="Project">
  40. select
  41. <include refid="projectColumns"/>
  42. from projects p
  43. where
  44. p.uuid in
  45. <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
  46. #{uuid,jdbcType=VARCHAR}
  47. </foreach>
  48. order by p.name, uuid desc
  49. offset (#{pagination.startRowNumber,jdbcType=INTEGER}-1) rows fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
  50. </select>
  51. <select id="selectProjectsByKeys" resultType="Project">
  52. select
  53. <include refid="projectColumns"/>
  54. from projects p
  55. where
  56. p.qualifier='TRK' and
  57. p.kee in
  58. <foreach collection="kees" open="(" close=")" item="k" separator=",">
  59. #{k,jdbcType=VARCHAR}
  60. </foreach>
  61. </select>
  62. <select id="selectApplicationsByKeys" resultType="Project">
  63. select
  64. <include refid="projectColumns"/>
  65. from projects p
  66. where
  67. p.qualifier='APP' and
  68. p.kee in
  69. <foreach collection="kees" open="(" close=")" item="k" separator=",">
  70. #{k,jdbcType=VARCHAR}
  71. </foreach>
  72. </select>
  73. <select id="selectByBranchUuid" parameterType="String" resultType="Project">
  74. SELECT
  75. <include refid="projectColumns"/>
  76. FROM projects p inner join project_branches pb on pb.project_uuid = p.uuid
  77. where pb.uuid=#{branchUuid,jdbcType=VARCHAR}
  78. </select>
  79. <select id="selectProjects" resultType="Project">
  80. select
  81. <include refid="projectColumns"/>
  82. from projects p
  83. where
  84. p.qualifier='TRK'
  85. </select>
  86. <select id="selectAll" resultType="Project">
  87. select
  88. <include refid="projectColumns"/>
  89. from projects p
  90. </select>
  91. <select id="selectAllApplications" resultType="Project">
  92. select
  93. <include refid="projectColumns"/>
  94. from projects p
  95. where
  96. p.qualifier='APP'
  97. </select>
  98. <select id="selectProjectByKey" parameterType="String" resultType="Project">
  99. SELECT
  100. <include refid="projectColumns"/>
  101. FROM projects p
  102. where
  103. p.qualifier='TRK' and
  104. p.kee=#{key,jdbcType=VARCHAR}
  105. </select>
  106. <select id="selectApplicationByKey" parameterType="String" resultType="Project">
  107. SELECT
  108. <include refid="projectColumns"/>
  109. FROM projects p
  110. where
  111. p.qualifier='APP' and
  112. p.kee=#{key,jdbcType=VARCHAR}
  113. </select>
  114. <select id="selectProjectOrAppByKey" parameterType="String" resultType="Project">
  115. SELECT
  116. <include refid="projectColumns"/>
  117. FROM projects p
  118. where
  119. p.kee=#{key,jdbcType=VARCHAR}
  120. </select>
  121. <select id="selectProjectUuidsAssociatedToDefaultQualityProfileByLanguage" parameterType="map" resultType="string">
  122. select
  123. lm.project_uuid
  124. from
  125. live_measures lm
  126. inner join
  127. projects p on p.uuid = lm.project_uuid
  128. inner join
  129. metrics m on m.uuid = lm.metric_uuid
  130. inner join
  131. project_branches pb on pb.uuid = lm.component_uuid
  132. where
  133. m.name = 'ncloc_language_distribution'
  134. and pb.is_main = ${_true}
  135. and p.uuid not in (select project_uuid from project_qprofiles)
  136. and
  137. <foreach collection="languageFilters" index="index" item="languageFilter" open="(" separator=" or " close=")">
  138. lm.text_value like #{languageFilter, jdbcType=VARCHAR} escape '/'
  139. </foreach>
  140. </select>
  141. <insert id="insert" parameterType="Project">
  142. INSERT INTO projects (
  143. kee,
  144. qualifier,
  145. uuid,
  146. name,
  147. description,
  148. private,
  149. tags,
  150. created_at,
  151. updated_at,
  152. initial_perm_sync
  153. )
  154. VALUES (
  155. #{kee,jdbcType=VARCHAR},
  156. #{qualifier,jdbcType=VARCHAR},
  157. #{uuid,jdbcType=VARCHAR},
  158. #{name,jdbcType=VARCHAR},
  159. #{description,jdbcType=VARCHAR},
  160. #{isPrivate,jdbcType=BOOLEAN},
  161. #{tagsString, jdbcType=VARCHAR},
  162. #{createdAt,jdbcType=BIGINT},
  163. #{updatedAt,jdbcType=BIGINT},
  164. #{initialPermSync,jdbcType=VARCHAR}
  165. )
  166. </insert>
  167. <update id="updateTags" parameterType="Project">
  168. update projects set
  169. tags = #{tagsString,jdbcType=VARCHAR},
  170. updated_at = #{updatedAt,jdbcType=BIGINT}
  171. where
  172. uuid = #{uuid,jdbcType=VARCHAR}
  173. </update>
  174. <update id="update" parameterType="Project">
  175. update projects set
  176. name = #{name,jdbcType=VARCHAR},
  177. description = #{description,jdbcType=VARCHAR},
  178. updated_at = #{updatedAt,jdbcType=BIGINT}
  179. where
  180. uuid = #{uuid,jdbcType=VARCHAR}
  181. </update>
  182. <update id="updateVisibility">
  183. update projects set
  184. private = #{isPrivate,jdbcType=BOOLEAN},
  185. updated_at = #{updatedAt,jdbcType=BIGINT}
  186. where
  187. uuid = #{uuid,jdbcType=VARCHAR}
  188. </update>
  189. <update id="updateNcloc">
  190. update projects set
  191. ncloc = #{ncloc,jdbcType=BIGINT}
  192. where
  193. uuid = #{projectUuid,jdbcType=VARCHAR}
  194. </update>
  195. <select id="getNclocSum" parameterType="string" resultType="long">
  196. select sum(ncloc) from projects where qualifier = 'TRK'
  197. <if test="projectUuidToExclude != null">
  198. and uuid &lt;&gt; #{projectUuidToExclude,jdbcType=VARCHAR}
  199. </if>
  200. </select>
  201. <select id="countIndexedProjects" resultType="int">
  202. select count(p.uuid)
  203. from projects p
  204. where p.qualifier = 'TRK'
  205. and not exists (select 1 from project_branches pb where pb.project_uuid = p.uuid and pb.need_issue_sync = ${_true})
  206. </select>
  207. <select id="countProjects" resultType="int">
  208. select count(p.uuid)
  209. from projects p
  210. where p.qualifier = 'TRK'
  211. </select>
  212. </mapper>