<?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.xxl.job.admin.dao.XxlJobRegistryDao">
	
	<resultMap id="XxlJobRegistry" type="com.xxl.job.admin.core.model.XxlJobRegistry" >
		<result column="id" property="id" />
	    <result column="registry_group" property="registryGroup" />
	    <result column="registry_key" property="registryKey" />
	    <result column="registry_value" property="registryValue" />
		<result column="update_time" property="updateTime" />
	</resultMap>

	<sql id="Base_Column_List">
		t.id,
		t.registry_group,
		t.registry_key,
		t.registry_value,
		t.update_time
	</sql>
	
	<delete id="removeDead" parameterType="java.lang.Integer" >
		DELETE FROM XXL_JOB_QRTZ_TRIGGER_REGISTRY
		WHERE update_time <![CDATA[ < ]]> DATE_ADD(NOW(),INTERVAL -#{timeout} SECOND)
	</delete>

	<select id="findAll" parameterType="java.lang.Integer" resultMap="XxlJobRegistry">
		SELECT <include refid="Base_Column_List" />
		FROM XXL_JOB_QRTZ_TRIGGER_REGISTRY AS t
		WHERE t.update_time <![CDATA[ > ]]> DATE_ADD(NOW(),INTERVAL -#{timeout} SECOND)
	</select>

    <update id="registryUpdate" >
        UPDATE XXL_JOB_QRTZ_TRIGGER_REGISTRY
        SET `update_time` = NOW()
        WHERE `registry_group` = #{registryGroup}
          AND `registry_key` = #{registryKey}
          AND `registry_value` = #{registryValue}
    </update>

    <insert id="registrySave" >
        INSERT INTO XXL_JOB_QRTZ_TRIGGER_REGISTRY( `registry_group` , `registry_key` , `registry_value`, `update_time`)
        VALUES( #{registryGroup}  , #{registryKey} , #{registryValue}, NOW())
    </insert>

	<delete id="registryDelete" >
		DELETE FROM XXL_JOB_QRTZ_TRIGGER_REGISTRY
		WHERE registry_group = #{registryGroup}
			AND registry_key = #{registryKey}
			AND registry_value = #{registryValue}
	</delete>

</mapper>