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;
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);
}
--- /dev/null
- <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>
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
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">