]> source.dussan.org Git - sonarqube.git/commitdiff
Merge remote-tracking branch 'origin/branch-6.7'
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 20 Dec 2017 10:58:08 +0000 (11:58 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 20 Dec 2017 10:58:08 +0000 (11:58 +0100)
1  2 
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeConfiguration.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java

index 245c23c7c6a01cf9a9c10a8ff552560ba641152a,15fc642e8423ac8f24f908db072e8d633d99642c..219d1afcfa722046cf6d9378a479620d8d7014fe
@@@ -20,6 -20,6 +20,7 @@@
  package org.sonar.db.purge;
  
  import com.google.common.annotations.VisibleForTesting;
++import java.util.Arrays;
  import java.util.Collection;
  import java.util.Date;
  import java.util.Optional;
@@@ -30,6 -30,9 +31,8 @@@ import org.sonar.api.resources.Scopes
  import org.sonar.api.utils.System2;
  import org.sonar.core.config.PurgeConstants;
  
 -import static java.util.Arrays.asList;
+ import static java.util.Collections.singletonList;
  public class PurgeConfiguration {
  
    private final IdUuidPair rootProjectIdUuid;
      this.maxAgeInDaysOfInactiveShortLivingBranches = maxAgeInDaysOfInactiveShortLivingBranches;
    }
  
 -  public static PurgeConfiguration newDefaultPurgeConfiguration(Configuration config, IdUuidPair idUuidPair, Collection<String> disabledComponentUuids) {
 -    Collection<String> scopesWithoutHistoricalData = singletonList(Scopes.FILE);
 +  public static PurgeConfiguration newDefaultPurgeConfiguration(Configuration config, IdUuidPair rootId, Collection<String> disabledComponentUuids) {
-     String[] scopes = new String[] {Scopes.FILE};
++    Collection<String> scopes = singletonList(Scopes.FILE);
      if (config.getBoolean(PurgeConstants.PROPERTY_CLEAN_DIRECTORY).orElse(false)) {
-       scopes = new String[] {Scopes.DIRECTORY, Scopes.FILE};
 -      scopesWithoutHistoricalData = asList(Scopes.FILE, Scopes.DIRECTORY);
++      scopes = Arrays.asList(Scopes.DIRECTORY, Scopes.FILE);
      }
 -    return new PurgeConfiguration(idUuidPair, scopesWithoutHistoricalData, config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES).get(),
 +    return new PurgeConfiguration(rootId, scopes, config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES).get(),
        config.getInt(PurgeConstants.DAYS_BEFORE_DELETING_INACTIVE_SHORT_LIVING_BRANCHES), System2.INSTANCE, disabledComponentUuids);
    }
  
index 57eb8f870087766c5d1f7044f41f3070467c7af4,0000000000000000000000000000000000000000..0c9db60b475c8fbb9955c4bd68ed64781af4d11f
mode 100644,000000..100644
--- /dev/null
@@@ -1,110 -1,0 +1,136 @@@
-       <include refid="org.sonar.db.component.ComponentMapper.selectDescendantsFilters"/>
 +<?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>
 +
 +  <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">
 +    delete from live_measures
 +    where
 +    project_uuid = #{projectUuid, jdbcType=VARCHAR} and
 +    (update_marker != #{marker, jdbcType=VARCHAR} or update_marker is null)
 +  </delete>
 +
 +  <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>
-       <include refid="org.sonar.db.component.ComponentMapper.selectDescendantsFilters"/>
++      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>
index 4dd4ecd7504e1c9d865b7df44a994149cf51560f,d29bcf17665d8de25762a9b94f9049aa82318179..a5d4d313c7bc4ac8283e027e8bf9326d92969cca
      pm.variation_value_1 as variation
    </sql>
  
 -  <sql id="extendedMeasureColumns">
 -    <include refid="measureColumns"/>,
 -    metric.name as metricKey
 -  </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}
++    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
@@@ -65,7 -49,7 +65,7 @@@
      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
++    and p.uuid=pm.component_uuid
      where
      <include refid="selectByQueryCommonFilters"/>
      and pm.component_uuid=#{query.componentUuid,jdbcType=VARCHAR}
      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>
 -      and pm.person_id is null
++    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
++    inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
      where
      pm.component_uuid = #{query.componentUuid, jdbcType=VARCHAR}
      <if test="query.from!= null">