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
|
<?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.uuid,
ca.task_type as taskType,
ca.component_uuid as componentUuid,
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
</sql>
<select id="selectByUuid" parameterType="String" resultType="org.sonar.db.ce.CeActivityDto">
select
<include refid="columns"/>
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
</select>
<select id="countByQuery" parameterType="map" resultType="int">
select count(ca.id)
<include refid="sqlSelectByQuery" />
</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.status != null">
and ca.status=#{query.status}
</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>
<insert id="insert" parameterType="org.sonar.db.ce.CeActivityDto" useGeneratedKeys="false">
insert into ce_activity
(uuid, component_uuid, status, task_type, is_last, is_last_key, submitter_login, submitted_at, started_at,
executed_at, created_at, updated_at, execution_time_ms)
values (
#{uuid,jdbcType=VARCHAR},
#{componentUuid,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}
)
</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>
|