]> source.dussan.org Git - sonarqube.git/blob
33cd3600741f7a9ca82feb5ba1372536e8a147d9
[sonarqube.git] /
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
3
4 <mapper namespace="org.sonar.db.qualitygate.QualityGateGroupPermissionsMapper">
5
6   <sql id="sqlColumns">
7     qggp.uuid as "uuid",
8     qggp.group_uuid as "groupUuid",
9     qggp.quality_gate_uuid as "qualityGateUuid"
10   </sql>
11
12   <select id="selectByQualityGateAndGroup" parameterType="String" resultType="org.sonar.db.qualitygate.QualityGateGroupPermissionsDto">
13     select
14     <include refid="sqlColumns"/>
15     from qgate_group_permissions qggp
16     where
17     qggp.group_uuid = #{groupUuid}
18     and qggp.quality_gate_uuid = #{qualityGateUuid}
19   </select>
20
21   <select id="selectByQualityGateAndGroups" parameterType="map" resultType="org.sonar.db.qualitygate.QualityGateGroupPermissionsDto">
22     select
23     <include refid="sqlColumns"/>
24     from qgate_group_permissions qggp
25     where
26     <foreach collection="groupUuids" open="(" close=")" item="groupUuid" separator=" or ">
27       qggp.group_uuid = #{groupUuid, jdbcType=VARCHAR}
28     </foreach>
29     and qggp.quality_gate_uuid = #{qualityGateUuid, jdbcType=VARCHAR}
30   </select>
31
32   <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchGroupMembershipDto">
33     SELECT g.uuid as groupUuid, g.name as name, qggp.uuid as uuid
34     <include refid="sqlSelectByQuery"/>
35     ORDER BY g.name ASC
36     LIMIT #{pagination.pageSize,jdbcType=INTEGER}
37     OFFSET #{pagination.offset,jdbcType=INTEGER}
38   </select>
39
40   <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchGroupMembershipDto" databaseId="mssql">
41     select * from (
42     select row_number() over(order by g.name asc) as number,
43       g.uuid as groupUuid, g.name as name, qggp.uuid as uuid
44       <include refid="sqlSelectByQuery" />
45     ) as query
46     where
47     query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
48     order by query.name asc
49   </select>
50
51   <select id="selectByQuery" parameterType="map" resultType="org.sonar.db.user.SearchGroupMembershipDto" databaseId="oracle">
52     select * from (
53       select rownum as rn, t.* from (
54         select g.uuid as groupUuid, g.name as name, qggp.uuid as uuid
55         <include refid="sqlSelectByQuery"/>
56         order by g.name ASC
57       ) t
58     ) t
59     where
60     t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
61   </select>
62
63    <select id="countByQuery" resultType="int">
64     select count(g.uuid)
65     <include refid="sqlSelectByQuery" />
66   </select>
67
68   <sql id="sqlSelectByQuery">
69     FROM groups g
70     LEFT JOIN qgate_group_permissions qggp ON qggp.group_uuid=g.uuid AND qggp.quality_gate_uuid=#{query.qualityGateUuid, jdbcType=VARCHAR}
71     <where>
72       <choose>
73         <when test="query.getMembership() == 'IN'">
74           AND qggp.uuid IS NOT NULL
75         </when>
76         <when test="query.getMembership() == 'OUT'">
77           AND qggp.uuid IS NULL
78         </when>
79       </choose>
80       <if test="query.getQuery() != null">
81         AND (LOWER(g.name) LIKE #{query.querySqlLowercase} ESCAPE '/')
82       </if>
83     </where>
84   </sql>
85
86   <insert id="insert" useGeneratedKeys="false" parameterType="map">
87     insert into qgate_group_permissions(
88     uuid,
89     group_uuid,
90     quality_gate_uuid,
91     created_at
92     ) values (
93     #{dto.uuid, jdbcType=VARCHAR},
94     #{dto.groupUuid, jdbcType=VARCHAR},
95     #{dto.qualityGateUuid, jdbcType=VARCHAR},
96     #{now, jdbcType=BIGINT}
97     )
98   </insert>
99
100   <delete id="delete">
101     delete from qgate_group_permissions
102     where quality_gate_uuid = #{qualityGateUuid, jdbcType=VARCHAR}
103     and group_uuid = #{groupUuid, jdbcType=VARCHAR}
104   </delete>
105
106   <delete id="deleteByGroup">
107     delete from qgate_group_permissions
108     where group_uuid = #{groupUuid, jdbcType=VARCHAR}
109   </delete>
110
111   <delete id="deleteByQualityGate">
112     delete from qgate_group_permissions
113     where quality_gate_uuid = #{qualityGateUuid, jdbcType=VARCHAR}
114   </delete>
115
116 </mapper>