123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- <?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.qualityprofile.QualityProfileMapper">
-
- <sql id="qProfileColumns">
- oqp.uuid as kee,
- oqp.organization_uuid as organizationUuid,
- oqp.parent_uuid as parentKee,
- oqp.last_used as lastUsed,
- oqp.user_updated_at as userUpdatedAt,
- rp.uuid as rulesProfileUuid,
- rp.name as name,
- rp.language as language,
- rp.rules_updated_at as rulesUpdatedAt,
- rp.is_built_in as isBuiltIn
- </sql>
-
- <sql id="ruleProfileColumns">
- rp.uuid as uuid,
- rp.name as name,
- rp.language as language,
- rp.rules_updated_at as rulesUpdatedAt,
- rp.is_built_in as isBuiltIn
- </sql>
-
- <insert id="insertRuleProfile" parameterType="map" useGeneratedKeys="false">
- insert into rules_profiles (
- uuid,
- name,
- language,
- created_at,
- updated_at,
- rules_updated_at,
- is_built_in
- ) values (
- #{dto.uuid, jdbcType=VARCHAR},
- #{dto.name, jdbcType=VARCHAR},
- #{dto.language, jdbcType=VARCHAR},
- #{now, jdbcType=TIMESTAMP},
- #{now, jdbcType=TIMESTAMP},
- #{dto.rulesUpdatedAt, jdbcType=VARCHAR},
- #{dto.isBuiltIn, jdbcType=BOOLEAN}
- )
- </insert>
-
- <insert id="insertOrgQProfile" parameterType="map" useGeneratedKeys="false">
- insert into org_qprofiles (
- uuid,
- organization_uuid,
- rules_profile_uuid,
- parent_uuid,
- last_used,
- user_updated_at,
- created_at,
- updated_at
- ) values (
- #{dto.uuid, jdbcType=VARCHAR},
- #{dto.organizationUuid, jdbcType=VARCHAR},
- #{dto.rulesProfileUuid, jdbcType=VARCHAR},
- #{dto.parentUuid, jdbcType=VARCHAR},
- #{dto.lastUsed, jdbcType=BIGINT},
- #{dto.userUpdatedAt, jdbcType=BIGINT},
- #{now, jdbcType=BIGINT},
- #{now, jdbcType=BIGINT}
- )
- </insert>
-
- <update id="updateRuleProfile" parameterType="map">
- update rules_profiles
- set
- name = #{dto.name, jdbcType=VARCHAR},
- language = #{dto.language, jdbcType=VARCHAR},
- updated_at = #{now, jdbcType=TIMESTAMP},
- rules_updated_at = #{dto.rulesUpdatedAt, jdbcType=VARCHAR},
- is_built_in = #{dto.isBuiltIn, jdbcType=BOOLEAN}
- where
- uuid = #{dto.uuid, jdbcType=VARCHAR}
- </update>
-
- <update id="updateOrgQProfile" parameterType="map">
- update org_qprofiles
- set
- parent_uuid = #{dto.parentUuid, jdbcType=VARCHAR},
- last_used = #{dto.lastUsed, jdbcType=BIGINT},
- user_updated_at = #{dto.userUpdatedAt, jdbcType=BIGINT},
- updated_at = #{now, jdbcType=BIGINT}
- where
- uuid = #{dto.uuid, jdbcType=VARCHAR}
- </update>
-
- <update id="updateLastUsedDate" parameterType="map">
- update org_qprofiles
- set
- last_used = #{lastUsedDate, jdbcType=BIGINT},
- updated_at = #{now, jdbcType=BIGINT}
- where
- uuid = #{uuid, jdbcType=VARCHAR}
- and (last_used is null or last_used < #{lastUsedDate, jdbcType=BIGINT})
- </update>
-
- <delete id="deleteRuleProfilesByUuids" parameterType="String">
- delete from rules_profiles
- where uuid in
- <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
- </delete>
-
- <delete id="deleteOrgQProfilesByUuids" parameterType="String">
- delete from org_qprofiles
- where uuid in
- <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
- </delete>
-
- <select id="selectBuiltInRuleProfiles" resultType="org.sonar.db.qualityprofile.RulesProfileDto">
- select <include refid="ruleProfileColumns"/>
- from rules_profiles rp
- where rp.is_built_in = ${_true}
- </select>
-
- <select id="selectRuleProfile" resultType="org.sonar.db.qualityprofile.RulesProfileDto">
- select <include refid="ruleProfileColumns"/>
- from rules_profiles rp
- where rp.uuid = #{uuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectOrderedByOrganizationUuid" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- where
- oqp.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
- order by rp.name, rp.language
- </select>
-
- <select id="selectDefaultProfile" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid
- where
- dp.language = #{language, jdbcType=VARCHAR}
- and dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- and rp.language = dp.language
- and oqp.organization_uuid = dp.organization_uuid
- </select>
-
- <select id="selectDefaultBuiltInProfilesWithoutActiveRules" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- SELECT
- <include refid="qProfileColumns"/>
- FROM org_qprofiles oqp
- INNER JOIN rules_profiles rp ON oqp.rules_profile_uuid = rp.uuid
- INNER JOIN default_qprofiles dp ON dp.qprofile_uuid = oqp.uuid
- WHERE
- rp.is_built_in = ${_true}
- AND rp.language IN <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
- AND NOT EXISTS (
- SELECT 1 FROM active_rules ar
- INNER JOIN rules r ON r.uuid = ar.rule_uuid AND r.status <> 'REMOVED'
- WHERE profile_uuid = rp.uuid
- )
- </select>
-
- <select id="selectDefaultProfiles" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid
- where
- dp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
- and dp.organization_uuid = oqp.organization_uuid
- and rp.language = dp.language
- and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectBuiltInRuleProfilesWithActiveRules" resultType="org.sonar.db.qualityprofile.RulesProfileDto">
- select <include refid="ruleProfileColumns"/>
- from rules_profiles rp
- where rp.is_built_in = ${_true}
- AND EXISTS (
- SELECT 1 FROM active_rules ar
- INNER JOIN rules r ON r.uuid = ar.rule_uuid AND r.status <> 'REMOVED'
- WHERE profile_uuid=rp.uuid
- )
- </select>
-
- <select id="selectByNameAndLanguage" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- where
- rp.name = #{name, jdbcType=VARCHAR}
- and rp.language = #{language, jdbcType=VARCHAR}
- and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByRuleProfileUuid" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- where
- rp.uuid = #{ruleProfileUuid, jdbcType=VARCHAR}
- and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByNameAndLanguages" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- where
- rp.name = #{name, jdbcType=VARCHAR}
- and rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
- and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByUuid" parameterType="string" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- where
- oqp.uuid = #{uuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByUuids" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- where
- oqp.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
- </select>
-
- <select id="selectByLanguage" parameterType="String" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- where
- rp.language = #{language, jdbcType=VARCHAR}
- and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <!-- the join on "org_qprofiles parent" is required to benefit from the index on uuid -->
- <select id="selectChildren" parameterType="string" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- inner join org_qprofiles parent on parent.uuid = oqp.parent_uuid
- where
- parent.uuid in <foreach collection="uuids" item="uuid" open="(" close=")" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
- order by rp.name
- </select>
-
- <select id="countProjectsByOrganizationAndProfiles" resultType="KeyLongValue" parameterType="map">
- select pqp.profile_key as "key", count(pj.uuid) as "value"
- from components pj
- inner join project_qprofiles pqp on pqp.project_uuid = pj.uuid
- inner join org_qprofiles oqp on oqp.uuid = pqp.profile_key
- where
- pj.enabled = ${_true}
- and pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- and oqp.organization_uuid = pj.organization_uuid
- and <foreach collection="profileUuids" item="profileUuid" open="(" separator=" or " close=")">
- oqp.uuid = #{profileUuid, jdbcType=VARCHAR}
- </foreach>
- group by pqp.profile_key
- </select>
-
- <select id="selectAssociatedToProjectUuidAndLanguage" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid
- where
- rp.language = #{language, jdbcType=VARCHAR}
- and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
- and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectAssociatedToProjectUuidAndLanguages" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid
- where
- rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
- and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
- and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- </select>
-
- <insert id="insertProjectProfileAssociation" useGeneratedKeys="false">
- insert into project_qprofiles (
- uuid,
- project_uuid,
- profile_key
- ) values (
- #{uuid, jdbcType=VARCHAR},
- #{projectUuid, jdbcType=VARCHAR},
- #{profileUuid, jdbcType=VARCHAR}
- )
- </insert>
-
- <update id="updateProjectProfileAssociation">
- update project_qprofiles
- set
- profile_key = #{profileUuid, jdbcType=VARCHAR}
- where
- project_uuid = #{projectUuid, jdbcType=VARCHAR}
- and profile_key = #{oldProfileUuid, jdbcType=VARCHAR}
- </update>
-
- <delete id="deleteProjectProfileAssociation">
- delete from project_qprofiles
- where
- project_uuid = #{projectUuid, jdbcType=VARCHAR}
- and profile_key=#{profileUuid, jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteProjectAssociationByProfileUuids" parameterType="String">
- delete from project_qprofiles
- where profile_key in
- <foreach collection="profileUuids" open="(" close=")" item="profileUuid" separator=",">
- #{profileUuid, jdbcType=VARCHAR}
- </foreach>
- </delete>
-
- <select id="selectSelectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- select
- pj.uuid as projectUuid,
- pj.kee as projectKey,
- pj.name as projectName,
- pp.profile_key as profileKey
- from components pj
- inner join project_qprofiles pp ON pp.project_uuid = pj.uuid and pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
- where
- pj.scope = 'PRJ'
- and pj.qualifier = 'TRK'
- and pj.main_branch_project_uuid is null
- and upper(pj.name) like #{nameQuery, jdbcType=VARCHAR}
- and pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- order by pj.name ASC
- </select>
-
- <select id="selectDeselectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
- FROM components pj
- LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
- AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null
- AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
- AND pp.profile_key IS NULL
- AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- ORDER BY pj.name ASC
- </select>
-
- <select id="selectProjectAssociations" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
- FROM components pj
- LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
- AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null
- AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
- AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- ORDER BY pj.name ASC
- </select>
-
- <select id="selectUuidsOfCustomRuleProfiles" parameterType="map" resultType="string">
- select oqp.rules_profile_uuid
- from org_qprofiles oqp
- inner join organizations o on o.uuid = oqp.organization_uuid
- inner join rules_profiles rp on rp.uuid = oqp.rules_profile_uuid
- where
- rp.language = #{language, jdbcType=VARCHAR}
- and rp.name = #{name, jdbcType=VARCHAR}
- and rp.is_built_in = ${_false}
- </select>
-
- <update id="renameRuleProfiles" parameterType="map">
- update rules_profiles
- set
- name = #{newName, jdbcType=VARCHAR},
- updated_at = #{updatedAt, jdbcType=TIMESTAMP}
- where
- uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
- </update>
-
- <select id="selectQProfilesByRuleProfileUuid" parameterType="string" resultType="org.sonar.db.qualityprofile.QProfileDto">
- select
- <include refid="qProfileColumns"/>
- from org_qprofiles oqp
- inner join rules_profiles rp on oqp.rules_profile_uuid = rp.uuid
- where
- rp.uuid= #{rulesProfileUuid, jdbcType=VARCHAR}
- </select>
- </mapper>
|