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

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

  <sql id="measureColumns">
    pm.metric_id as metricId,
    pm.component_uuid as componentUuid,
    pm.analysis_uuid as analysisUuid,
    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 variation
  </sql>

  <select id="selectLastMeasure" parameterType="map" resultType="Measure">
    select <include refid="measureColumns"/>
    from project_measures pm
    inner join metrics m on m.id = pm.metric_id
    inner join snapshots s on s.uuid = pm.analysis_uuid
    where
    pm.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
    m.name = #{metricKey,jdbcType=VARCHAR} and
    s.islast= ${_true}
  </select>

  <select id="selectMeasure" parameterType="map" resultType="Measure">
    select <include refid="measureColumns"/>
    from project_measures pm
    inner join metrics m on m.id = pm.metric_id
    inner join snapshots s on s.uuid = pm.analysis_uuid
    where
    pm.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
    m.name = #{metricKey,jdbcType=VARCHAR} and
    s.uuid = #{analysisUuid,jdbcType=VARCHAR}
  </select>

  <select id="selectByQueryOnProjects" parameterType="map" resultType="Measure">
    select <include refid="measureColumns"/> from project_measures pm
    <include refid="selectByQueryCommonJoins"/>
    where
    <include refid="selectByQueryCommonFilters"/>
    and analysis.component_uuid=pm.component_uuid
    and analysis.component_uuid in
    <foreach item="projectUuid" collection="query.getProjectUuids()" open="(" separator="," close=")">
      #{projectUuid,jdbcType=VARCHAR}
    </foreach>
  </select>

  <select id="selectByQueryOnComponents" parameterType="map" resultType="Measure">
    select <include refid="measureColumns"/> from project_measures pm
    <include refid="selectByQueryCommonJoins"/>
    where
    <include refid="selectByQueryCommonFilters"/>
    and analysis.component_uuid=#{query.projectUuid,jdbcType=VARCHAR}
    and pm.component_uuid in
    <foreach item="componentUuid" collection="query.getComponentUuids()" open="(" separator="," close=")">
      #{componentUuid,jdbcType=VARCHAR}
    </foreach>
  </select>

  <select id="selectByQueryOnSingleComponent" parameterType="map" resultType="Measure">
    select <include refid="measureColumns"/> from project_measures pm
    <include refid="selectByQueryCommonJoins"/>
    inner join projects p on p.project_uuid=analysis.component_uuid
    and p.uuid=pm.component_uuid
    where
    <include refid="selectByQueryCommonFilters"/>
    and pm.component_uuid=#{query.componentUuid,jdbcType=VARCHAR}
  </select>

  <sql id="selectByQueryCommonJoins">
    inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
    <if test="query.getMetricKeys() != null">
      inner join metrics m on m.id = pm.metric_id
    </if>
  </sql>

  <sql id="selectByQueryCommonFilters">
    <if test="query.getAnalysisUuid() == null">
      analysis.islast=${_true}
    </if>
    <if test="query.getAnalysisUuid() != null">
      analysis.uuid = #{query.analysisUuid,jdbcType=VARCHAR}
    </if>
    <if test="query.getMetricIds() != null">
      and pm.metric_id in
      <foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId}</foreach>
    </if>
    <if test="query.getMetricKeys() != null">
      and m.name in
      <foreach item="metricKey" collection="query.getMetricKeys()" open="(" separator="," close=")">
        #{metricKey,jdbcType=VARCHAR}
      </foreach>
    </if>
  </sql>

  <select id="selectPastMeasuresOnSingleAnalysis" parameterType="map" resultType="org.sonar.db.measure.PastMeasureDto">
    select pm.id as id, pm.metric_id as metricId, pm.value as value
    from project_measures pm
    inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
    where
    pm.component_uuid = #{componentUuid,jdbcType=VARCHAR}
    and analysis.uuid = #{analysisUuid,jdbcType=VARCHAR}
    and pm.metric_id in <foreach item="metricId" collection="metricIds" open="(" separator="," close=")">#{metricId}</foreach>
  </select>

  <select id="selectPastMeasuresOnSeveralAnalyses" parameterType="map" resultType="Measure">
    select <include refid="measureColumns"/>
    from project_measures pm
    inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
    where
    pm.component_uuid = #{query.componentUuid, jdbcType=VARCHAR}
    <if test="query.from!= null">
      and analysis.created_at>=#{query.from, jdbcType=BIGINT}
    </if>
    <if test="query.to!=null">
      and analysis.created_at&lt;#{query.to, jdbcType=BIGINT}
    </if>
    and pm.metric_id in <foreach item="metricId" collection="query.metricIds" open="(" separator="," close=")">#{metricId, jdbcType=VARCHAR}</foreach>
    and analysis.status=#{query.status, jdbcType=VARCHAR}
  </select>

  <insert id="insert" parameterType="Measure" useGeneratedKeys="false">
    insert into project_measures (
    value,
    metric_id,
    component_uuid,
    analysis_uuid,
    text_value,
    alert_status,
    alert_text,
    variation_value_1,
    measure_data)
    VALUES (
    #{value, jdbcType=DOUBLE},
    #{metricId, jdbcType=INTEGER},
    #{componentUuid, jdbcType=VARCHAR},
    #{analysisUuid, jdbcType=VARCHAR},
    #{textValue, jdbcType=VARCHAR},
    #{alertStatus, jdbcType=VARCHAR},
    #{alertText, jdbcType=VARCHAR},
    #{variation, jdbcType=DOUBLE},
    #{dataValue, jdbcType=BINARY}
    )
  </insert>

</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy