-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
CeActivityMapper.xml
182 lines (167 loc) · 5.52 KB
/
CeActivityMapper.xml
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
<?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.ce.CeActivityMapper">
<sql id="columns">
ca.id,
ca.uuid,
ca.task_type as taskType,
ca.component_uuid as componentUuid,
ca.analysis_uuid as analysisUuid,
ca.status as status,
ca.submitter_login as submitterLogin,
ca.submitted_at as submittedAt,
ca.started_at as startedAt,
ca.executed_at as executedAt,
ca.created_at as createdAt,
ca.updated_at as updatedAt,
ca.is_last as isLast,
ca.is_last_key as isLastKey,
ca.execution_time_ms as executionTimeMs,
ca.error_message as errorMessage
</sql>
<select id="selectByUuid" parameterType="String" resultType="org.sonar.db.ce.CeActivityDto">
select
<include refid="columns"/>,
ca.error_stacktrace as errorStacktrace
from ce_activity ca
where ca.uuid=#{uuid}
</select>
<select id="selectByComponentUuid" parameterType="String" resultType="org.sonar.db.ce.CeActivityDto">
select
<include refid="columns"/>
from ce_activity ca
where ca.component_uuid=#{componentUuid}
order by ca.id asc
</select>
<select id="selectUuidsOfRecentlyCreatedByIsLastKey" parameterType="String" resultType="String">
select uuid
from ce_activity
where is_last_key=#{isLastKey}
and status <> 'CANCELED'
order by id desc
</select>
<select id="selectByQuery" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto">
SELECT
<include refid="columns"/>
<include refid="sqlSelectByQuery" />
ORDER BY ca.id desc
LIMIT #{pageSize} OFFSET #{offset}
</select>
<select id="selectByQuery" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto" databaseId="mssql">
SELECT * FROM (
SELECT ROW_NUMBER() OVER(ORDER BY id desc) AS NUMBER,
<include refid="columns"/>
<include refid="sqlSelectByQuery" />
) AS QUERY
WHERE NUMBER BETWEEN (#{offset} * #{pageSize} + 1) AND ((#{offset} + 1) * #{pageSize})
ORDER BY id desc
</select>
<select id="selectByQuery" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto" databaseId="oracle">
SELECT * FROM (
SELECT ROWNUM AS rn, t.* FROM (
SELECT
<include refid="columns"/>
<include refid="sqlSelectByQuery" />
ORDER BY ca.id desc
) t
) t
WHERE rn BETWEEN (#{offset} * #{pageSize} + 1) AND ((#{offset} + 1) * #{pageSize})
</select>
<sql id="sqlSelectByQuery">
from ce_activity ca
<where>
<if test="query.onlyCurrents">
and ca.is_last=${_true}
</if>
<if test="query.componentUuids != null and query.componentUuids.size()>0">
and ca.component_uuid in
<foreach collection="query.componentUuids" open="(" close=")" item="cUuid" separator=",">
#{cUuid}
</foreach>
</if>
<if test="query.statuses != null and !query.statuses.isEmpty()">
and ca.status in
<foreach collection="query.statuses" open="(" close=")" item="status" separator=",">
#{status}
</foreach>
</if>
<if test="query.type != null">
and ca.task_type=#{query.type}
</if>
<if test="query.minSubmittedAt != null">
and ca.submitted_at >= #{query.minSubmittedAt}
</if>
<if test="query.maxExecutedAt != null">
and ca.executed_at <= #{query.maxExecutedAt}
</if>
</where>
</sql>
<select id="selectOlderThan" parameterType="long" resultType="org.sonar.db.ce.CeActivityDto">
select <include refid="columns"/>
from ce_activity ca
where ca.created_at < #{beforeDate,jdbcType=BIGINT}
</select>
<select id="countLastByStatusAndComponentUuid" resultType="int">
select count(1)
from ce_activity
where status=#{status}
and is_last=${_true}
<if test="componentUuid!=null">
and component_uuid=#{componentUuid}
</if>
</select>
<insert id="insert" parameterType="org.sonar.db.ce.CeActivityDto" useGeneratedKeys="false">
insert into ce_activity (
uuid,
component_uuid,
analysis_uuid,
status,
task_type,
is_last,
is_last_key,
submitter_login,
submitted_at,
started_at,
executed_at,
created_at,
updated_at,
execution_time_ms,
error_message,
error_stacktrace
)
values (
#{uuid,jdbcType=VARCHAR},
#{componentUuid,jdbcType=VARCHAR},
#{analysisUuid,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR},
#{taskType,jdbcType=VARCHAR},
#{isLast,jdbcType=BOOLEAN},
#{isLastKey,jdbcType=VARCHAR},
#{submitterLogin,jdbcType=VARCHAR},
#{submittedAt,jdbcType=BIGINT},
#{startedAt,jdbcType=BIGINT},
#{executedAt,jdbcType=BIGINT},
#{createdAt,jdbcType=BIGINT},
#{updatedAt,jdbcType=BIGINT},
#{executionTimeMs,jdbcType=BIGINT},
#{errorMessage,jdbcType=VARCHAR},
#{errorStacktrace,jdbcType=CLOB}
)
</insert>
<update id="updateIsLastToFalseForLastKey" parameterType="map">
update ce_activity
set is_last=${_false},
updated_at=#{updatedAt,jdbcType=BIGINT}
where is_last=${_true} and is_last_key=#{isLastKey}
</update>
<update id="updateIsLastToTrueForUuid" parameterType="map">
update ce_activity
set is_last=${_true},
updated_at=#{updatedAt,jdbcType=BIGINT}
where uuid=#{uuid}
</update>
<delete id="deleteByUuid" parameterType="string">
delete from ce_activity
where uuid=#{uuid}
</delete>
</mapper>