BusServerMapper.xml 11.8 KB
<?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.sunyo.wlpt.message.bus.service.mapper.BusServerMapper">
    <cache-ref namespace="com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper"/>
    <resultMap id="BaseResultMap" type="com.sunyo.wlpt.message.bus.service.domain.BusServer">
        <!--@mbg.generated-->
        <!--@Table bus_server-->
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="server_name" jdbcType="VARCHAR" property="serverName"/>
        <result column="server_name" jdbcType="VARCHAR" property="aliasName"/>
        <result column="server_ip" jdbcType="VARCHAR" property="serverIp"/>
        <result column="server_port" jdbcType="INTEGER" property="serverPort"/>
        <result column="client_port" jdbcType="INTEGER" property="clientPort"/>
        <result column="super_username" jdbcType="VARCHAR" property="superUsername"/>
        <result column="super_password" jdbcType="VARCHAR" property="superPassword"/>
        <result column="description" jdbcType="VARCHAR" property="description"/>
        <result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>
        <result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>
    </resultMap>

    <!-- 该Mapper映射关系的作用,是服务器与虚拟主机的1:n的关系映射 -->
    <resultMap extends="BaseResultMap" id="ServerAndVirtualHostMap"
               type="com.sunyo.wlpt.message.bus.service.domain.BusServer">
        <collection ofType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost" property="aliasList">
            <id column="vid" jdbcType="VARCHAR" property="id"/>
            <result column="virtual_host_name" jdbcType="VARCHAR" property="virtualHostName"/>
            <result column="virtual_host_name" jdbcType="VARCHAR" property="aliasName"/>
            <result column="server_id" jdbcType="VARCHAR" property="serverId"/>
        </collection>
    </resultMap>
    <!-- 该Mapper映射关系的作用,服务器:虚拟主机—&gt;1:n ; 虚拟主机:交换机—&gt;1:n  的关系映射 -->
    <resultMap extends="BaseResultMap" id="ServerAndHostAndExchangeMap"
               type="com.sunyo.wlpt.message.bus.service.domain.BusServer">
        <collection ofType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost" property="aliasList">
            <id column="vid" jdbcType="VARCHAR" property="id"/>
            <result column="virtual_host_name" jdbcType="VARCHAR" property="virtualHostName"/>
            <result column="virtual_host_name" jdbcType="VARCHAR" property="aliasName"/>
            <collection ofType="com.sunyo.wlpt.message.bus.service.domain.BusExchange" property="aliasList">
                <id column="eid" jdbcType="VARCHAR" property="id"/>
                <result column="exchange_name" jdbcType="VARCHAR" property="exchangeName"/>
                <result column="exchange_name" jdbcType="VARCHAR" property="aliasName"/>
            </collection>
        </collection>
    </resultMap>

  <sql id="Base_Column_List">
      <!--@mbg.generated-->
      id, `server_name`, server_ip, server_port, client_port, super_username, super_password,
    description, gmt_create, gmt_modified
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
      <!--@mbg.generated-->
      select
      <include refid="Base_Column_List"/>
      from bus_server
      where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
      <!--@mbg.generated-->
      delete
      from bus_server
      where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
      <!--@mbg.generated-->
      insert into bus_server (id, `server_name`, server_ip,
                              server_port, client_port, super_username,
                              super_password, description, gmt_create,
                              gmt_modified)
      values (#{id,jdbcType=VARCHAR}, #{serverName,jdbcType=VARCHAR}, #{serverIp,jdbcType=VARCHAR},
              #{serverPort,jdbcType=INTEGER}, #{clientPort,jdbcType=INTEGER}, #{superUsername,jdbcType=VARCHAR},
              #{superPassword,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP},
              #{gmtModified,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
      <!--@mbg.generated-->
      insert into bus_server
      <trim prefix="(" suffix=")" suffixOverrides=",">
          <if test="id != null">
              id,
          </if>
      <if test="serverName != null">
          `server_name`,
      </if>
      <if test="serverIp != null">
          server_ip,
      </if>
      <if test="serverPort != null">
          server_port,
      </if>
      <if test="clientPort != null">
          client_port,
      </if>
      <if test="superUsername != null">
          super_username,
      </if>
      <if test="superPassword != null">
          super_password,
      </if>
      <if test="description != null">
          description,
      </if>
      <if test="gmtCreate != null">
          gmt_create,
      </if>
      <if test="gmtModified != null">
          gmt_modified,
      </if>
      </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
        <if test="id != null">
            #{id,jdbcType=VARCHAR},
        </if>
      <if test="serverName != null">
          #{serverName,jdbcType=VARCHAR},
      </if>
      <if test="serverIp != null">
          #{serverIp,jdbcType=VARCHAR},
      </if>
      <if test="serverPort != null">
          #{serverPort,jdbcType=INTEGER},
      </if>
      <if test="clientPort != null">
          #{clientPort,jdbcType=INTEGER},
      </if>
      <if test="superUsername != null">
          #{superUsername,jdbcType=VARCHAR},
      </if>
      <if test="superPassword != null">
          #{superPassword,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
          #{description,jdbcType=VARCHAR},
      </if>
      <if test="gmtCreate != null">
          #{gmtCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="gmtModified != null">
          #{gmtModified,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
      <!--@mbg.generated-->
      update bus_server
      <set>
          <if test="serverName != null">
              `server_name` = #{serverName,jdbcType=VARCHAR},
          </if>
      <if test="serverIp != null">
          server_ip = #{serverIp,jdbcType=VARCHAR},
      </if>
      <if test="serverPort != null">
          server_port = #{serverPort,jdbcType=INTEGER},
      </if>
      <if test="clientPort != null">
          client_port = #{clientPort,jdbcType=INTEGER},
      </if>
      <if test="superUsername != null">
          super_username = #{superUsername,jdbcType=VARCHAR},
      </if>
      <if test="superPassword != null">
          super_password = #{superPassword,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
          description = #{description,jdbcType=VARCHAR},
      </if>
      <if test="gmtCreate != null">
          gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="gmtModified != null">
          gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
      </if>
      </set>
      where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
      <!--@mbg.generated-->
      update bus_server
      set `server_name`  = #{serverName,jdbcType=VARCHAR},
          server_ip      = #{serverIp,jdbcType=VARCHAR},
          server_port    = #{serverPort,jdbcType=INTEGER},
          client_port    = #{clientPort,jdbcType=INTEGER},
          super_username = #{superUsername,jdbcType=VARCHAR},
          super_password = #{superPassword,jdbcType=VARCHAR},
          description    = #{description,jdbcType=VARCHAR},
          gmt_create     = #{gmtCreate,jdbcType=TIMESTAMP},
          gmt_modified   = #{gmtModified,jdbcType=TIMESTAMP}
      where id = #{id,jdbcType=VARCHAR}
  </update>

    <!-- 获取服务器列表,可能要级联或者懒加载 -->
    <select id="getServerList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from bus_server
    </select>

    <!--  查询服务器和虚拟主机基本信息(id,名称)  -->
    <select id="getServerAndHostList" resultMap="ServerAndVirtualHostMap">
        select s.id,
               s.server_name,
               v.id as vid,
               v.virtual_host_name,
               v.server_id
        from bus_server as s,
             virtual_host as v
        where s.id = v.server_id
    </select>

    <!--  查询服务器和虚拟主机以及虚拟机基本信息(id,名称)  -->
    <select id="getServerAndHostAndExchangeList" resultMap="ServerAndHostAndExchangeMap">
        select s.id,
               s.server_name,
               v.id as vid,
               v.virtual_host_name,
               e.id as eid,
               e.exchange_name
        from bus_server as s,
             virtual_host as v,
             bus_exchange as e
        where s.id = v.server_id
          and v.id = e.virtual_host_id
    </select>

    <!-- 获取服务器列表,分页 -->
    <select id="selectBusServerList" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer"
            resultMap="BaseResultMap">
        select id,
               `server_name`,
               server_ip,
               server_port,
               client_port,
               super_username,
               description,
               gmt_create,
               gmt_modified
        from bus_server
        <where>
            <!-- 服务器名称 -->
            <if test="serverName != null and serverName != ''">
                server_name = #{serverName,jdbcType=VARCHAR}
            </if>
        </where>
    </select>

    <!-- 首先。校验服务器名称,是否存在 -->
    <select id="validateServerName" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from bus_server
        <where>
            <!-- 服务器名称 -->
            <if test="serverName != null and serverName != ''">
                server_name = #{serverName,jdbcType=VARCHAR}
            </if>
        </where>
    </select>

    <!-- 再校验服务器信息(服务器的ip,服务器的port)是否同时存在 -->
    <select id="validateBusServer" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from bus_server
        <where>
            <!-- 服务器的ip -->
            <if test="serverIp != null and serverIp != ''">
                server_ip = #{serverIp,jdbcType=VARCHAR}
            </if>
            <!-- 服务器的port -->
            <if test="serverPort != null and serverPort != ''">
                AND server_port = #{serverPort,jdbcType=INTEGER}
            </if>
        </where>
    </select>

    <select id="selectByServerName" parameterType="java.lang.String" resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List"/>
        from bus_server
        where server_name = #{serverName,jdbcType=VARCHAR}
    </select>

    <select id="selectServerExist" parameterType="java.lang.String" resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List"/>
        from bus_server
        where server_name = #{serverName,jdbcType=VARCHAR}
    </select>
</mapper>