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.

RuleMapper.xml 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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.rule.RuleMapper">
  4. <sql id="ruleColumns">
  5. r.plugin_rule_key as "ruleKey",
  6. r.plugin_name as "repositoryKey",
  7. r.description_format as "descriptionFormat",
  8. r.status,
  9. r.name,
  10. r.plugin_config_key as "configKey",
  11. r.priority as "severity",
  12. r.is_template as "isTemplate",
  13. r.is_external as "isExternal",
  14. r.is_ad_hoc as "isAdHoc",
  15. r.language as "language",
  16. r.template_uuid as "templateUuid",
  17. r.def_remediation_function as "defRemediationFunction",
  18. r.def_remediation_gap_mult as "defRemediationGapMultiplier",
  19. r.def_remediation_base_effort as "defRemediationBaseEffort",
  20. r.gap_description as "gapDescription",
  21. r.security_standards as "securityStandardsField",
  22. r.rule_type as "type",
  23. r.plugin_key as "pluginKey",
  24. r.scope,
  25. r.created_at as "createdAt",
  26. r.updated_at as "updatedAt",
  27. r.note_data as "noteData",
  28. r.note_user_uuid as "noteUserUuid",
  29. r.note_created_at as "noteCreatedAt",
  30. r.note_updated_at as "noteUpdatedAt",
  31. r.remediation_function as "remediationFunction",
  32. r.remediation_gap_mult as "remediationGapMultiplier",
  33. r.remediation_base_effort as "remediationBaseEffort",
  34. r.ad_hoc_name as "adHocName",
  35. r.ad_hoc_description as "adHocDescription",
  36. r.ad_hoc_severity as "adHocSeverity",
  37. r.ad_hoc_type as "adHocType",
  38. r.education_principles as "educationPrinciplesField",
  39. r.clean_code_attribute as "cleanCodeAttribute"
  40. </sql>
  41. <sql id="leftOuterJoinRulesDescriptionSections">
  42. left outer join rule_desc_sections rds on
  43. rds.rule_uuid = r.uuid
  44. </sql>
  45. <sql id="leftOuterJoinRulesDefaultImpacts">
  46. left outer join rules_default_impacts rdi on
  47. rdi.rule_uuid = r.uuid
  48. </sql>
  49. <sql id="leftOuterJoinRulesTags">
  50. left outer join rule_tags rt on
  51. rt.rule_uuid = r.uuid
  52. </sql>
  53. <sql id="selectJoinedTablesColumns">
  54. <!-- rule default impacts -->
  55. rdi.uuid as "rdi_uuid",
  56. rdi.rule_uuid as "rdi_ruleUuid",
  57. rdi.software_quality as "rdi_softwareQuality",
  58. rdi.severity as "rdi_severity",
  59. <!-- rule tags -->
  60. CASE WHEN rt.is_system_tag = ${_true} THEN rt.value ELSE NULL END as rt_systemTags,
  61. CASE WHEN rt.is_system_tag = ${_false} THEN rt.value ELSE NULL END as rt_tags,
  62. rt.is_system_tag as "rt_isSystemTag",
  63. rt.value as "rt_value",
  64. <!-- rule description sections -->
  65. rds.content as "rds_content",
  66. rds.uuid as "rds_uuid",
  67. rds.kee as "rds_kee",
  68. rds.context_key as "rds_contextKey",
  69. rds.context_display_name as "rds_contextDisplayName",
  70. <!-- rule -->
  71. r.uuid as "r_uuid",
  72. <include refid="ruleColumns"/>
  73. </sql>
  74. <select id="selectAll" resultMap="ruleResultMap">
  75. select
  76. <include refid="selectJoinedTablesColumns"/>
  77. from
  78. rules r
  79. <include refid="leftOuterJoinRulesDescriptionSections"/>
  80. <include refid="leftOuterJoinRulesDefaultImpacts"/>
  81. <include refid="leftOuterJoinRulesTags"/>
  82. order by r.uuid
  83. </select>
  84. <resultMap id="ruleResultMap" type="org.sonar.db.rule.RuleDto" autoMapping="true">
  85. <id property="uuid" column="r_uuid"/>
  86. <collection property="ruleDescriptionSectionDtos" ofType="org.sonar.db.rule.RuleDescriptionSectionDto" autoMapping="true"
  87. columnPrefix="rds_">
  88. <id property="uuid" column="uuid"/>
  89. <result property="key" column="kee"/>
  90. <association property="context" javaType="org.sonar.db.rule.RuleDescriptionSectionContextDto" autoMapping="false">
  91. <constructor>
  92. <arg column="contextKey" javaType="String"/>
  93. <arg column="contextDisplayName" javaType="String"/>
  94. </constructor>
  95. </association>
  96. </collection>
  97. <collection property="defaultImpacts" column="rdi_uuid" notNullColumn="rdi_uuid" javaType="java.util.Set" ofType="Impact">
  98. <id property="uuid" column="rdi_uuid"/>
  99. <result property="softwareQuality" column="rdi_softwareQuality"/>
  100. <result property="severity" column="rdi_severity"/>
  101. </collection>
  102. <collection property="systemTags" column="rt_systemTags" notNullColumn="rt_systemTags" javaType="java.util.Set" ofType="string">
  103. <result column="rt_systemTags"/>
  104. </collection>
  105. <collection property="tags" column="rt_tags" notNullColumn="rt_tags" javaType="java.util.Set" ofType="string">
  106. <result column="rt_tags"/>
  107. </collection>
  108. </resultMap>
  109. <select id="selectEnabled" resultMap="ruleResultMap">
  110. select
  111. <include refid="selectJoinedTablesColumns"/>
  112. from
  113. rules r
  114. <include refid="leftOuterJoinRulesDescriptionSections"/>
  115. <include refid="leftOuterJoinRulesDefaultImpacts"/>
  116. <include refid="leftOuterJoinRulesTags"/>
  117. where
  118. r.status != 'REMOVED'
  119. order by r.uuid
  120. </select>
  121. <select id="selectByUuid" parameterType="map" resultMap="ruleResultMap">
  122. select
  123. <include refid="selectJoinedTablesColumns"/>
  124. from
  125. rules r
  126. <include refid="leftOuterJoinRulesDescriptionSections"/>
  127. <include refid="leftOuterJoinRulesDefaultImpacts"/>
  128. <include refid="leftOuterJoinRulesTags"/>
  129. where
  130. r.uuid=#{uuid,jdbcType=VARCHAR}
  131. order by r.uuid
  132. </select>
  133. <select id="selectByUuids" parameterType="map" resultMap="ruleResultMap">
  134. select
  135. <include refid="selectJoinedTablesColumns"/>
  136. from
  137. rules r
  138. <include refid="leftOuterJoinRulesDescriptionSections"/>
  139. <include refid="leftOuterJoinRulesDefaultImpacts"/>
  140. <include refid="leftOuterJoinRulesTags"/>
  141. where
  142. <foreach collection="uuids" index="index" item="uuid" open="" separator=" or " close="">
  143. r.uuid=#{uuid,jdbcType=VARCHAR}
  144. </foreach>
  145. order by r.uuid
  146. </select>
  147. <select id="selectByKey" parameterType="map" resultMap="ruleResultMap">
  148. select
  149. <include refid="selectJoinedTablesColumns"/>
  150. from
  151. rules r
  152. <include refid="leftOuterJoinRulesDescriptionSections"/>
  153. <include refid="leftOuterJoinRulesDefaultImpacts"/>
  154. <include refid="leftOuterJoinRulesTags"/>
  155. where
  156. r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR}
  157. and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR}
  158. order by r.uuid
  159. </select>
  160. <select id="selectIndexingRuleExtensionsByIds" parameterType="map" resultType="org.sonar.db.rule.RuleExtensionForIndexingDto">
  161. <include refid="sqlSelectIndexingRuleExtensions"/>
  162. and
  163. <foreach collection="ruleExtensionIds" index="index" item="ruleExtId" open="" separator=" or " close="">
  164. ( r.uuid = #{ruleExtId, jdbcType=VARCHAR} )
  165. </foreach>
  166. </select>
  167. <sql id="sqlSelectIndexingRuleExtensions">
  168. select
  169. r.uuid as "ruleUuid",
  170. r.plugin_name as "pluginName",
  171. r.plugin_rule_key as "pluginRuleKey",
  172. r.tags as "tags"
  173. from rules r
  174. where
  175. r.tags is not null and
  176. r.tags != ''
  177. </sql>
  178. <sql id="sqlSelectIndexingRuleExtensions" databaseId="oracle">
  179. select
  180. r.uuid as "ruleUuid",
  181. r.plugin_name as "pluginName",
  182. r.plugin_rule_key as "pluginRuleKey",
  183. r.tags as "tags"
  184. from rules r
  185. where
  186. r.tags is not null
  187. </sql>
  188. <select id="selectByKeys" parameterType="map" resultMap="ruleResultMap">
  189. select
  190. <include refid="selectJoinedTablesColumns"/>
  191. from
  192. rules r
  193. <include refid="leftOuterJoinRulesDescriptionSections"/>
  194. <include refid="leftOuterJoinRulesDefaultImpacts"/>
  195. <include refid="leftOuterJoinRulesTags"/>
  196. where
  197. <foreach collection="ruleKeys" index="index" item="ruleKey" open="" separator=" or " close="">
  198. (r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR} and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR})
  199. </foreach>
  200. order by r.uuid
  201. </select>
  202. <select id="selectByQuery" parameterType="map" resultMap="ruleResultMap">
  203. select
  204. <include refid="selectJoinedTablesColumns"/>
  205. from
  206. rules r
  207. <include refid="leftOuterJoinRulesDescriptionSections"/>
  208. <include refid="leftOuterJoinRulesDefaultImpacts"/>
  209. <include refid="leftOuterJoinRulesTags"/>
  210. where
  211. r.status != 'REMOVED'
  212. <if test="query.repositoryKey!=null">
  213. and r.plugin_name = #{query.repositoryKey,jdbcType=VARCHAR}
  214. </if>
  215. <if test="query.key!=null">
  216. and r.plugin_rule_key = #{query.key,jdbcType=VARCHAR}
  217. </if>
  218. <if test="query.configKey!=null">
  219. and r.plugin_config_key = #{query.configKey,jdbcType=VARCHAR}
  220. </if>
  221. order by
  222. r.uuid,
  223. r.updated_at desc
  224. </select>
  225. <select id="selectByTypeAndLanguages" parameterType="map" resultMap="ruleResultMap">
  226. select
  227. <include refid="selectJoinedTablesColumns"/>
  228. from
  229. rules r
  230. <include refid="leftOuterJoinRulesDescriptionSections"/>
  231. <include refid="leftOuterJoinRulesDefaultImpacts"/>
  232. <include refid="leftOuterJoinRulesTags"/>
  233. where
  234. r.status != 'REMOVED' and r.is_external=${_false} and r.is_template=${_false}
  235. and r.rule_type in
  236. <foreach collection="types" item="type" separator="," open="(" close=")">#{type, jdbcType=INTEGER}</foreach>
  237. and r.language in
  238. <foreach collection="languages" item="language" separator="," open="(" close=")">#{language, jdbcType=VARCHAR}</foreach>
  239. order by r.uuid
  240. </select>
  241. <select id="selectByLanguage" parameterType="String" resultType="org.sonar.db.rule.RuleDto" fetchSize="${_scrollFetchSize}"
  242. resultSetType="FORWARD_ONLY">
  243. select
  244. r.uuid as uuid,
  245. <include refid="ruleColumns"/>
  246. from
  247. rules r
  248. where
  249. <include refid="conditionNotExternalRulesByLanguage" />
  250. </select>
  251. <select id="countByLanguage" resultType="java.lang.Long">
  252. select count(*)
  253. from
  254. rules r
  255. where
  256. <include refid="conditionNotExternalRulesByLanguage" />
  257. </select>
  258. <sql id="conditionNotExternalRulesByLanguage">
  259. r.status in ('READY', 'DEPRECATED', 'BETA')
  260. and r.is_external=${_false}
  261. and r.language=#{language, jdbcType=VARCHAR}
  262. </sql>
  263. <insert id="insertRuleDescriptionSection" parameterType="Map" useGeneratedKeys="false">
  264. insert into rule_desc_sections (
  265. uuid,
  266. rule_uuid,
  267. kee,
  268. content,
  269. context_key,
  270. context_display_name
  271. )
  272. values (
  273. #{dto.uuid,jdbcType=VARCHAR},
  274. #{ruleUuid,jdbcType=VARCHAR},
  275. #{dto.key,jdbcType=VARCHAR},
  276. #{dto.content,jdbcType=VARCHAR},
  277. #{dto.context.key,jdbcType=VARCHAR},
  278. #{dto.context.displayName,jdbcType=VARCHAR}
  279. )
  280. </insert>
  281. <insert id="insertRule" parameterType="org.sonar.db.rule.RuleDto" useGeneratedKeys="false">
  282. insert into rules (
  283. uuid,
  284. plugin_key,
  285. plugin_rule_key,
  286. plugin_name,
  287. description_format,
  288. status,
  289. name,
  290. plugin_config_key,
  291. priority,
  292. is_template,
  293. is_external,
  294. is_ad_hoc,
  295. language,
  296. template_uuid,
  297. def_remediation_function,
  298. def_remediation_gap_mult,
  299. def_remediation_base_effort,
  300. gap_description,
  301. security_standards,
  302. rule_type,
  303. scope,
  304. note_data,
  305. note_user_uuid,
  306. note_created_at,
  307. note_updated_at,
  308. remediation_function,
  309. remediation_gap_mult,
  310. remediation_base_effort,
  311. ad_hoc_name,
  312. ad_hoc_description,
  313. ad_hoc_severity,
  314. ad_hoc_type,
  315. education_principles,
  316. clean_code_attribute,
  317. created_at,
  318. updated_at
  319. )
  320. values (
  321. #{uuid,jdbcType=VARCHAR},
  322. #{pluginKey,jdbcType=VARCHAR},
  323. #{ruleKey,jdbcType=VARCHAR},
  324. #{repositoryKey,jdbcType=VARCHAR},
  325. #{descriptionFormat,jdbcType=VARCHAR},
  326. #{status,jdbcType=VARCHAR},
  327. #{name,jdbcType=VARCHAR},
  328. #{configKey,jdbcType=VARCHAR},
  329. #{severity,jdbcType=INTEGER},
  330. #{isTemplate,jdbcType=BOOLEAN},
  331. #{isExternal,jdbcType=BOOLEAN},
  332. #{isAdHoc,jdbcType=BOOLEAN},
  333. #{language,jdbcType=VARCHAR},
  334. #{templateUuid,jdbcType=VARCHAR},
  335. #{defRemediationFunction,jdbcType=VARCHAR},
  336. #{defRemediationGapMultiplier,jdbcType=VARCHAR},
  337. #{defRemediationBaseEffort,jdbcType=VARCHAR},
  338. #{gapDescription,jdbcType=VARCHAR},
  339. #{securityStandardsField,jdbcType=VARCHAR},
  340. #{type,jdbcType=TINYINT},
  341. #{scope,jdbcType=VARCHAR},
  342. #{noteData,jdbcType=CLOB},
  343. #{noteUserUuid,jdbcType=VARCHAR},
  344. #{noteCreatedAt,jdbcType=BIGINT},
  345. #{noteUpdatedAt,jdbcType=BIGINT},
  346. #{remediationFunction,jdbcType=VARCHAR},
  347. #{remediationGapMultiplier,jdbcType=VARCHAR},
  348. #{remediationBaseEffort,jdbcType=VARCHAR},
  349. #{adHocName,jdbcType=VARCHAR},
  350. #{adHocDescription,jdbcType=CLOB},
  351. #{adHocSeverity,jdbcType=VARCHAR},
  352. #{adHocType,jdbcType=TINYINT},
  353. #{educationPrinciplesField,jdbcType=VARCHAR},
  354. #{cleanCodeAttribute,jdbcType=VARCHAR},
  355. #{createdAt,jdbcType=BIGINT},
  356. #{updatedAt,jdbcType=BIGINT}
  357. )
  358. </insert>
  359. <insert id="insertRuleDefaultImpact" parameterType="Map" useGeneratedKeys="false">
  360. INSERT INTO rules_default_impacts (uuid, rule_uuid, software_quality, severity)
  361. VALUES (
  362. #{dto.uuid,jdbcType=VARCHAR},
  363. #{ruleUuid,jdbcType=VARCHAR},
  364. #{dto.softwareQuality,jdbcType=VARCHAR},
  365. #{dto.severity,jdbcType=VARCHAR})
  366. </insert>
  367. <insert id="insertRuleTag" parameterType="Map" useGeneratedKeys="false">
  368. INSERT INTO rule_tags (rule_uuid, value, is_system_tag)
  369. VALUES (
  370. #{ruleUuid,jdbcType=VARCHAR},
  371. #{value,jdbcType=VARCHAR},
  372. #{isSystemTag,jdbcType=BOOLEAN})
  373. </insert>
  374. <update id="updateRule" parameterType="org.sonar.db.rule.RuleDto">
  375. update rules set
  376. plugin_key=#{pluginKey,jdbcType=VARCHAR},
  377. plugin_rule_key=#{ruleKey,jdbcType=VARCHAR},
  378. plugin_name=#{repositoryKey,jdbcType=VARCHAR},
  379. description_format=#{descriptionFormat,jdbcType=VARCHAR},
  380. status=#{status,jdbcType=VARCHAR},
  381. name=#{name,jdbcType=VARCHAR},
  382. plugin_config_key=#{configKey,jdbcType=VARCHAR},
  383. priority=#{severity,jdbcType=INTEGER},
  384. is_template=#{isTemplate,jdbcType=BOOLEAN},
  385. is_external=#{isExternal,jdbcType=BOOLEAN},
  386. is_ad_hoc=#{isAdHoc,jdbcType=BOOLEAN},
  387. language=#{language,jdbcType=VARCHAR},
  388. template_uuid=#{templateUuid,jdbcType=VARCHAR},
  389. def_remediation_function=#{defRemediationFunction,jdbcType=VARCHAR},
  390. def_remediation_gap_mult=#{defRemediationGapMultiplier,jdbcType=VARCHAR},
  391. def_remediation_base_effort=#{defRemediationBaseEffort,jdbcType=VARCHAR},
  392. gap_description=#{gapDescription,jdbcType=VARCHAR},
  393. security_standards=#{securityStandardsField,jdbcType=VARCHAR},
  394. scope=#{scope,jdbcType=VARCHAR},
  395. rule_type=#{type,jdbcType=TINYINT},
  396. note_data=#{noteData,jdbcType=CLOB},
  397. note_user_uuid=#{noteUserUuid,jdbcType=VARCHAR},
  398. note_created_at=#{noteCreatedAt,jdbcType=BIGINT},
  399. note_updated_at=#{noteUpdatedAt,jdbcType=BIGINT},
  400. remediation_function=#{remediationFunction,jdbcType=VARCHAR},
  401. remediation_gap_mult=#{remediationGapMultiplier,jdbcType=VARCHAR},
  402. remediation_base_effort=#{remediationBaseEffort,jdbcType=VARCHAR},
  403. ad_hoc_name=#{adHocName,jdbcType=VARCHAR},
  404. ad_hoc_description=#{adHocDescription,jdbcType=CLOB},
  405. ad_hoc_severity=#{adHocSeverity,jdbcType=VARCHAR},
  406. ad_hoc_type=#{adHocType,jdbcType=TINYINT},
  407. education_principles=#{educationPrinciplesField,jdbcType=VARCHAR},
  408. clean_code_attribute=#{cleanCodeAttribute,jdbcType=VARCHAR},
  409. updated_at=#{updatedAt,jdbcType=BIGINT}
  410. where
  411. uuid=#{uuid,jdbcType=VARCHAR}
  412. </update>
  413. <delete id="deleteRuleDescriptionSection" parameterType="String">
  414. delete from
  415. rule_desc_sections
  416. where
  417. rule_uuid=#{ruleUuid,jdbcType=VARCHAR}
  418. </delete>
  419. <delete id="deleteRuleDefaultImpacts" parameterType="String">
  420. delete from
  421. rules_default_impacts
  422. where
  423. rule_uuid=#{ruleUuid,jdbcType=VARCHAR}
  424. </delete>
  425. <delete id="deleteRuleTags" parameterType="String">
  426. delete from
  427. rule_tags
  428. where
  429. rule_uuid=#{ruleUuid,jdbcType=VARCHAR}
  430. </delete>
  431. <delete id="deleteParams" parameterType="String">
  432. delete from
  433. active_rule_parameters
  434. where
  435. rules_parameter_uuid=#{uuid,jdbcType=VARCHAR}
  436. </delete>
  437. <sql id="paramColumns">
  438. p.uuid as "uuid",
  439. p.rule_uuid as "ruleUuid",
  440. p.name as "name",
  441. p.param_type as "type",
  442. p.default_value as "defaultValue",
  443. p.description as "description"
  444. </sql>
  445. <select id="selectParamsByRuleUuids" resultType="RuleParam">
  446. select
  447. <include refid="paramColumns"/>
  448. from
  449. rules_parameters p
  450. where
  451. <foreach item="uuid" index="index" collection="ruleUuids" open="(" separator=" or " close=")">
  452. p.rule_uuid=#{uuid,jdbcType=VARCHAR}
  453. </foreach>
  454. </select>
  455. <select id="selectAllRuleParams" resultType="RuleParam">
  456. select
  457. <include refid="paramColumns"/>
  458. from
  459. rules_parameters p
  460. </select>
  461. <select id="selectParamsByRuleKey" resultType="RuleParam" parameterType="org.sonar.api.rule.RuleKey">
  462. select
  463. <include refid="paramColumns"/>
  464. from
  465. rules_parameters p, rules r
  466. where
  467. p.rule_uuid=r.uuid
  468. and r.plugin_name=#{repository,jdbcType=VARCHAR}
  469. and r.plugin_rule_key=#{rule,jdbcType=VARCHAR}
  470. </select>
  471. <select id="selectParamsByRuleKeys" resultType="RuleParam" parameterType="map">
  472. select
  473. <include refid="paramColumns"/>
  474. from
  475. rules_parameters p
  476. inner join rules r on
  477. r.uuid=p.rule_uuid
  478. where
  479. <foreach collection="ruleKeys" index="index" item="ruleKey" open="" separator=" or " close="">
  480. (r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR} AND r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR})
  481. </foreach>
  482. </select>
  483. <delete id="deleteParameter" parameterType="String">
  484. delete from
  485. rules_parameters
  486. where
  487. uuid=#{uuid,jdbcType=INTEGER}
  488. </delete>
  489. <insert id="insertParameter" parameterType="RuleParam" useGeneratedKeys="false">
  490. insert into rules_parameters (
  491. uuid,
  492. rule_uuid,
  493. name,
  494. param_type,
  495. default_value,
  496. description
  497. )
  498. values (
  499. #{uuid,jdbcType=VARCHAR},
  500. #{ruleUuid,jdbcType=VARCHAR},
  501. #{name,jdbcType=VARCHAR},
  502. #{type,jdbcType=VARCHAR},
  503. #{defaultValue,jdbcType=VARCHAR},
  504. #{description,jdbcType=VARCHAR}
  505. )
  506. </insert>
  507. <update id="updateParameter" parameterType="RuleParam">
  508. update rules_parameters set
  509. param_type=#{type,jdbcType=VARCHAR},
  510. default_value=#{defaultValue,jdbcType=VARCHAR},
  511. description=#{description,jdbcType=VARCHAR}
  512. where
  513. uuid=#{uuid,jdbcType=VARCHAR}
  514. </update>
  515. <select id="selectAllDeprecatedRuleKeys" resultType="org.sonar.db.rule.DeprecatedRuleKeyDto">
  516. SELECT
  517. drk.uuid,
  518. drk.rule_uuid as "ruleUuid",
  519. drk.old_repository_key as "oldRepositoryKey",
  520. drk.old_rule_key as "oldRuleKey",
  521. r.plugin_rule_key as "newRuleKey",
  522. r.plugin_name as "newRepositoryKey",
  523. drk.created_at as "createdAt"
  524. FROM
  525. deprecated_rule_keys drk
  526. LEFT OUTER JOIN rules r on r.uuid = drk.rule_uuid
  527. </select>
  528. <select id="selectDeprecatedRuleKeysByRuleUuids" resultType="org.sonar.db.rule.DeprecatedRuleKeyDto">
  529. SELECT
  530. drk.uuid,
  531. drk.rule_uuid as "ruleUuid",
  532. drk.old_repository_key as "oldRepositoryKey",
  533. drk.old_rule_key as "oldRuleKey",
  534. r.plugin_rule_key as "newRuleKey",
  535. r.plugin_name as "newRepositoryKey",
  536. drk.created_at as "createdAt"
  537. FROM
  538. deprecated_rule_keys drk
  539. LEFT OUTER JOIN rules r on r.uuid = drk.rule_uuid
  540. WHERE
  541. <foreach item="uuid" index="index" collection="ruleUuids" open="(" separator=" or " close=")">
  542. drk.rule_uuid=#{uuid,jdbcType=VARCHAR}
  543. </foreach>
  544. </select>
  545. <delete id="deleteDeprecatedRuleKeys">
  546. DELETE FROM
  547. deprecated_rule_keys
  548. WHERE
  549. <foreach collection="uuids" index="index" item="uuid" open="" separator=" or " close="">
  550. uuid=#{uuid,jdbcType=INTEGER}
  551. </foreach>
  552. </delete>
  553. <insert id="insertDeprecatedRuleKey" parameterType="org.sonar.db.rule.DeprecatedRuleKeyDto" keyColumn="uuid" useGeneratedKeys="false"
  554. keyProperty="uuid">
  555. INSERT INTO deprecated_rule_keys (
  556. uuid,
  557. rule_uuid,
  558. old_repository_key,
  559. old_rule_key,
  560. created_at
  561. )
  562. values (
  563. #{uuid,jdbcType=VARCHAR},
  564. #{ruleUuid,jdbcType=VARCHAR},
  565. #{oldRepositoryKey,jdbcType=VARCHAR},
  566. #{oldRuleKey,jdbcType=VARCHAR},
  567. #{createdAt,jdbcType=BIGINT}
  568. )
  569. </insert>
  570. <select id="selectTags" resultType="string">
  571. SELECT DISTINCT value FROM
  572. rule_tags rt
  573. WHERE lower(value) like #{query}
  574. ORDER BY value
  575. <include refid="org.sonar.db.common.Common.pagination"/>
  576. </select>
  577. <select id="selectRules">
  578. select r.uuid from rules r
  579. <include refid="queryList"/>
  580. <choose>
  581. <when test="query.sortField == 'createdAt'">
  582. order by r.created_at ${query.sortDirection}
  583. </when>
  584. <otherwise>
  585. order by r.uuid
  586. </otherwise>
  587. </choose>
  588. <include refid="org.sonar.db.common.Common.pagination"/>
  589. </select>
  590. <select id="countByQuery" resultType="long">
  591. select count(r.uuid) from rules r
  592. <include refid="queryList"/>
  593. </select>
  594. <sql id="queryList">
  595. <if test="query.profileUuid != null">
  596. inner join active_rules ar on ar.rule_uuid = r.uuid
  597. </if>
  598. where
  599. r.status != 'REMOVED'
  600. and r.is_external = ${_false}
  601. <if test="query.createdAt != null">
  602. and r.created_at &gt;= #{query.createdAt,jdbcType=BIGINT}
  603. </if>
  604. <if test="query.language != null">
  605. and r.language = #{query.language,jdbcType=VARCHAR}
  606. </if>
  607. <if test="query.profileUuid != null">
  608. and ar.profile_uuid = #{query.profileUuid,jdbcType=VARCHAR}
  609. </if>
  610. </sql>
  611. </mapper>