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

mybatis.contract.ContractStateMapper.xml Maven / Gradle / Ivy

The newest version!
<?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.higgschain.trust.slave.dao.mysql.contract.ContractStateDao">
    <!-- Result Map -->
    <resultMap id="baseResultMap" type="com.higgschain.trust.slave.dao.po.contract.ContractStatePO">
        <result column="id" property="id"/>
        <result column="address" property="address"/>
        <result column="state" property="state" />
        <result column="key_desc" property="keyDesc" />
    </resultMap>

    <!-- contract table all fields -->
    <sql id="baseColumnList">
        id,address,update_time,state,key_desc
    </sql>

    <!-- batch insert -->
    <insert id ="batchInsert" parameterType="java.util.Collection" >
        INSERT INTO contract_state (address, update_time, state,key_desc)
        VALUES
        <foreach collection ="list" item="item" index= "index" separator =",">
            (#{item.address}, now(3), #{item.state},#{item.keyDesc})
        </foreach>
    </insert>

    <!-- batch update -->
    <update id="batchUpdate" parameterType="java.util.Collection">
        UPDATE contract_state
        <trim prefix="SET" suffixOverrides=",">
            <trim prefix="`state` = CASE" suffix="END,">
                <foreach collection="list" item="item">
                    WHEN `address` = #{item.address}
                    THEN #{item.state}
                </foreach>
                ELSE `state`
            </trim>
            <trim prefix="`update_time` = CASE" suffix="END">
                <foreach collection="list" item="item">
                    WHEN `address` = #{item.address}
                    THEN now(3)
                </foreach>
                ELSE `update_time`
            </trim>
        </trim>
        <where>
            <foreach collection="list" item="item" separator="or" open="(" close=")">
                `address` = #{item.address}
            </foreach>
        </where>
    </update>

    <!-- add -->
    <insert id="add" parameterType="com.higgschain.trust.slave.dao.po.contract.ContractStatePO">
        INSERT INTO contract_state (address, update_time, state,key_desc)
        VALUES (#{address}, now(3), #{state},#{keyDesc})
    </insert>

    <insert id="save"  parameterType="com.higgschain.trust.slave.dao.po.contract.ContractStatePO">
        INSERT INTO contract_state (address, update_time, state,key_desc) VALUES (#{address}, now(3), #{state},#{keyDesc})
        ON DUPLICATE KEY UPDATE state=#{state}
    </insert>

    <!-- delete -->
    <delete id="deleteByAddress" parameterType="java.lang.String">
        DELETE FROM contract_state WHERE address=#{address}
    </delete>

    <!-- query by contract address -->
    <select id="queryByAddress" resultMap="baseResultMap" parameterType="java.lang.String">
        SELECT
        <include refid="baseColumnList"/>
        FROM contract_state WHERE address=#{address}
    </select>

</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy