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

org.sonar.db.measure.LiveMeasureMapper.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.measure.LiveMeasureMapper">

  <sql id="columns">
    lm.component_uuid as componentUuid,
    lm.project_uuid as projectUuid,
    lm.metric_id as metricId,
    lm.value as value,
    lm.text_value as textValue,
    lm.measure_data as data,
    lm.variation as variation
  </sql>

  <select id="selectByComponentUuidsAndMetricIds" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
    select <include refid="columns"/> from live_measures lm
    where
    lm.metric_id in <foreach item="metricId" collection="metricIds" open="(" separator="," close=")">#{metricId, jdbcType=INTEGER}</foreach>
    and lm.component_uuid in
    <foreach item="componentUuid" collection="componentUuids" open="(" separator="," close=")">
      #{componentUuid, jdbcType=VARCHAR}
    </foreach>
  </select>

  <select id="selectByComponentUuidsAndMetricKeys" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
    select <include refid="columns"/> from live_measures lm
    inner join metrics m on m.id = lm.metric_id
    where
    m.name in <foreach item="metricKey" collection="metricKeys" open="(" separator="," close=")">#{metricKey, jdbcType=VARCHAR}</foreach>
    and lm.component_uuid in
    <foreach item="componentUuid" collection="componentUuids" open="(" separator="," close=")">
      #{componentUuid, jdbcType=VARCHAR}
    </foreach>
  </select>

  <select id="sumNclocOfBiggestLongLivingBranch" parameterType="map" resultType="long">
    select sum(sumncloc.maxncloc) from (
    select b.project_uuid as projectUuid, max(lm.value) as maxncloc
    from live_measures lm
    inner join metrics m on m.id = lm.metric_id
    inner join projects p on p.uuid = lm.component_uuid
    inner join project_branches b on b.uuid = p.uuid
    <where>
    m.name = #{ncloc, jdbcType=VARCHAR}
    and p.enabled = ${_true}
    and p.scope = 'PRJ'
    and p.qualifier = 'TRK'
    and p.copy_component_uuid is null
    and b.branch_type = #{branchType, jdbcType=VARCHAR}
    and b.key_type = #{branch, jdbcType=VARCHAR}
    <if test="projectUuidToExclude != null">
      and b.project_uuid &lt;&gt; #{projectUuidToExclude,jdbcType=VARCHAR}
    </if>
    </where>
    group by b.project_uuid
    ) sumncloc
  </select>

  <insert id="insert" parameterType="map" useGeneratedKeys="false">
    insert into live_measures (
    uuid,
    component_uuid,
    project_uuid,
    metric_id,
    value,
    text_value,
    variation,
    measure_data,
    update_marker,
    created_at,
    updated_at
    ) values (
    #{uuid, jdbcType=VARCHAR},
    #{dto.componentUuid, jdbcType=VARCHAR},
    #{dto.projectUuid, jdbcType=VARCHAR},
    #{dto.metricId, jdbcType=INTEGER},
    #{dto.value, jdbcType=DOUBLE},
    #{dto.textValue, jdbcType=VARCHAR},
    #{dto.variation, jdbcType=DOUBLE},
    #{dto.data, jdbcType=BINARY},
    #{marker, jdbcType=VARCHAR},
    #{now, jdbcType=BIGINT},
    #{now, jdbcType=BIGINT}
    )
  </insert>

  <update id="update" parameterType="map">
    update live_measures set
    value = #{dto.value, jdbcType=DOUBLE},
    variation = #{dto.variation, jdbcType=DOUBLE},
    text_value = #{dto.textValue, jdbcType=VARCHAR},
    measure_data  = #{dto.data, jdbcType=BINARY},
    update_marker = #{marker, jdbcType=VARCHAR},
    updated_at = #{now, jdbcType=BIGINT}
    where
    component_uuid = #{dto.componentUuid, jdbcType=VARCHAR}
    and metric_id = #{dto.metricId, jdbcType=INTEGER}
  </update>

  <delete id="deleteByProjectUuidExcludingMarker" parameterType="map">
    <include refid="sql_deleteByProjectUuidExcludingMarker"/>
  </delete>

  <!--
  best practice on MySQL : order the rows to be locked in order
  to minimze risk of deadlock.
  https://stackoverflow.com/a/2423921/229031
  https://jira.sonarsource.com/browse/SONAR-10117?focusedCommentId=153555&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-153555
  -->
  <delete id="deleteByProjectUuidExcludingMarker" parameterType="map" databaseId="mysql">
    <include refid="sql_deleteByProjectUuidExcludingMarker"/>
    order by uuid
  </delete>

  <sql id="sql_deleteByProjectUuidExcludingMarker">
    delete from live_measures
    where
    project_uuid = #{projectUuid, jdbcType=VARCHAR} and
    (update_marker != #{marker, jdbcType=VARCHAR} or update_marker is null)
  </sql>

  <select id="selectTreeByQuery" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
    select <include refid="columns"/> from live_measures lm
    inner join projects p on p.uuid = lm.component_uuid
    <!-- TODO do we really need another join on projects ? Using lm.project_uuid should be enough -->
    <include refid="org.sonar.db.component.ComponentMapper.selectDescendantsJoins"/>
    <where>
      <if test="query.getMetricIds() != null">
        lm.metric_id in
        <foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId,jdbcType=INTEGER}</foreach>
      </if>
      and p.enabled = ${_true}
      <if test="query.qualifiers != null">
        and p.qualifier in
        <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=",">
          #{qualifier,jdbcType=VARCHAR}
        </foreach>
      </if>
      <if test="query.nameOrKeyQuery != null">
        and (
        p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR}
        or
        upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/'
        )
      </if>
    </where>

    -- Add measures of base component
    union all
    select <include refid="columns"/> from live_measures lm
    inner join projects p on p.uuid = lm.component_uuid and lm.component_uuid = #{baseUuid, jdbcType=VARCHAR}
    <where>
      <if test="query.getMetricIds() != null">
        lm.metric_id in
        <foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId,jdbcType=INTEGER}</foreach>
      </if>
      and p.enabled = ${_true}
      <if test="query.qualifiers != null">
        and p.qualifier in
        <foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=",">
          #{qualifier,jdbcType=VARCHAR}
        </foreach>
      </if>
      <if test="query.nameOrKeyQuery != null">
        and (
        p.kee = #{query.nameOrKeyQuery,jdbcType=VARCHAR}
        or
        upper(p.name) like #{query.nameOrKeyUpperLikeQuery,jdbcType=VARCHAR} escape '/'
        )
      </if>
    </where>
  </select>
</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy