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

org.sonar.db.measure.MeasureMapper.xml Maven / Gradle / Ivy

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="org.sonar.db.measure.MeasureMapper">
  <sql id="measureColumns">
    pm.id,
    pm.metric_id as metricId,
    pm.person_id as developerId,
    pm.snapshot_id as snapshotId,
    pm.value as value,
    pm.text_value as textValue,
    pm.alert_status as alertStatus,
    pm.alert_text as alertText,
    pm.measure_data as dataValue,
    pm.variation_value_1 as variation1,
    pm.variation_value_2 as variation2,
    pm.variation_value_3 as variation3,
    pm.variation_value_4 as variation4,
    pm.variation_value_5 as variation5
  </sql>

  <sql id="extendedMeasureColumns">
    <include refid="measureColumns"/>,
    metric.name as metricKey
  </sql>

  <select id="selectByComponentAndMetric" parameterType="map" resultType="Measure">
    SELECT metric.name as metric_name,
    <include refid="extendedMeasureColumns"/>
    FROM project_measures pm
    INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.islast=${_true}
    INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true}
    INNER JOIN metrics metric ON metric.id=pm.metric_id
    <where>
      AND p.kee = #{componentKey}
      AND metric.name=#{metricKey}
      AND pm.person_id IS NULL
    </where>
  </select>

  <select id="selectByComponentAndMetrics" parameterType="map" resultType="Measure">
    SELECT metric.name as metric_name,
    <include refid="extendedMeasureColumns"/>
    FROM project_measures pm
    INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.islast=${_true}
    INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true}
    INNER JOIN metrics metric ON metric.id=pm.metric_id
    <where>
      AND p.kee = #{componentKey}
      AND
      <foreach item="metricKey" index="index" collection="metricKeys" open="(" separator=" or " close=")">
        metric.name=#{metricKey}
      </foreach>
      AND pm.person_id IS NULL
    </where>
  </select>

  <select id="selectBySnapshotAndMetricKeys" parameterType="map" resultType="Measure">
    SELECT
    <include refid="measureColumns"/>
    FROM project_measures pm
    INNER JOIN metrics metric ON metric.id=pm.metric_id
    <where>
      AND pm.snapshot_id = #{snapshotId}
      AND
      <foreach item="metricKey" index="index" collection="metricKeys" open="(" separator=" or " close=")">
        metric.name=#{metricKey}
      </foreach>
      AND pm.person_id IS NULL
    </where>
  </select>

  <select id="selectByDeveloperForSnapshotAndMetrics" parameterType="map" resultType="Measure">
    SELECT
    <include refid="measureColumns"/>
    FROM project_measures pm
    <where>
      pm.snapshot_id = #{snapshotId}
      <if test="developerId!=null">
        AND pm.person_id = #{developerId}
      </if>
      <if test="developerId==null">
        AND pm.person_id is NULL
      </if>
      AND
      <foreach item="metricId" index="index" collection="metricIds" open="(" separator=" or " close=")">
        pm.metric_id=#{metricId}
      </foreach>
    </where>
  </select>

  <select id="selectByDeveloperAndSnapshotIdsAndMetricIds" parameterType="map" resultType="Measure">
    SELECT
    <include refid="measureColumns"/>
    FROM project_measures pm
    <where>
      pm.snapshot_id in
      <foreach item="snapshotId" collection="snapshotIds" open="(" separator="," close=")">
        #{snapshotId}
      </foreach>
      AND
      pm.metric_id in
      <foreach item="metricId" collection="metricIds" open="(" separator="," close=")">
        #{metricId}
      </foreach>
      <if test="developerId==null">
        AND pm.person_id is NULL
      </if>
      <if test="developerId!=null">
        AND pm.person_id=#{developerId}
      </if>
    </where>
  </select>

  <select id="selectProjectMeasuresByDeveloperForMetrics" parameterType="map" resultType="Measure">
    SELECT
    <include refid="measureColumns"/>,
    s.project_id as componentId
    FROM project_measures pm
    INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.islast=${_true} AND s.scope='PRJ' AND s.qualifier='TRK'
    <where>
      pm.person_id = #{developerId}
      AND
      pm.metric_id in
      <foreach item="metricId" collection="metricIds" open="(" separator="," close=")">
        #{metricId}
      </foreach>
    </where>
  </select>

  <select id="selectBySnapshotAndMetrics" parameterType="map" resultType="Measure">
    SELECT
    <include refid="measureColumns"/>
    FROM project_measures pm
    <where>
      pm.snapshot_id = #{snapshotId}
      AND pm.person_id is NULL
      AND
      <foreach item="metricId" index="index" collection="metricIds" open="(" separator=" or " close=")">
        pm.metric_id=#{metricId}
      </foreach>
    </where>
  </select>

  <select id="countByComponentAndMetric" parameterType="map" resultType="long">
    SELECT count(pm.id)
    FROM project_measures pm
    INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.islast=${_true}
    INNER JOIN metrics metric ON metric.id=pm.metric_id
    INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true}
    <where>
      AND p.kee = #{componentKey}
      AND metric.name = #{metricKey}
      AND pm.person_id IS NULL
    </where>
  </select>

  <select id="selectByComponentUuidAndProjectSnapshotIdAndStatusAndMetricIds" parameterType="map"
          resultType="org.sonar.db.measure.PastMeasureDto">
    SELECT pm.id as id, pm.metric_id as metricId,
    pm.person_id as personId, pm.value as value
    FROM project_measures pm
    INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.status=#{status}
    INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true}
    <where>
      AND p.uuid = #{componentUuid}
      AND (s.root_snapshot_id=#{rootSnapshotId} OR s.id=#{rootSnapshotId})
      AND
      <foreach item="metricId" index="index" collection="metricIds" open="(" separator=" or " close=")">
        pm.metric_id=#{metricId}
      </foreach>
      AND pm.person_id IS NULL
    </where>
  </select>

  <insert id="insert" parameterType="Measure" useGeneratedKeys="false">
    INSERT INTO project_measures (
    value, metric_id, snapshot_id, text_value, project_id, alert_status, alert_text, description,
    person_id, variation_value_1, variation_value_2, variation_value_3, variation_value_4,
    variation_value_5, measure_data)
    VALUES (
    #{value, jdbcType=DOUBLE}, #{metricId, jdbcType=INTEGER}, #{snapshotId, jdbcType=INTEGER},
    #{textValue, jdbcType=VARCHAR},
    #{componentId, jdbcType=INTEGER}, #{alertStatus, jdbcType=VARCHAR}, #{alertText, jdbcType=VARCHAR},
    #{description, jdbcType=VARCHAR},
    #{developerId, jdbcType=INTEGER}, #{variation1, jdbcType=DOUBLE}, #{variation2, jdbcType=DOUBLE},
    #{variation3, jdbcType=DOUBLE},
    #{variation4, jdbcType=DOUBLE}, #{variation5, jdbcType=DOUBLE}, #{dataValue, jdbcType=BINARY}
    )
  </insert>

  <select id="selectMetricKeysForSnapshot" parameterType="long" resultType="string">
    SELECT DISTINCT m.name
    FROM project_measures pm
    INNER JOIN metrics m ON m.id=pm.metric_id
    WHERE pm.snapshot_id=#{snapshotId}
  </select>

</mapper>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy