aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
blob: 95af7ba53a8bb95da73d2930e31083c429537116 (plain)
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
<?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.component.SnapshotMapper">

  <sql id="snapshotColumns">
    s.id,
    s.parent_snapshot_id as parentId,
    s.root_snapshot_id as rootId,
    s.root_project_id as rootProjectId,
    s.project_id as componentId,
    s.created_at as createdAt,
    s.build_date as buildDate,
    s.status as status,
    s.purge_status as purgeStatus,
    s.islast as last,
    s.scope as scope,
    s.qualifier as qualifier,
    s.version as version,
    s.path as path,
    s.depth as depth,
    s.period1_mode as period1Mode,
    s.period2_mode as period2Mode,
    s.period3_mode as period3Mode,
    s.period4_mode as period4Mode,
    s.period5_mode as period5Mode,
    s.period1_param as period1Param,
    s.period2_param as period2Param,
    s.period3_param as period3Param,
    s.period4_param as period4Param,
    s.period5_param as period5Param,
    s.period1_date as period1Date,
    s.period2_date as period2Date,
    s.period3_date as period3Date,
    s.period4_date as period4Date,
    s.period5_date as period5Date
  </sql>

  <select id="selectByKey" parameterType="Long" resultType="Snapshot">
    SELECT
    <include refid="snapshotColumns"/>
    FROM snapshots s
    <where>
      AND s.id=#{key}
    </where>
  </select>

  <select id="selectLastSnapshot" resultType="Snapshot">
    select
    <include refid="snapshotColumns"/>
    from snapshots s
    where s.islast=${_true} and s.project_id = #{resource}
  </select>

  <select id="selectSnapshotsByQuery" parameterType="map" resultType="Snapshot">
    SELECT
    <include refid="snapshotColumns"/>
    FROM snapshots s
    <where>
      <if test="query.componentId != null">
        AND s.project_id=#{query.componentId}
      </if>
      <if test="query.status != null">
        AND status=#{query.status}
      </if>
      <if test="query.version != null">
        AND version=#{query.version}
      </if>
      <if test="query.isLast != null">
        AND islast=#{query.isLast}
      </if>
      <if test="query.createdAfter != null">
        AND created_at>=#{query.createdAfter}
      </if>
      <if test="query.createdBefore != null">
        AND created_at&lt;#{query.createdBefore}
      </if>
    </where>
    <if test="query.sortField != null">
      ORDER BY
      <if test="query.sortField == 'created_at'">
        created_at
      </if>
      <if test="query.sortOrder == 'asc'">
        asc
      </if>
      <if test="query.sortOrder == 'desc'">
        desc
      </if>
    </if>
  </select>

  <select id="selectPreviousVersionSnapshots" parameterType="map" resultType="Snapshot">
    SELECT
    <include refid="snapshotColumns"/>
    FROM snapshots s
    INNER JOIN events e ON s.id = e.snapshot_id AND e.name &lt;&gt; #{lastVersion} AND e.category='Version'
    INNER JOIN projects p ON p.uuid=e.component_uuid AND p.id=#{componentId}
    ORDER BY e.event_date DESC
  </select>

  <select id="selectSnapshotAndChildrenOfScope" parameterType="map" resultType="Snapshot">
    select
    <include refid="snapshotColumns"/>
    from snapshots s
    where s.scope = #{scope}
    AND (s.id = #{snapshot} or s.root_snapshot_id = #{snapshot})
  </select>

  <sql id="insertColumns">
    (parent_snapshot_id, root_snapshot_id, root_project_id, project_id, created_at, build_date, status, purge_status,
    islast, scope, qualifier, version, path, depth,
    period1_mode, period2_mode, period3_mode, period4_mode, period5_mode,
    period1_param, period2_param, period3_param, period4_param, period5_param,
    period1_date, period2_date, period3_date, period4_date, period5_date)
  </sql>

  <update id="updateSnapshotAndChildrenLastFlagAndStatus" parameterType="map">
    update snapshots
    set islast = #{isLast}, status = #{status}
    where root_snapshot_id=#{root} or id=#{root} or (path like #{path} and root_snapshot_id=#{pathRootId})
  </update>

  <update id="updateSnapshotAndChildrenLastFlag" parameterType="map">
    update snapshots
    set islast = #{isLast}
    where root_snapshot_id=#{root} or id=#{root} or (path like #{path} and root_snapshot_id=#{pathRootId})
  </update>

  <insert id="insert" parameterType="Snapshot" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
    insert into snapshots
    <include refid="insertColumns"/>
    values (#{parentId}, #{rootId}, #{rootProjectId}, #{componentId}, #{createdAt}, #{buildDate}, #{status},
    #{purgeStatus}, #{last}, #{scope}, #{qualifier}, #{version}, #{path}, #{depth},
    #{period1Mode}, #{period2Mode}, #{period3Mode}, #{period4Mode}, #{period5Mode},
    #{period1Param}, #{period2Param}, #{period3Param}, #{period4Param}, #{period5Param},
    #{period1Date}, #{period2Date}, #{period3Date}, #{period4Date}, #{period5Date})
  </insert>

</mapper>