diff options
Diffstat (limited to 'sonar-db/src/main/resources/org/sonar/db/measure')
3 files changed, 213 insertions, 0 deletions
diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/CustomMeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/CustomMeasureMapper.xml new file mode 100644 index 00000000000..119cec178b4 --- /dev/null +++ b/sonar-db/src/main/resources/org/sonar/db/measure/CustomMeasureMapper.xml @@ -0,0 +1,83 @@ +<?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.CustomMeasureMapper"> + <sql id="selectColumns"> + m.id, + m.metric_id as metricId, + m.component_uuid as componentUuid, + m.value, + m.text_value as textValue, + m.user_login as userLogin, + m.description, + m.created_at as createdAt, + m.updated_at as updatedAt + </sql> + + <select id="selectById" resultType="CustomMeasure"> + select + <include refid="selectColumns"/> + from manual_measures m + where m.id=#{id} + </select> + + <select id="selectByMetricId" resultType="CustomMeasure"> + select + <include refid="selectColumns"/> + from manual_measures m + where m.metric_id=#{metricId} + </select> + + <select id="selectByComponentUuid" resultType="CustomMeasure"> + select + <include refid="selectColumns"/> + from manual_measures m + where m.component_uuid=#{componentUuid} + </select> + + <insert id="insert" parameterType="CustomMeasure" useGeneratedKeys="true" keyColumn="id" keyProperty="id"> + INSERT INTO manual_measures ( + metric_id, component_uuid, value, text_value, user_login, description, created_at, updated_at + ) + VALUES ( + #{metricId, jdbcType=INTEGER}, #{componentUuid, jdbcType=VARCHAR}, + #{value, jdbcType=DOUBLE}, #{textValue, jdbcType=VARCHAR}, #{userLogin, jdbcType=VARCHAR}, + #{description, jdbcType=VARCHAR}, #{createdAt, jdbcType=BIGINT}, #{updatedAt, jdbcType=BIGINT} + ) + </insert> + + <update id="update" parameterType="CustomMeasure"> + update manual_measures + set value = #{value, jdbcType=DOUBLE}, + text_value = #{textValue, jdbcType=VARCHAR}, + description = #{description, jdbcType=VARCHAR}, + user_login = #{userLogin, jdbcType=VARCHAR}, + updated_at = #{updatedAt, jdbcType=BIGINT} + where id = #{id} + </update> + + <delete id="deleteByMetricIds"> + delete from manual_measures + where metric_id in + <foreach collection="metricIds" item="metricId" open="(" close=")" separator=","> + #{metricId} + </foreach> + </delete> + + <delete id="delete"> + delete from manual_measures + where id=#{id} + </delete> + + <select id="countByComponentUuid" resultType="Integer"> + select count(*) + from manual_measures m + where m.component_uuid=#{componentUuid} + </select> + + <select id="countByComponentIdAndMetricId" resultType="Integer"> + select count(*) + from manual_measures m + where m.metric_id=#{metricId} and m.component_uuid=#{componentUuid} + </select> +</mapper> diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterMapper.xml new file mode 100644 index 00000000000..85e85b3fa4e --- /dev/null +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureFilterMapper.xml @@ -0,0 +1,17 @@ +<?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.MeasureFilterMapper"> + + <select id="findSystemFilterByName" parameterType="string" resultType="MeasureFilter"> + select id, name, user_id as "userId", shared, description, data, created_at as "createdAt", updated_at as + "updatedAt" + from measure_filters WHERE user_id is null and name=#{id} + </select> + + <insert id="insert" parameterType="MeasureFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + INSERT INTO measure_filters (name, user_id, shared, description, data, created_at, updated_at) + VALUES (#{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt}) + </insert> + +</mapper> diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml new file mode 100644 index 00000000000..7d83e993e05 --- /dev/null +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -0,0 +1,113 @@ +<?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.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, + p.kee as componentKey, + metric.name as metricKey + </sql> + + <select id="selectByComponentAndMetric" parameterType="map" resultType="Measure"> + SELECT metric.name as metric_name, + <include refid="measureColumns"/> + 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.rule_id IS NULL + AND pm.characteristic_id IS NULL + AND pm.person_id IS NULL + </where> + </select> + + <select id="selectByComponentAndMetrics" parameterType="map" resultType="Measure"> + SELECT metric.name as metric_name, + <include refid="measureColumns"/> + 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.rule_id IS NULL + AND pm.characteristic_id IS NULL + AND pm.person_id IS NULL + </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.rule_id IS NULL + AND pm.characteristic_id IS NULL + 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.rule_id as ruleId, pm.characteristic_id as characteristicId, + 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> + </where> + </select> + + <insert id="insert" parameterType="Measure" useGeneratedKeys="false"> + INSERT INTO project_measures ( + value, metric_id, snapshot_id, rule_id, text_value, project_id, alert_status, alert_text, description, + characteristic_id, 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}, + #{ruleId, jdbcType=INTEGER}, #{textValue, jdbcType=VARCHAR}, + #{componentId, jdbcType=INTEGER}, #{alertStatus, jdbcType=VARCHAR}, #{alertText, jdbcType=VARCHAR}, + #{description, jdbcType=VARCHAR}, #{characteristicId, jdbcType=INTEGER}, + #{personId, 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> |