SequenceKeyDao.xml 2.22 KB
<?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="com.diligrp.assistant.uid.dao.SequenceKeyDao">
    <resultMap id="PersistentKeyMap" type="com.diligrp.assistant.uid.domain.PersistentSequenceKey">
        <id column="id" property="id"/>
        <result column="key" property="key"/>
        <result column="name" property="name"/>
        <result column="value" property="value"/>
        <result column="step" property="step"/>
        <result column="pattern" property="pattern"/>
        <result column="expired_on" property="expiredOn"/>
        <result column="today" property="today"/>
        <result column="version" property="version"/>
    </resultMap>

    <insert id="insertSequenceKey" parameterType="com.diligrp.assistant.uid.domain.PersistentSequenceKey">
        INSERT INTO uid_sequence_key(`key`, name, value, step, pattern, expired_on, version)
        VALUES (#{key}, #{name}, #{value}, #{step}, #{pattern}, #{expiredOn}, #{version})
    </insert>

    <select id="findSequenceKey" parameterType="string" resultMap="PersistentKeyMap">
        SELECT
            id, `key`, name, value, step, pattern, expired_on, curdate() AS today, version
        FROM
            uid_sequence_key
        WHERE
          `key` = #{key}
    </select>

    <select id="findSequenceKeyById" parameterType="long" resultMap="PersistentKeyMap">
        SELECT
            id, `key`, name, value, step, pattern, expired_on, curdate() AS today, version
        FROM
            uid_sequence_key
        WHERE
            id = #{id}
    </select>

    <select id="lockSequenceKey" parameterType="long" resultMap="PersistentKeyMap">
        SELECT
            id, `key`, name, value, step, pattern, expired_on, curdate() AS today, version
        FROM
            uid_sequence_key
        WHERE
            id = #{id}
        FOR UPDATE
    </select>

    <update id="unlockSequenceKey" parameterType="com.diligrp.assistant.uid.domain.PersistentSequenceKey">
        UPDATE
            uid_sequence_key
        SET
            value = #{value}, expired_on = #{expiredOn}, version = version + 1
        WHERE
            id = #{id}
    </update>
</mapper>