<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.hswebframework.web.dao.form.DynamicFormDao">
    <resultMap id="DynamicFormResultMap" type="org.hswebframework.web.entity.form.DynamicFormEntity">
        <id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
        <result property="name" column="name" javaType="String" jdbcType="VARCHAR"/>
        <result property="databaseTableName" column="t_name" javaType="String" jdbcType="VARCHAR"/>
        <result property="describe" column="describe" javaType="String" jdbcType="VARCHAR"/>
        <result property="version" column="version" javaType="Long" jdbcType="DECIMAL"/>
        <result property="creatorId" column="creator_id" javaType="String" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" javaType="Long" jdbcType="DECIMAL"/>
        <result property="updateTime" column="update_time" javaType="Long" jdbcType="DECIMAL"/>
        <result property="deployed" column="is_deployed" javaType="Boolean" jdbcType="DECIMAL"/>
        <result property="alias" column="alias" javaType="String" jdbcType="VARCHAR"/>
        <result property="triggers" column="triggers" javaType="String" jdbcType="CLOB"/>
        <result property="correlations" column="correlations" javaType="String" jdbcType="CLOB"/>
        <result property="dataSourceId" column="data_source_id" javaType="String" jdbcType="VARCHAR"/>
        <result property="properties" column="properties" javaType="java.util.Map" jdbcType="CLOB"/>
        <result property="type" column="type" javaType="String" jdbcType="VARCHAR"/>
    </resultMap>

    <!--用于动态生成sql所需的配置-->
    <sql id="config">
        <bind name="resultMapId" value="'DynamicFormResultMap'"/>
        <bind name="tableName" value="'s_dyn_form'"/>
    </sql>

    <insert id="insert" parameterType="org.hswebframework.web.entity.form.DynamicFormEntity">
        <include refid="config"/>
        <include refid="BasicMapper.buildInsertSql"/>
    </insert>

    <delete id="deleteByPk" parameterType="String">
        delete from s_dyn_form where u_id =#{id}
    </delete>

    <delete id="delete" parameterType="org.hswebframework.web.commons.entity.Entity">
        <include refid="config"/>
        <include refid="BasicMapper.buildDeleteSql"/>
    </delete>

    <update id="update" parameterType="org.hswebframework.web.commons.entity.Entity">
        <include refid="config"/>
        <include refid="BasicMapper.buildUpdateSql"/>
    </update>

    <update id="incrementVersion" parameterType="String">
        update s_dyn_form set version=version+1 where u_id = #{id}
    </update>

    <select id="query" parameterType="org.hswebframework.web.commons.entity.Entity" resultMap="DynamicFormResultMap">
        <include refid="config"/>
        <include refid="BasicMapper.buildSelectSql"/>
    </select>

    <select id="count" parameterType="org.hswebframework.web.commons.entity.Entity" resultType="int">
        <include refid="config"/>
        <include refid="BasicMapper.buildTotalSql"/>
    </select>
</mapper>
