All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.db.qualityprofile.QualityProfileMapper.xml Maven / Gradle / Ivy

The newest version!
<?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.id as id,
    rp.kee 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.id as id,
    rp.kee as kee,
    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" keyColumn="id" useGeneratedKeys="true" keyProperty="dto.id">
    insert into rules_profiles (
      kee,
      name,
      language,
      created_at,
      updated_at,
      rules_updated_at,
      is_built_in
    ) values (
      #{dto.kee, 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
      kee = #{dto.kee, 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>

  <delete id="deleteRuleProfilesByUuids" parameterType="String">
    delete from rules_profiles
    where kee 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.kee = #{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.kee
    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.kee
    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="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.kee
    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.QProfileDto">
    SELECT
      <include refid="qProfileColumns"/>
    FROM org_qprofiles oqp
    INNER JOIN rules_profiles rp ON oqp.rules_profile_uuid = rp.kee
    WHERE
      rp.is_built_in = ${_true}
      AND EXISTS (
        SELECT 1 FROM active_rules ar
        INNER JOIN rules r ON r.id = ar.rule_id AND r.status &lt;&gt; 'REMOVED'
        WHERE profile_id=rp.id
      )
  </select>

  <select id="selectDefaultBuiltInProfilesWithoutActiveRules" 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.kee
    INNER JOIN default_qprofiles dp ON dp.qprofile_uuid = oqp.uuid
    WHERE
      rp.is_built_in = ${_true}
      AND NOT EXISTS (
        SELECT 1 FROM active_rules ar
        INNER JOIN rules r ON r.id = ar.rule_id AND r.status &lt;&gt; 'REMOVED'
        WHERE profile_id=rp.id
      )
  </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.kee
    where 
      rp.name = #{name, jdbcType=VARCHAR}
      and rp.language = #{language, 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.kee
    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.kee
    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.kee
    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.kee
    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.kee
    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 projects 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.kee
    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.kee
    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 (
      project_uuid,
      profile_key
    ) values (
      #{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
      pp.id as id,
      pj.id as projectId,
      pj.uuid as projectUuid,
      pj.kee as projectKey,
      pj.name as projectName,
      pp.profile_key as profileKey
    from projects 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 pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
    FROM projects 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 pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
    FROM projects 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.kee = 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
      kee 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.kee
    where
    rp.kee= #{rulesProfileUuid, jdbcType=VARCHAR}
  </select>
</mapper>





© 2015 - 2024 Weber Informatics LLC | Privacy Policy