<?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="cn.superdesk.uniorder.dao.mapper.kafka.KafkaConsumerRecordOffsetMapper">
  <resultMap id="BaseResultMap" type="cn.superdesk.uniorder.dao.entity.kafka.KafkaConsumerRecordOffset">

    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="topic" jdbcType="VARCHAR" property="topic" />
    <result column="group_id" jdbcType="VARCHAR" property="groupId" />
    <result column="partitions" jdbcType="INTEGER" property="partitions" />
    <result column="offset_from" jdbcType="BIGINT" property="offsetFrom" />
    <result column="offset_until" jdbcType="BIGINT" property="offsetUntil" />
  </resultMap>
  <sql id="Example_Where_Clause">

    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">

    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">

    id, topic, group_id, partitions, offset_from, offset_until
  </sql>
  <select id="selectByExample" parameterType="cn.superdesk.uniorder.dao.entity.kafka.KafkaConsumerRecordOffsetExample" resultMap="BaseResultMap">

    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from ims_kafka_consumer_record_offset
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">

    select 
    <include refid="Base_Column_List" />
    from ims_kafka_consumer_record_offset
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">

    delete from ims_kafka_consumer_record_offset
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="cn.superdesk.uniorder.dao.entity.kafka.KafkaConsumerRecordOffsetExample">

    delete from ims_kafka_consumer_record_offset
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="cn.superdesk.uniorder.dao.entity.kafka.KafkaConsumerRecordOffset">

    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into ims_kafka_consumer_record_offset (topic, group_id, partitions, 
      offset_from, offset_until)
    values (#{topic,jdbcType=VARCHAR}, #{groupId,jdbcType=VARCHAR}, #{partitions,jdbcType=INTEGER}, 
      #{offsetFrom,jdbcType=BIGINT}, #{offsetUntil,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" parameterType="cn.superdesk.uniorder.dao.entity.kafka.KafkaConsumerRecordOffset">

    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into ims_kafka_consumer_record_offset
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="topic != null">
        topic,
      </if>
      <if test="groupId != null">
        group_id,
      </if>
      <if test="partitions != null">
        partitions,
      </if>
      <if test="offsetFrom != null">
        offset_from,
      </if>
      <if test="offsetUntil != null">
        offset_until,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="topic != null">
        #{topic,jdbcType=VARCHAR},
      </if>
      <if test="groupId != null">
        #{groupId,jdbcType=VARCHAR},
      </if>
      <if test="partitions != null">
        #{partitions,jdbcType=INTEGER},
      </if>
      <if test="offsetFrom != null">
        #{offsetFrom,jdbcType=BIGINT},
      </if>
      <if test="offsetUntil != null">
        #{offsetUntil,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="cn.superdesk.uniorder.dao.entity.kafka.KafkaConsumerRecordOffsetExample" resultType="java.lang.Long">

    select count(*) from ims_kafka_consumer_record_offset
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">

    update ims_kafka_consumer_record_offset
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.topic != null">
        topic = #{record.topic,jdbcType=VARCHAR},
      </if>
      <if test="record.groupId != null">
        group_id = #{record.groupId,jdbcType=VARCHAR},
      </if>
      <if test="record.partitions != null">
        partitions = #{record.partitions,jdbcType=INTEGER},
      </if>
      <if test="record.offsetFrom != null">
        offset_from = #{record.offsetFrom,jdbcType=BIGINT},
      </if>
      <if test="record.offsetUntil != null">
        offset_until = #{record.offsetUntil,jdbcType=BIGINT},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">

    update ims_kafka_consumer_record_offset
    set id = #{record.id,jdbcType=BIGINT},
      topic = #{record.topic,jdbcType=VARCHAR},
      group_id = #{record.groupId,jdbcType=VARCHAR},
      partitions = #{record.partitions,jdbcType=INTEGER},
      offset_from = #{record.offsetFrom,jdbcType=BIGINT},
      offset_until = #{record.offsetUntil,jdbcType=BIGINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="cn.superdesk.uniorder.dao.entity.kafka.KafkaConsumerRecordOffset">

    update ims_kafka_consumer_record_offset
    <set>
      <if test="topic != null">
        topic = #{topic,jdbcType=VARCHAR},
      </if>
      <if test="groupId != null">
        group_id = #{groupId,jdbcType=VARCHAR},
      </if>
      <if test="partitions != null">
        partitions = #{partitions,jdbcType=INTEGER},
      </if>
      <if test="offsetFrom != null">
        offset_from = #{offsetFrom,jdbcType=BIGINT},
      </if>
      <if test="offsetUntil != null">
        offset_until = #{offsetUntil,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.superdesk.uniorder.dao.entity.kafka.KafkaConsumerRecordOffset">

    update ims_kafka_consumer_record_offset
    set topic = #{topic,jdbcType=VARCHAR},
      group_id = #{groupId,jdbcType=VARCHAR},
      partitions = #{partitions,jdbcType=INTEGER},
      offset_from = #{offsetFrom,jdbcType=BIGINT},
      offset_until = #{offsetUntil,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>