<?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.tencent.supersonic.semantic.materialization.infrastructure.mapper.MaterializationRecordDOMapper">
  <resultMap id="BaseResultMap" type="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="materialization_id" jdbcType="BIGINT" property="materializationId" />
    <result column="element_type" jdbcType="VARCHAR" property="elementType" />
    <result column="element_id" jdbcType="BIGINT" property="elementId" />
    <result column="element_name" jdbcType="VARCHAR" property="elementName" />
    <result column="data_time" jdbcType="VARCHAR" property="dataTime" />
    <result column="state" jdbcType="VARCHAR" property="state" />
    <result column="task_id" jdbcType="VARCHAR" property="taskId" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
    <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
    <result column="retry_count" jdbcType="BIGINT" property="retryCount" />
    <result column="source_count" jdbcType="BIGINT" property="sourceCount" />
    <result column="sink_count" jdbcType="BIGINT" property="sinkCount" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDO">
    <result column="message" jdbcType="LONGVARCHAR" property="message" />
  </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="Base_Column_List">
    id, materialization_id, element_type, element_id, element_name, data_time, state, 
    task_id, created_at, updated_at, created_by, updated_by, retry_count, source_count, 
    sink_count
  </sql>
  <sql id="Blob_Column_List">
    message
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDOExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from s2_materialization_record
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDOExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from s2_materialization_record
    <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="ResultMapWithBLOBs">
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from s2_materialization_record
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from s2_materialization_record
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDO">
    insert into s2_materialization_record (id, materialization_id, element_type, 
      element_id, element_name, data_time, 
      state, task_id, created_at, 
      updated_at, created_by, updated_by, 
      retry_count, source_count, sink_count, 
      message)
    values (#{id,jdbcType=BIGINT}, #{materializationId,jdbcType=BIGINT}, #{elementType,jdbcType=VARCHAR}, 
      #{elementId,jdbcType=BIGINT}, #{elementName,jdbcType=VARCHAR}, #{dataTime,jdbcType=VARCHAR}, 
      #{state,jdbcType=VARCHAR}, #{taskId,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, 
      #{updatedAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=VARCHAR}, #{updatedBy,jdbcType=VARCHAR}, 
      #{retryCount,jdbcType=BIGINT}, #{sourceCount,jdbcType=BIGINT}, #{sinkCount,jdbcType=BIGINT}, 
      #{message,jdbcType=LONGVARCHAR})
    ON DUPLICATE KEY UPDATE
      updated_at = #{updatedAt}, retry_count = retry_count + 1
  </insert>
  <insert id="insertSelective" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDO">
    insert into s2_materialization_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="materializationId != null">
        materialization_id,
      </if>
      <if test="elementType != null">
        element_type,
      </if>
      <if test="elementId != null">
        element_id,
      </if>
      <if test="elementName != null">
        element_name,
      </if>
      <if test="dataTime != null">
        data_time,
      </if>
      <if test="state != null">
        state,
      </if>
      <if test="taskId != null">
        task_id,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="updatedAt != null">
        updated_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
      <if test="retryCount != null">
        retry_count,
      </if>
      <if test="sourceCount != null">
        source_count,
      </if>
      <if test="sinkCount != null">
        sink_count,
      </if>
      <if test="message != null">
        message,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="materializationId != null">
        #{materializationId,jdbcType=BIGINT},
      </if>
      <if test="elementType != null">
        #{elementType,jdbcType=VARCHAR},
      </if>
      <if test="elementId != null">
        #{elementId,jdbcType=BIGINT},
      </if>
      <if test="elementName != null">
        #{elementName,jdbcType=VARCHAR},
      </if>
      <if test="dataTime != null">
        #{dataTime,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        #{state,jdbcType=VARCHAR},
      </if>
      <if test="taskId != null">
        #{taskId,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedAt != null">
        #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedBy != null">
        #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="retryCount != null">
        #{retryCount,jdbcType=BIGINT},
      </if>
      <if test="sourceCount != null">
        #{sourceCount,jdbcType=BIGINT},
      </if>
      <if test="sinkCount != null">
        #{sinkCount,jdbcType=BIGINT},
      </if>
      <if test="message != null">
        #{message,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDOExample" resultType="java.lang.Long">
    select count(*) from s2_materialization_record
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDO">
    update s2_materialization_record
    <set>
      <if test="materializationId != null">
        materialization_id = #{materializationId,jdbcType=BIGINT},
      </if>
      <if test="elementType != null">
        element_type = #{elementType,jdbcType=VARCHAR},
      </if>
      <if test="elementId != null">
        element_id = #{elementId,jdbcType=BIGINT},
      </if>
      <if test="elementName != null">
        element_name = #{elementName,jdbcType=VARCHAR},
      </if>
      <if test="dataTime != null">
        data_time = #{dataTime,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        state = #{state,jdbcType=VARCHAR},
      </if>
      <if test="taskId != null">
        task_id = #{taskId,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedAt != null">
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="retryCount != null">
        retry_count = #{retryCount,jdbcType=BIGINT},
      </if>
      <if test="sourceCount != null">
        source_count = #{sourceCount,jdbcType=BIGINT},
      </if>
      <if test="sinkCount != null">
        sink_count = #{sinkCount,jdbcType=BIGINT},
      </if>
      <if test="message != null">
        message = #{message,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDO">
    update s2_materialization_record
    set materialization_id = #{materializationId,jdbcType=BIGINT},
      element_type = #{elementType,jdbcType=VARCHAR},
      element_id = #{elementId,jdbcType=BIGINT},
      element_name = #{elementName,jdbcType=VARCHAR},
      data_time = #{dataTime,jdbcType=VARCHAR},
      state = #{state,jdbcType=VARCHAR},
      task_id = #{taskId,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      retry_count = #{retryCount,jdbcType=BIGINT},
      source_count = #{sourceCount,jdbcType=BIGINT},
      sink_count = #{sinkCount,jdbcType=BIGINT},
      message = #{message,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <update id="updateByBizName"  parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDO">
    update s2_materialization_record
    set
      element_id = #{elementId,jdbcType=BIGINT},
      state = #{state,jdbcType=VARCHAR},
      task_id = #{taskId,jdbcType=VARCHAR},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      retry_count = #{retryCount,jdbcType=BIGINT},
      source_count = #{sourceCount,jdbcType=BIGINT},
      sink_count = #{sinkCount,jdbcType=BIGINT},
      message = #{message,jdbcType=LONGVARCHAR}
    where
     materialization_id = #{materializationId}
     AND element_type = #{elementType}
     AND element_name = #{elementName}
     AND data_time = #{dataTime}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationRecordDO">
    update s2_materialization_record
    set materialization_id = #{materializationId,jdbcType=BIGINT},
      element_type = #{elementType,jdbcType=VARCHAR},
      element_id = #{elementId,jdbcType=BIGINT},
      element_name = #{elementName,jdbcType=VARCHAR},
      data_time = #{dataTime,jdbcType=VARCHAR},
      state = #{state,jdbcType=VARCHAR},
      task_id = #{taskId,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      retry_count = #{retryCount,jdbcType=BIGINT},
      source_count = #{sourceCount,jdbcType=BIGINT},
      sink_count = #{sinkCount,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>