1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
<?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.metric_id as metricId,
pm.person_id as developerId,
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>
<sql id="extendedMeasureColumns">
<include refid="measureColumns"/>,
metric.name as metricKey
</sql>
<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>
<choose>
<when test="query.getPersonId() != null">
and pm.person_id = #{query.personId,jdbcType=BIGINT}
</when>
<otherwise>
and pm.person_id is null
</otherwise>
</choose>
</sql>
<select id="selectTreeByQuery" parameterType="map" resultType="Measure">
select <include refid="measureColumns"/> from project_measures pm
inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
inner join projects p on p.project_uuid=analysis.component_uuid and p.uuid=pm.component_uuid
<include refid="org.sonar.db.component.ComponentMapper.selectDescendantsJoins"/>
<where>
<include refid="selectTreeByQueryFilters"/>
</where>
-- Add measures of base component
union all
select <include refid="measureColumns"/> from project_measures pm
inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
inner join projects p on p.project_uuid=analysis.component_uuid and p.uuid=pm.component_uuid and pm.component_uuid=#{baseUuid}
<where>
<include refid="selectTreeByQueryFilters"/>
</where>
</select>
<sql id="selectTreeByQueryFilters">
and analysis.islast=${_true}
<if test="query.getMetricIds() != null">
and pm.metric_id in
<foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId}</foreach>
</if>
<choose>
<when test="query.getPersonId() != null">
and pm.person_id = #{query.personId,jdbcType=BIGINT}
</when>
<otherwise>
and pm.person_id is null
</otherwise>
</choose>
<include refid="org.sonar.db.component.ComponentMapper.selectDescendantsFilters"/>
</sql>
<select id="selectPastMeasuresOnSingleAnalysis" 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 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
</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<#{query.to, jdbcType=BIGINT}
</if>
and pm.metric_id in <foreach item="metricId" collection="query.metricIds" open="(" separator="," close=")">#{metricId, jdbcType=VARCHAR}</foreach>
and pm.person_id is null
and analysis.status=#{query.status, jdbcType=VARCHAR}
</select>
<select id="selectProjectMeasuresOfDeveloper" parameterType="map" resultType="Measure">
SELECT
<include refid="measureColumns"/>
from
project_measures pm, snapshots s, projects p
where
pm.person_id=#{developerId,jdbcType=BIGINT}
and pm.metric_id in
<foreach item="metricId" collection="metricIds" open="(" separator="," close=")">
#{metricId}
</foreach>
and s.uuid=pm.analysis_uuid
and s.islast=${_true}
and p.uuid=pm.component_uuid
and p.scope='PRJ'
and p.qualifier='TRK'
</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,
description,
person_id,
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},
#{description, jdbcType=VARCHAR},
#{developerId, jdbcType=INTEGER},
#{variation, jdbcType=DOUBLE},
#{dataValue, jdbcType=BINARY}
)
</insert>
</mapper>
|