<?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.salpa.subject.mapper.DataSourcePropertyMapper">

    <resultMap type="com.salpa.subject.domain.MonitorDataSourceProperty" id="MonitorDataSourcePropertyResult">
        <id     property="id"            column="id"             />
        <result property="dataSourceId"          column="data_source_id"           />
        <result property="dataSourceKey"   column="data_source_key"    />
        <result property="dataSourceValue"              column="data_source_value"                />
        <result property="createAt"             column="create_at"              />
    </resultMap>

    <select id="selectPropertyBySourceId" resultType="map">
        SELECT data_source_key dataSourceKey,data_source_value dataSourceValue FROM monitor_data_source_property WHERE data_source_id = #{dataSourceId}
    </select>

    <insert id="addDataSourceProperty">
        insert into monitor_data_source_property(
        <if test="dataSourceId != null">data_source_id,</if>
        <if test="dataSourceKey != null and dataSourceKey != ''">data_source_key,</if>
        <if test="dataSourceValue != null and dataSourceValue != ''">data_source_value</if>
        )values(
        <if test="dataSourceId != null">#{dataSourceId},</if>
        <if test="dataSourceKey != null and dataSourceKey != ''">#{dataSourceKey},</if>
        <if test="dataSourceValue != null and dataSourceValue != ''">#{dataSourceValue}</if>
        )
    </insert>

    <update id="updateDataSourceProperty">
        update monitor_data_source_property
        <set>
            <if test="dataSourceId != null">data_source_id = #{dataSourceId},</if>
            <if test="dataSourceKey != null and dataSourceKey != ''">data_source_key = #{dataSourceKey},</if>
            <if test="dataSourceValue != null and dataSourceValue != ''">data_source_value = #{dataSourceValue}</if>
        </set>
        where id = #{id}
    </update>

    <delete id="deleteDataSourceProperty">
        DELETE FROM monitor_data_source_property WHERE data_source_id = #{dataSourceId}
    </delete>
</mapper>