123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
-
- <mapper namespace="org.sonar.db.rule.RuleMapper">
-
- <sql id="selectDefinitionColumns">
- r.uuid,
- r.plugin_rule_key as "ruleKey",
- r.plugin_name as "repositoryKey",
- r.description,
- r.description_format as "descriptionFormat",
- r.status,
- r.name,
- r.plugin_config_key as "configKey",
- r.priority as "severity",
- r.is_template as "isTemplate",
- r.is_external as "isExternal",
- r.is_ad_hoc as "isAdHoc",
- r.language as "language",
- r.template_uuid as "templateUuid",
- r.def_remediation_function as "defRemediationFunction",
- r.def_remediation_gap_mult as "defRemediationGapMultiplier",
- r.def_remediation_base_effort as "defRemediationBaseEffort",
- r.gap_description as "gapDescription",
- r.system_tags as "systemTagsField",
- r.security_standards as "securityStandardsField",
- r.rule_type as "type",
- r.plugin_key as "pluginKey",
- r.scope,
- </sql>
-
- <sql id="selectRuleTableColumns">
- <include refid="selectDefinitionColumns"/>
- r.created_at as "createdAt",
- r.updated_at as "updatedAt"
- </sql>
-
- <sql id="selectJoinedTablesColumns">
- <include refid="selectDefinitionColumns"/>
- r.created_at as "createdAtFromDefinition",
- r.updated_at as "updatedAtFromDefinition",
- rm.note_data as "noteData",
- rm.note_user_uuid as "noteUserUuid",
- rm.note_created_at as "noteCreatedAt",
- rm.note_updated_at as "noteUpdatedAt",
- rm.remediation_function as "remediationFunction",
- rm.remediation_gap_mult as "remediationGapMultiplier",
- rm.remediation_base_effort as "remediationBaseEffort",
- rm.tags as "tagsField",
- rm.ad_hoc_name as "adHocName",
- rm.ad_hoc_description as "adHocDescription",
- rm.ad_hoc_severity as "adHocSeverity",
- rm.ad_hoc_type as "adHocType",
- rm.created_at as "createdAtFromMetadata",
- rm.updated_at as "updatedAtFromMetadata"
- </sql>
-
- <sql id="outerJoinRulesMetadata">
- left outer join rules_metadata rm on
- rm.rule_uuid = r.uuid
- and rm.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
- </sql>
-
- <select id="selectAll" resultType="Rule">
- select
- <include refid="selectJoinedTablesColumns"/>
- from
- rules r
- <include refid="outerJoinRulesMetadata"/>
- </select>
-
- <select id="selectAllDefinitions" resultType="org.sonar.db.rule.RuleDefinitionDto">
- select
- <include refid="selectRuleTableColumns"/>
- from
- rules r
- </select>
-
- <select id="selectEnabled" resultType="org.sonar.db.rule.RuleDefinitionDto">
- select
- <include refid="selectRuleTableColumns"/>
- from
- rules r
- where
- r.status != 'REMOVED'
- </select>
-
- <select id="selectByUuid" parameterType="map" resultType="Rule">
- select
- <include refid="selectJoinedTablesColumns"/>
- from
- rules r
- <include refid="outerJoinRulesMetadata"/>
- where
- r.uuid=#{uuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectDefinitionByUuid" parameterType="String" resultType="org.sonar.db.rule.RuleDefinitionDto">
- select
- <include refid="selectRuleTableColumns"/>
- from
- rules r
- where
- r.uuid=#{uuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectByUuids" parameterType="map" resultType="Rule">
- select
- <include refid="selectJoinedTablesColumns"/>
- from
- rules r
- <include refid="outerJoinRulesMetadata"/>
- where
- <foreach collection="uuids" index="index" item="uuid" open="" separator=" or " close="">
- r.uuid=#{uuid,jdbcType=VARCHAR}
- </foreach>
- </select>
-
- <select id="selectDefinitionByUuids" parameterType="map" resultType="org.sonar.db.rule.RuleDefinitionDto">
- select
- <include refid="selectRuleTableColumns"/>
- from
- rules r
- where
- <foreach collection="uuids" index="index" item="uuid" open="" separator=" or " close="">
- r.uuid=#{uuid,jdbcType=VARCHAR}
- </foreach>
- </select>
-
- <select id="selectByKey" parameterType="map" resultType="Rule">
- select
- <include refid="selectJoinedTablesColumns"/>
- from
- rules r
- <include refid="outerJoinRulesMetadata"/>
- where
- r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR}
- and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR}
- </select>
-
- <select id="selectDefinitionByKey" parameterType="map" resultType="org.sonar.db.rule.RuleDefinitionDto">
- select
- <include refid="selectRuleTableColumns"/>
- from
- rules r
- where
- r.plugin_name=#{repository,jdbcType=VARCHAR}
- and r.plugin_rule_key=#{rule,jdbcType=VARCHAR}
- </select>
-
- <select id="selectIndexingRuleExtensionsByIds" parameterType="map" resultType="org.sonar.db.rule.RuleExtensionForIndexingDto">
- <include refid="sqlSelectIndexingRuleExtensions" />
- and
- <foreach collection="ruleExtensionIds" index="index" item="ruleExtId" open="" separator=" or " close="">
- ( r.uuid = #{ruleExtId.ruleUuid, jdbcType=VARCHAR} and
- rm.organization_uuid = #{ruleExtId.organizationUuid, jdbcType=VARCHAR} )
- </foreach>
- </select>
-
- <select id="scrollIndexingRuleExtensions" resultType="org.sonar.db.rule.RuleExtensionForIndexingDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
- <include refid="sqlSelectIndexingRuleExtensions" />
- </select>
-
- <sql id="sqlSelectIndexingRuleExtensions">
- select
- r.uuid as "ruleUuid",
- r.plugin_name as "pluginName",
- r.plugin_rule_key as "pluginRuleKey",
- rm.organization_uuid as "organizationUuid",
- rm.tags as "tags"
- from rules r
- inner join rules_metadata rm on rm.rule_uuid = r.uuid
- where
- rm.tags is not null and
- rm.tags != ''
- </sql>
-
- <sql id="sqlSelectIndexingRuleExtensions" databaseId="oracle">
- select
- r.uuid as "ruleUuid",
- r.plugin_name as "pluginName",
- r.plugin_rule_key as "pluginRuleKey",
- rm.organization_uuid as "organizationUuid",
- rm.tags as "tags"
- from rules r
- inner join rules_metadata rm on rm.rule_uuid = r.uuid
- where
- rm.tags is not null
- </sql>
-
- <select id="selectMetadataByKey" parameterType="map" resultType="org.sonar.db.rule.RuleMetadataDto">
- select
- rm.rule_uuid as "ruleUuid",
- rm.organization_uuid as "organizationUuid",
- rm.note_data as "noteData",
- rm.note_user_uuid as "noteUserUuid",
- rm.note_created_at as "noteCreatedAt",
- rm.note_updated_at as "noteUpdatedAt",
- rm.remediation_function as "remediationFunction",
- rm.remediation_gap_mult as "remediationGapMultiplier",
- rm.remediation_base_effort as "remediationBaseEffort",
- rm.tags as "tagsField",
- rm.ad_hoc_name as "adHocName",
- rm.ad_hoc_description as "adHocDescription",
- rm.ad_hoc_severity as "adHocSeverity",
- rm.ad_hoc_type as "adHocType",
- rm.created_at as "createdAt",
- rm.updated_at as "updatedAt"
- from
- rules_metadata rm
- inner join rules r on rm.rule_uuid = r.uuid
- where
- r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR}
- and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR}
- and rm.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectByKeys" parameterType="map" resultType="Rule">
- select
- <include refid="selectJoinedTablesColumns"/>
- from
- rules r
- <include refid="outerJoinRulesMetadata"/>
- where
- <foreach collection="ruleKeys" index="index" item="ruleKey" open="" separator=" or " close="">
- (r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR} and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR})
- </foreach>
- </select>
-
- <select id="selectDefinitionByKeys" parameterType="map" resultType="org.sonar.db.rule.RuleDefinitionDto">
- select
- <include refid="selectRuleTableColumns"/>
- from
- rules r
- where
- <foreach collection="ruleKeys" index="index" item="ruleKey" open="" separator=" or " close="">
- (r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR} and r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR})
- </foreach>
- </select>
-
- <select id="selectIndexingRulesByUuids" parameterType="map" resultType="org.sonar.db.rule.RuleForIndexingDto">
- <include refid="sqlSelectIndexingRules"/>
- where
- <foreach collection="ruleUuids" index="index" item="ruleUuid" open="" separator=" or " close="">
- r.uuid=#{ruleUuid,jdbcType=VARCHAR}
- </foreach>
- order by r.created_at asc
- </select>
-
- <select id="scrollIndexingRules" resultType="org.sonar.db.rule.RuleForIndexingDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
- <include refid="sqlSelectIndexingRules"/>
- order by r.created_at asc
- </select>
-
- <sql id="sqlSelectIndexingRules">
- select
- r.uuid as "uuid",
- r.plugin_name as "repository",
- r.plugin_rule_key as "pluginRuleKey",
- r.name as "name",
- r.description as "description",
- r.description_format as "descriptionFormat",
- r.priority as "severity",
- r.status as "status",
- r.is_template as "isTemplate",
- r.is_external as "isExternal",
- r.system_tags as "systemTags",
- r.security_standards as "securityStandards",
- t.plugin_rule_key as "templateRuleKey",
- t.plugin_name as "templateRepository",
- r.plugin_config_key as "internalKey",
- r.language as "language",
- r.rule_type as "type",
- r.created_at as "createdAt",
- r.updated_at as "updatedAt"
- from rules r
- left outer join rules t on t.uuid = r.template_uuid
- </sql>
-
- <select id="selectByQuery" parameterType="map" resultType="Rule">
- select
- <include refid="selectJoinedTablesColumns"/>
- from
- rules r
- <include refid="outerJoinRulesMetadata"/>
- where
- r.status != 'REMOVED'
- <if test="query.repositoryKey!=null">
- and r.plugin_name = #{query.repositoryKey,jdbcType=VARCHAR}
- </if>
- <if test="query.key!=null">
- and r.plugin_rule_key = #{query.key,jdbcType=VARCHAR}
- </if>
- <if test="query.configKey!=null">
- and r.plugin_config_key = #{query.configKey,jdbcType=VARCHAR}
- </if>
- order by
- r.updated_at desc
- </select>
-
- <select id="selectByTypeAndLanguages" parameterType="map" resultType="Rule">
- select
- <include refid="selectJoinedTablesColumns"/>
- from
- rules r
- <include refid="outerJoinRulesMetadata"/>
- where
- r.status != 'REMOVED' and r.is_external=${_false} and r.is_template=${_false}
- and r.rule_type in <foreach collection="types" item="type" separator="," open="(" close=")">#{type, jdbcType=INTEGER}</foreach>
- and r.language in <foreach collection="languages" item="language" separator="," open="(" close=")">#{language, jdbcType=VARCHAR}</foreach>
- </select>
-
- <insert id="insertDefinition" parameterType="org.sonar.db.rule.RuleDefinitionDto" useGeneratedKeys="false">
- insert into rules (
- uuid,
- plugin_key,
- plugin_rule_key,
- plugin_name,
- description,
- description_format,
- status,
- name,
- plugin_config_key,
- priority,
- is_template,
- is_external,
- is_ad_hoc,
- language,
- template_uuid,
- def_remediation_function,
- def_remediation_gap_mult,
- def_remediation_base_effort,
- gap_description,
- system_tags,
- security_standards,
- rule_type,
- scope,
- created_at,
- updated_at
- )
- values (
- #{uuid,jdbcType=VARCHAR},
- #{pluginKey,jdbcType=VARCHAR},
- #{ruleKey,jdbcType=VARCHAR},
- #{repositoryKey,jdbcType=VARCHAR},
- #{description,jdbcType=VARCHAR},
- #{descriptionFormat,jdbcType=VARCHAR},
- #{status,jdbcType=VARCHAR},
- #{name,jdbcType=VARCHAR},
- #{configKey,jdbcType=VARCHAR},
- #{severity,jdbcType=INTEGER},
- #{isTemplate,jdbcType=BOOLEAN},
- #{isExternal,jdbcType=BOOLEAN},
- #{isAdHoc,jdbcType=BOOLEAN},
- #{language,jdbcType=VARCHAR},
- #{templateUuid,jdbcType=VARCHAR},
- #{defRemediationFunction,jdbcType=VARCHAR},
- #{defRemediationGapMultiplier,jdbcType=VARCHAR},
- #{defRemediationBaseEffort,jdbcType=VARCHAR},
- #{gapDescription,jdbcType=VARCHAR},
- #{systemTagsField,jdbcType=VARCHAR},
- #{securityStandardsField,jdbcType=VARCHAR},
- #{type,jdbcType=TINYINT},
- #{scope,jdbcType=VARCHAR},
- #{createdAt,jdbcType=BIGINT},
- #{updatedAt,jdbcType=BIGINT}
- )
- </insert>
-
- <update id="updateDefinition" parameterType="org.sonar.db.rule.RuleDefinitionDto">
- update rules set
- plugin_key=#{pluginKey,jdbcType=VARCHAR},
- plugin_rule_key=#{ruleKey,jdbcType=VARCHAR},
- plugin_name=#{repositoryKey,jdbcType=VARCHAR},
- description=#{description,jdbcType=VARCHAR},
- description_format=#{descriptionFormat,jdbcType=VARCHAR},
- status=#{status,jdbcType=VARCHAR},
- name=#{name,jdbcType=VARCHAR},
- plugin_config_key=#{configKey,jdbcType=VARCHAR},
- priority=#{severity,jdbcType=INTEGER},
- is_template=#{isTemplate,jdbcType=BOOLEAN},
- is_external=#{isExternal,jdbcType=BOOLEAN},
- is_ad_hoc=#{isAdHoc,jdbcType=BOOLEAN},
- language=#{language,jdbcType=VARCHAR},
- template_uuid=#{templateUuid,jdbcType=VARCHAR},
- def_remediation_function=#{defRemediationFunction,jdbcType=VARCHAR},
- def_remediation_gap_mult=#{defRemediationGapMultiplier,jdbcType=VARCHAR},
- def_remediation_base_effort=#{defRemediationBaseEffort,jdbcType=VARCHAR},
- gap_description=#{gapDescription,jdbcType=VARCHAR},
- system_tags=#{systemTagsField,jdbcType=VARCHAR},
- security_standards=#{securityStandardsField,jdbcType=VARCHAR},
- scope=#{scope,jdbcType=VARCHAR},
- rule_type=#{type,jdbcType=TINYINT},
- updated_at=#{updatedAt,jdbcType=BIGINT}
- where
- uuid=#{uuid,jdbcType=VARCHAR}
- </update>
-
- <select id="countMetadata" parameterType="org.sonar.db.rule.RuleMetadataDto" resultType="int">
- select
- count(1)
- from
- rules_metadata rm
- where
- rm.rule_uuid=#{ruleUuid,jdbcType=VARCHAR}
- and rm.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
- </select>
-
- <insert id="insertMetadata" parameterType="org.sonar.db.rule.RuleMetadataDto">
- insert into rules_metadata (
- rule_uuid,
- organization_uuid,
- note_data,
- note_user_uuid,
- note_created_at,
- note_updated_at,
- remediation_function,
- remediation_gap_mult,
- remediation_base_effort,
- tags,
- ad_hoc_name,
- ad_hoc_description,
- ad_hoc_severity,
- ad_hoc_type,
- created_at,
- updated_at
- )
- values (
- #{ruleUuid,jdbcType=VARCHAR},
- #{organizationUuid,jdbcType=VARCHAR},
- #{noteData,jdbcType=CLOB},
- #{noteUserUuid,jdbcType=VARCHAR},
- #{noteCreatedAt,jdbcType=BIGINT},
- #{noteUpdatedAt,jdbcType=BIGINT},
- #{remediationFunction,jdbcType=VARCHAR},
- #{remediationGapMultiplier,jdbcType=VARCHAR},
- #{remediationBaseEffort,jdbcType=VARCHAR},
- #{tagsField,jdbcType=VARCHAR},
- #{adHocName,jdbcType=VARCHAR},
- #{adHocDescription,jdbcType=CLOB},
- #{adHocSeverity,jdbcType=VARCHAR},
- #{adHocType,jdbcType=TINYINT},
- #{createdAt,jdbcType=BIGINT},
- #{updatedAt,jdbcType=BIGINT}
- )
- </insert>
-
- <update id="updateMetadata" parameterType="org.sonar.db.rule.RuleMetadataDto">
- update rules_metadata set
- note_data=#{noteData,jdbcType=CLOB},
- note_user_uuid=#{noteUserUuid,jdbcType=VARCHAR},
- note_created_at=#{noteCreatedAt,jdbcType=BIGINT},
- note_updated_at=#{noteUpdatedAt,jdbcType=BIGINT},
- remediation_function=#{remediationFunction,jdbcType=VARCHAR},
- remediation_gap_mult=#{remediationGapMultiplier,jdbcType=VARCHAR},
- remediation_base_effort=#{remediationBaseEffort,jdbcType=VARCHAR},
- tags=#{tagsField,jdbcType=VARCHAR},
- ad_hoc_name=#{adHocName,jdbcType=VARCHAR},
- ad_hoc_description=#{adHocDescription,jdbcType=CLOB},
- ad_hoc_severity=#{adHocSeverity,jdbcType=VARCHAR},
- ad_hoc_type=#{adHocType,jdbcType=TINYINT},
- updated_at=#{updatedAt,jdbcType=BIGINT}
- where
- rule_uuid=#{ruleUuid,jdbcType=VARCHAR}
- and organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
- </update>
-
- <delete id="deleteParams" parameterType="String">
- delete from
- active_rule_parameters
- where
- rules_parameter_uuid=#{uuid,jdbcType=VARCHAR}
- </delete>
-
- <sql id="paramColumns">
- p.uuid as "uuid",
- p.rule_uuid as "ruleUuid",
- p.name as "name",
- p.param_type as "type",
- p.default_value as "defaultValue",
- p.description as "description"
- </sql>
-
- <select id="selectParamsByRuleUuids" resultType="RuleParam">
- select
- <include refid="paramColumns"/>
- from
- rules_parameters p
- where
- <foreach item="uuid" index="index" collection="ruleUuids" open="(" separator=" or " close=")">
- p.rule_uuid=#{uuid,jdbcType=VARCHAR}
- </foreach>
- </select>
-
- <select id="selectParamsByRuleKey" resultType="RuleParam" parameterType="org.sonar.api.rule.RuleKey">
- select
- <include refid="paramColumns"/>
- from
- rules_parameters p, rules r
- where
- p.rule_uuid=r.uuid
- and r.plugin_name=#{repository,jdbcType=VARCHAR}
- and r.plugin_rule_key=#{rule,jdbcType=VARCHAR}
- </select>
-
- <select id="selectParamsByRuleKeys" resultType="RuleParam" parameterType="map">
- select
- <include refid="paramColumns"/>
- from
- rules_parameters p
- inner join rules r on
- r.uuid=p.rule_uuid
- where
- <foreach collection="ruleKeys" index="index" item="ruleKey" open="" separator=" or " close="">
- (r.plugin_name=#{ruleKey.repository,jdbcType=VARCHAR} AND r.plugin_rule_key=#{ruleKey.rule,jdbcType=VARCHAR})
- </foreach>
- </select>
-
- <delete id="deleteParameter" parameterType="String">
- delete from
- rules_parameters
- where
- uuid=#{uuid,jdbcType=INTEGER}
- </delete>
-
- <insert id="insertParameter" parameterType="RuleParam" useGeneratedKeys="false">
- insert into rules_parameters (
- uuid,
- rule_uuid,
- name,
- param_type,
- default_value,
- description
- )
- values (
- #{uuid,jdbcType=VARCHAR},
- #{ruleUuid,jdbcType=VARCHAR},
- #{name,jdbcType=VARCHAR},
- #{type,jdbcType=VARCHAR},
- #{defaultValue,jdbcType=VARCHAR},
- #{description,jdbcType=VARCHAR}
- )
- </insert>
-
- <update id="updateParameter" parameterType="RuleParam">
- update rules_parameters set
- param_type=#{type,jdbcType=VARCHAR},
- default_value=#{defaultValue,jdbcType=VARCHAR},
- description=#{description,jdbcType=VARCHAR}
- where
- uuid=#{uuid,jdbcType=VARCHAR}
- </update>
-
- <select id="selectAllDeprecatedRuleKeys" resultType="org.sonar.db.rule.DeprecatedRuleKeyDto">
- SELECT
- drk.uuid,
- drk.rule_uuid as "ruleUuid",
- drk.old_repository_key as "oldRepositoryKey",
- drk.old_rule_key as "oldRuleKey",
- r.plugin_rule_key as "newRuleKey",
- r.plugin_name as "newRepositoryKey",
- drk.created_at as "createdAt"
- FROM
- deprecated_rule_keys drk
- LEFT OUTER JOIN rules r on r.uuid = drk.rule_uuid
- </select>
-
- <delete id="deleteDeprecatedRuleKeys">
- DELETE FROM
- deprecated_rule_keys
- WHERE
- <foreach collection="uuids" index="index" item="uuid" open="" separator=" or " close="">
- uuid=#{uuid,jdbcType=INTEGER}
- </foreach>
- </delete>
-
- <insert id="insertDeprecatedRuleKey" parameterType="org.sonar.db.rule.DeprecatedRuleKeyDto" keyColumn="uuid" useGeneratedKeys="false" keyProperty="uuid">
- INSERT INTO deprecated_rule_keys (
- uuid,
- rule_uuid,
- old_repository_key,
- old_rule_key,
- created_at
- )
- values (
- #{uuid,jdbcType=VARCHAR},
- #{ruleUuid,jdbcType=VARCHAR},
- #{oldRepositoryKey,jdbcType=VARCHAR},
- #{oldRuleKey,jdbcType=VARCHAR},
- #{createdAt,jdbcType=BIGINT}
- )
- </insert>
- </mapper>
|