123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
-
- <mapper namespace="org.sonar.db.organization.OrganizationMapper">
- <sql id="selectColumns">
- org.uuid as "uuid",
- org.kee as "key",
- org.name as "name",
- org.description as "description",
- org.default_quality_gate_uuid as "defaultQualityGateUuid",
- org.url as "url",
- org.avatar_url as "avatarUrl",
- org.subscription as "subscription",
- org.created_at as "createdAt",
- org.updated_at as "updatedAt"
- </sql>
-
- <sql id="defaultTemplatesColumns">
- org.default_perm_template_project as "projectUuid",
- org.default_perm_template_app as "applicationsUuid",
- org.default_perm_template_port as "portfoliosUuid"
- </sql>
-
- <select id="selectByUuid" resultType="Organization">
- select
- <include refid="selectColumns"/>
- from organizations org
- where
- org.uuid = #{uuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectDefaultTemplatesByUuid" resultType="org.sonar.db.permission.template.DefaultTemplates">
- select
- <include refid="defaultTemplatesColumns"/>
- from organizations org
- where
- org.uuid = #{uuid, jdbcType=VARCHAR}
- and org.default_perm_template_project is not null
- </select>
-
- <select id="selectByKey" resultType="Organization">
- select
- <include refid="selectColumns"/>
- from organizations org
- where
- org.kee = #{key, jdbcType=VARCHAR}
- </select>
-
- <select id="selectByUuids" resultType="Organization">
- select
- <include refid="selectColumns"/>
- from organizations org
- where
- org.uuid in
- <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
- #{uuid, jdbcType=VARCHAR}
- </foreach>
- </select>
-
- <select id="countByQuery" resultType="int">
- select count(org.uuid)
- <include refid="sqlSelectByQuery" />
- </select>
-
- <select id="selectByQuery" parameterType="map" resultType="Organization">
- select
- <include refid="selectColumns"/>
- <include refid="sqlSelectByQuery" />
- order by
- org.created_at desc
- limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
- </select>
-
- <select id="selectByQuery" parameterType="map" resultType="Organization" databaseId="mssql">
- select * from (
- select row_number() over(order by org.created_at desc) as number,
- <include refid="selectColumns"/>
- <include refid="sqlSelectByQuery" />
- ) as query
- where
- query.number between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
- order by
- query.createdAt desc
- </select>
-
- <select id="selectByQuery" parameterType="map" resultType="Organization" databaseId="oracle">
- select * from (
- select rownum as rn, t.* from (
- select
- <include refid="selectColumns"/>
- <include refid="sqlSelectByQuery" />
- ORDER BY org.created_at desc
- ) t
- ) t
- where
- t.rn between #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
- </select>
-
- <sql id="sqlSelectByQuery">
- from organizations org
- <where>
- <if test="query.keys != null">
- org.kee in
- <foreach collection="query.keys" open="(" close=")" item="key" separator=",">
- #{key, jdbcType=VARCHAR}
- </foreach>
- </if>
- <if test="query.withAnalyses">
- and exists(
- select 1
- from snapshots s
- inner join components p on p.uuid = s.component_uuid
- where p.organization_uuid = org.uuid
- and p.enabled = ${_true}
- and s.islast = ${_true}
- )
- </if>
- <if test="query.analyzedAfter != null">
- and exists(
- select 1
- from snapshots s
- inner join components p on p.uuid = s.component_uuid
- where p.organization_uuid = org.uuid
- and p.enabled = ${_true}
- and s.islast = ${_true}
- and s.created_at >= #{query.analyzedAfter,jdbcType=BIGINT}
- )
- </if>
- </where>
- </sql>
-
- <select id="selectByPermission" parameterType="map" resultType="Organization">
- select
- <include refid="selectColumns"/>
- from organizations org
- inner join user_roles ur on ur.user_uuid = #{userUuid,jdbcType=VARCHAR}
- and ur.component_uuid is null
- and ur.role = #{permission,jdbcType=VARCHAR}
- union
- select
- <include refid="selectColumns"/>
- from organizations org
- inner join group_roles g on g.component_uuid is null
- and g.role = #{permission,jdbcType=VARCHAR}
- inner join groups_users gu on
- gu.group_uuid = g.group_uuid
- and gu.user_uuid= #{userUuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectAllUuids" resultType="String">
- select uuid from organizations
- </select>
-
- <select id="selectDefaultGroupUuidByUuid" resultType="string">
- select org.default_group_uuid
- from organizations org
- where
- org.uuid = #{uuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectNewProjectPrivateByUuid" resultType="Boolean">
- select org.new_project_private
- from organizations org
- where
- org.uuid = #{uuid, jdbcType=VARCHAR}
- </select>
-
- <select id="selectOrganizationsWithNcloc" resultType="org.sonar.db.organization.OrganizationWithNclocDto">
- select o.uuid as id, o.kee as kee, o.name as name, t.ncloc as ncloc
- from organizations o
- left outer join (
- select orgUuid, sum(sumncloc.maxncloc) as ncloc from (
- select b.project_uuid, p.organization_uuid as orgUuid, max(lm.value) as maxncloc
- from live_measures lm
- inner join metrics m on m.uuid = lm.metric_uuid
- inner join components p on p.uuid = lm.component_uuid
- inner join project_branches b on b.uuid = p.uuid
- where
- m.name = #{ncloc, jdbcType=VARCHAR}
- and p.enabled = ${_true}
- and p.private = ${_true}
- and p.scope = 'PRJ'
- and p.qualifier = 'TRK'
- and p.copy_component_uuid is null
- and p.organization_uuid in <foreach collection="organizationUuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
- and b.branch_type = #{branchType, jdbcType=VARCHAR}
- group by b.project_uuid, p.organization_uuid
- ) sumncloc
- group by orgUuid
- ) t on t.orgUuid = o.uuid
- where
- o.uuid in <foreach collection="organizationUuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
- </select>
-
- <insert id="insert" parameterType="map" useGeneratedKeys="false">
- insert into organizations
- (
- uuid,
- kee,
- name,
- description,
- url,
- avatar_url,
- new_project_private,
- default_quality_gate_uuid,
- subscription,
- created_at,
- updated_at
- )
- values
- (
- #{organization.uuid, jdbcType=VARCHAR},
- #{organization.key, jdbcType=VARCHAR},
- #{organization.name, jdbcType=VARCHAR},
- #{organization.description, jdbcType=VARCHAR},
- #{organization.url, jdbcType=VARCHAR},
- #{organization.avatarUrl, jdbcType=VARCHAR},
- #{newProjectPrivate, jdbcType=BOOLEAN},
- #{organization.defaultQualityGateUuid, jdbcType=VARCHAR},
- #{organization.subscription, jdbcType=VARCHAR},
- #{organization.createdAt, jdbcType=BIGINT},
- #{organization.updatedAt, jdbcType=BIGINT}
- )
- </insert>
-
- <update id="update" parameterType="Organization">
- update organizations
- set
- kee = #{organization.key, jdbcType=VARCHAR},
- name = #{organization.name, jdbcType=VARCHAR},
- description = #{organization.description, jdbcType=VARCHAR},
- url = #{organization.url, jdbcType=VARCHAR},
- default_quality_gate_uuid = #{organization.defaultQualityGateUuid, jdbcType=VARCHAR},
- subscription = #{organization.subscription, jdbcType=VARCHAR},
- avatar_url = #{organization.avatarUrl, jdbcType=VARCHAR},
- updated_at = #{organization.updatedAt, jdbcType=BIGINT}
- where
- uuid = #{organization.uuid, jdbcType=VARCHAR}
- </update>
-
- <update id="updateDefaultTemplates">
- update organizations
- set
- default_perm_template_project = #{defaultTemplates.projectUuid, jdbcType=VARCHAR},
- default_perm_template_app = #{defaultTemplates.applicationsUuid, jdbcType=VARCHAR},
- default_perm_template_port = #{defaultTemplates.portfoliosUuid, jdbcType=VARCHAR},
- updated_at = #{now, jdbcType=BIGINT}
- where
- uuid = #{organizationUuid, jdbcType=VARCHAR}
- </update>
-
- <update id="updateDefaultGroupUuid">
- update organizations
- set
- default_group_uuid = #{defaultGroupUuid, jdbcType=VARCHAR},
- updated_at = #{now, jdbcType=BIGINT}
- where
- uuid = #{organizationUuid, jdbcType=VARCHAR}
- </update>
-
- <update id="updateDefaultQualityGate">
- update organizations
- set
- default_quality_gate_uuid = #{defaultQualityGateUuid, jdbcType=INTEGER},
- updated_at = #{now, jdbcType=BIGINT}
- where
- uuid = #{organizationUuid, jdbcType=VARCHAR}
- </update>
-
- <update id="updateNewProjectPrivate">
- update organizations
- set
- new_project_private = #{newProjectPrivate, jdbcType=INTEGER},
- updated_at = #{now, jdbcType=BIGINT}
- where
- uuid = #{organizationUuid, jdbcType=VARCHAR}
- </update>
-
- <delete id="deleteByUuid">
- delete from organizations
- where
- uuid = #{uuid, jdbcType=VARCHAR}
- </delete>
- </mapper>
|