All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.db.user.UserMapper.xml Maven / Gradle / Ivy

The newest version!
<?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.user.UserMapper">

    <sql id="userColumns">
        u.id as id,
        u.uuid as uuid,
        u.login as login,
        u.name as name,
        u.email as email,
        u.active as "active",
        u.scm_accounts as "scmAccounts",
        u.salt as "salt",
        u.crypted_password as "cryptedPassword",
        u.hash_method as "hashMethod",
        u.external_id as "externalId",
        u.external_login as "externalLogin",
        u.external_identity_provider as "externalIdentityProvider",
        u.user_local as "local",
        u.is_root as "root",
        u.onboarded as "onboarded",
        u.homepage_type as "homepageType",
        u.homepage_parameter as "homepageParameter",
        u.organization_uuid as organizationUuid,
        u.created_at as "createdAt",
        u.updated_at as "updatedAt"
    </sql>

    <select id="selectByUuid" parameterType="String" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE u.uuid=#{uuid}
    </select>

    <select id="selectByLogin" parameterType="String" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE u.login=#{login}
    </select>

    <select id="selectNullableByScmAccountOrLoginOrEmail" parameterType="map" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE
        u.login=#{scmAccount}
        OR u.email=#{scmAccount}
        OR u.scm_accounts like #{likeScmAccount}
    </select>

    <select id="selectUser" parameterType="int" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE u.id=#{id}
    </select>

    <select id="selectUserByLogin" parameterType="string" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE u.login=#{id} AND u.active=${_true}
    </select>

    <select id="selectByLogins" parameterType="string" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE u.login in
        <foreach collection="list" open="(" close=")" item="login" separator=",">
            #{login}
        </foreach>
    </select>

    <select id="selectByUuids" parameterType="string" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE u.uuid in
        <foreach collection="list" open="(" close=")" item="uuid" separator=",">
            #{uuid}
        </foreach>
    </select>

    <select id="scrollAll" resultType="User" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
        select
        <include refid="userColumns"/>
        from users u
    </select>

    <select id="selectByIds" parameterType="string" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE u.id in
        <foreach collection="ids" open="(" close=")" item="id" separator=",">
            #{id}
        </foreach>
    </select>

    <select id="selectUsers" parameterType="map" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        <where>
            <if test="logins != null and logins.size() > 0">
                u.login IN
                <foreach item="login" index="index" collection="logins" open="(" separator="," close=")">
                    #{login}
                </foreach>
            </if>
            <if test="includeDeactivated==false">
                AND u.active=${_true}
            </if>
            <if test="searchText != null">
                AND (u.login LIKE #{searchTextSql} ESCAPE '/' OR u.name LIKE #{searchTextSql} ESCAPE '/')
            </if>
            <if test="mustBeRoot != null and mustBeRoot==true">
                AND u.is_root = ${_true}
            </if>
            <if test="mustBeRoot != null and mustBeRoot==false">
                AND u.is_root = ${_false}
            </if>
        </where>
        ORDER BY u.name
    </select>

    <select id="selectByEmail" parameterType="String" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE lower(u.email)=#{email, jdbcType=VARCHAR}
        AND u.active=${_true}
    </select>

    <select id="selectByExternalIdAndIdentityProvider" parameterType="map" resultType="User">
        SELECT
        <include refid="userColumns"/>
        FROM users u
        WHERE u.external_id=#{externalId} AND u.external_identity_provider=#{externalIdentityProvider}
    </select>

    <select id="countRootUsersButLogin" parameterType="String" resultType="long">
        select
        count(1)
        from
        users u
        where
        u.active = ${_true}
        and u.is_root = ${_true}
        and u.login &lt;&gt; #{login}
    </select>

    <update id="deactivateUser" parameterType="map">
        update users set
        active = ${_false},
        email = null,
        scm_accounts = null,
        salt = null,
        crypted_password = null,
        updated_at = #{now, jdbcType=BIGINT}
        where
        login = #{login, jdbcType=VARCHAR}
    </update>

    <update id="clearHomepages" parameterType="map">
        update users set
        homepage_type = null,
        homepage_parameter = null,
        updated_at = #{now, jdbcType=BIGINT}
        where
        homepage_type = #{homepageType, jdbcType=VARCHAR}
        and homepage_parameter = #{homepageParameter, jdbcType=VARCHAR}
    </update>

    <update id="clearHomepage" parameterType="map">
        update users set
        homepage_type = null,
        homepage_parameter = null,
        updated_at = #{now, jdbcType=BIGINT}
        where
        login = #{login, jdbcType=VARCHAR}
    </update>

    <update id="setRoot">
        update users set
        is_root = #{root, jdbcType=BOOLEAN},
        updated_at = #{now, jdbcType=BIGINT}
        where
        login = #{login, jdbcType=VARCHAR}
        and active = ${_true}
    </update>

    <insert id="insert" parameterType="map" keyColumn="id" useGeneratedKeys="true" keyProperty="user.id">
        insert into users (
        uuid,
        login,
        name,
        email,
        active,
        scm_accounts,
        external_id,
        external_login,
        external_identity_provider,
        user_local,
        salt,
        crypted_password,
        hash_method,
        is_root,
        onboarded,
        homepage_type,
        homepage_parameter,
        organization_uuid,
        created_at,
        updated_at
        ) values (
        #{user.uuid,jdbcType=VARCHAR},
        #{user.login,jdbcType=VARCHAR},
        #{user.name,jdbcType=VARCHAR},
        #{user.email,jdbcType=VARCHAR},
        #{user.active,jdbcType=BOOLEAN},
        #{user.scmAccounts,jdbcType=VARCHAR},
        #{user.externalId,jdbcType=VARCHAR},
        #{user.externalLogin,jdbcType=VARCHAR},
        #{user.externalIdentityProvider,jdbcType=VARCHAR},
        #{user.local,jdbcType=BOOLEAN},
        #{user.salt,jdbcType=VARCHAR},
        #{user.cryptedPassword,jdbcType=VARCHAR},
        #{user.hashMethod,jdbcType=VARCHAR},
        #{user.root,jdbcType=BOOLEAN},
        #{user.onboarded,jdbcType=BOOLEAN},
        #{user.homepageType,jdbcType=VARCHAR},
        #{user.homepageParameter,jdbcType=VARCHAR},
        #{user.organizationUuid,jdbcType=VARCHAR},
        #{user.createdAt,jdbcType=BIGINT},
        #{user.updatedAt,jdbcType=BIGINT}
        )
    </insert>

    <update id="update" parameterType="map">
        update users set
        login = #{user.login, jdbcType=VARCHAR},
        name = #{user.name, jdbcType=VARCHAR},
        email = #{user.email, jdbcType=VARCHAR},
        active = #{user.active, jdbcType=BOOLEAN},
        scm_accounts = #{user.scmAccounts, jdbcType=VARCHAR},
        external_id = #{user.externalId, jdbcType=VARCHAR},
        external_login = #{user.externalLogin, jdbcType=VARCHAR},
        external_identity_provider = #{user.externalIdentityProvider, jdbcType=VARCHAR},
        user_local = #{user.local, jdbcType=BOOLEAN},
        onboarded = #{user.onboarded, jdbcType=BOOLEAN},
        salt = #{user.salt, jdbcType=VARCHAR},
        crypted_password = #{user.cryptedPassword, jdbcType=BIGINT},
        hash_method = #{user.hashMethod, jdbcType=VARCHAR},
        homepage_type = #{user.homepageType, jdbcType=VARCHAR},
        homepage_parameter = #{user.homepageParameter, jdbcType=VARCHAR},
        organization_uuid = #{user.organizationUuid, jdbcType=VARCHAR},
        updated_at = #{user.updatedAt,jdbcType=BIGINT}
        where
        uuid = #{user.uuid, jdbcType=VARCHAR}
    </update>

</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy