<?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.aizuda.easy.retry.server.persistence.mybatis.mapper.ServerNodeMapper">
  <resultMap id="BaseResultMap" type="com.aizuda.easy.retry.server.persistence.mybatis.po.ServerNode">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="group_name" jdbcType="VARCHAR" property="groupName" />
    <result column="host_id" jdbcType="VARCHAR" property="hostId" />
    <result column="host_ip" jdbcType="VARCHAR" property="hostIp" />
    <result column="host_port" jdbcType="INTEGER" property="hostPort" />
    <result column="expire_at" jdbcType="TIMESTAMP" property="expireAt" />
    <result column="node_type" jdbcType="TINYINT" property="nodeType" />
    <result column="context_path" jdbcType="VARCHAR" property="contextPath" />
    <result column="create_dt" jdbcType="TIMESTAMP" property="createDt" />
    <result column="update_dt" jdbcType="TIMESTAMP" property="updateDt" />
  </resultMap>
  <sql id="Base_Column_List">
    id, group_name, context_path, host_id, host_ip, host_port, expire_at, node_type,create_dt,update_dt
  </sql>
  <insert id="insertOrUpdate" parameterType="com.aizuda.easy.retry.server.persistence.mybatis.po.ServerNode" useGeneratedKeys="true" keyProperty="id">
    insert into server_node (id, group_name, host_id, host_ip, host_port,
                             expire_at, node_type, context_path, create_dt)
    values (#{id,jdbcType=BIGINT}, #{groupName,jdbcType=VARCHAR}, #{hostId,jdbcType=VARCHAR}, #{hostIp,jdbcType=VARCHAR},
            #{hostPort,jdbcType=INTEGER},
            #{expireAt,jdbcType=TIMESTAMP}, #{nodeType,jdbcType=TINYINT},  #{contextPath,jdbcType=VARCHAR},  #{createDt,jdbcType=TIMESTAMP}
            ) ON DUPLICATE KEY UPDATE
      expire_at = values(`expire_at`)
  </insert>
  <delete id="deleteByExpireAt">
    delete from server_node
    where expire_at &lt;= #{endTime,jdbcType=TIMESTAMP}
  </delete>
</mapper>
