<?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="ClusterDao">
  <resultMap id="ClusterMap" type="com.xiaojukeji.kafka.manager.common.entity.pojo.ClusterDO">
    <id column="id"                       property="id" />
    <id column="status"                   property="status" />
    <result column="gmt_create"           property="gmtCreate" />
    <result column="gmt_modify"           property="gmtModify" />

    <result column="cluster_name"         property="clusterName" />
    <result column="zookeeper"            property="zookeeper" />
    <result column="bootstrap_servers"    property="bootstrapServers" />
    <result column="security_properties"  property="securityProperties" />
    <result column="jmx_properties"       property="jmxProperties" />
  </resultMap>

  <insert id="insert"
          parameterType="com.xiaojukeji.kafka.manager.common.entity.pojo.ClusterDO"
          useGeneratedKeys="true"
          keyProperty="id">
    INSERT INTO cluster (
      cluster_name, zookeeper, bootstrap_servers, security_properties, jmx_properties
    ) VALUES (
      #{clusterName}, #{zookeeper}, #{bootstrapServers}, #{securityProperties}, #{jmxProperties}
    )
  </insert>

  <update id="updateById" parameterType="com.xiaojukeji.kafka.manager.common.entity.pojo.ClusterDO">
    UPDATE cluster SET
      cluster_name=#{clusterName},
      bootstrap_servers=#{bootstrapServers},
      security_properties=#{securityProperties},
      jmx_properties=#{jmxProperties},
      status=#{status}
    WHERE id = #{id}
  </update>

  <select id="getById" parameterType="java.lang.Long" resultMap="ClusterMap">
    SELECT * FROM cluster where id=#{id}
  </select>

  <delete id="deleteById" parameterType="java.lang.Long">
    DELETE FROM cluster where id=#{id}
  </delete>

  <select id="list" resultMap="ClusterMap">
    SELECT * FROM cluster WHERE status = 1
  </select>

  <select id="listAll" resultMap="ClusterMap">
    SELECT * FROM cluster ORDER BY status DESC
  </select>
</mapper>