<?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.MaterializationDOMapper">
  <resultMap id="BaseResultMap" type="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="materialized_type" jdbcType="VARCHAR" property="materializedType" />
    <result column="update_cycle" jdbcType="VARCHAR" property="updateCycle" />
    <result column="model_id" jdbcType="BIGINT" property="modelId" />
    <result column="database_id" jdbcType="BIGINT" property="databaseId" />
    <result column="level" jdbcType="INTEGER" property="level" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="destination_table" jdbcType="VARCHAR" property="destinationTable" />
    <result column="principals" jdbcType="VARCHAR" property="principals" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDOWithBLOBs">
    <result column="date_info" jdbcType="LONGVARCHAR" property="dateInfo" />
    <result column="entities" jdbcType="LONGVARCHAR" property="entities" />
    <result column="description" jdbcType="LONGVARCHAR" property="description" />
  </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, name, materialized_type, update_cycle, model_id, database_id, level, status, 
    destination_table, principals, created_at, created_by, updated_at, updated_by
  </sql>
  <sql id="Blob_Column_List">
    date_info, entities, description
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDOExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from s2_materialization
    <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.MaterializationDOExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from s2_materialization
    <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
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from s2_materialization
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDOWithBLOBs">
    insert into s2_materialization (id, name, materialized_type, 
      update_cycle, model_id, database_id, 
      level, status, destination_table, 
      principals, created_at, created_by, 
      updated_at, updated_by, date_info, 
      entities, description)
    values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{materializedType,jdbcType=VARCHAR}, 
      #{updateCycle,jdbcType=VARCHAR}, #{modelId,jdbcType=BIGINT}, #{databaseId,jdbcType=BIGINT}, 
      #{level,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{destinationTable,jdbcType=VARCHAR}, 
      #{principals,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=VARCHAR}, 
      #{updatedAt,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR}, #{dateInfo,jdbcType=LONGVARCHAR}, 
      #{entities,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR})
  </insert>

  <insert id="insertSelective" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDOWithBLOBs">
    insert into s2_materialization
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="materializedType != null">
        materialized_type,
      </if>
      <if test="updateCycle != null">
        update_cycle,
      </if>
      <if test="modelId != null">
        model_id,
      </if>
      <if test="databaseId != null">
        database_id,
      </if>
      <if test="level != null">
        level,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="destinationTable != null">
        destination_table,
      </if>
      <if test="principals != null">
        principals,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="updatedAt != null">
        updated_at,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
      <if test="dateInfo != null">
        date_info,
      </if>
      <if test="entities != null">
        entities,
      </if>
      <if test="description != null">
        description,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="materializedType != null">
        #{materializedType,jdbcType=VARCHAR},
      </if>
      <if test="updateCycle != null">
        #{updateCycle,jdbcType=VARCHAR},
      </if>
      <if test="modelId != null">
        #{modelId,jdbcType=BIGINT},
      </if>
      <if test="databaseId != null">
        #{databaseId,jdbcType=BIGINT},
      </if>
      <if test="level != null">
        #{level,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="destinationTable != null">
        #{destinationTable,jdbcType=VARCHAR},
      </if>
      <if test="principals != null">
        #{principals,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedAt != null">
        #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="dateInfo != null">
        #{dateInfo,jdbcType=LONGVARCHAR},
      </if>
      <if test="entities != null">
        #{entities,jdbcType=LONGVARCHAR},
      </if>
      <if test="description != null">
        #{description,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDOExample" resultType="java.lang.Long">
    select count(*) from s2_materialization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDOWithBLOBs">
    update s2_materialization
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="materializedType != null">
        materialized_type = #{materializedType,jdbcType=VARCHAR},
      </if>
      <if test="updateCycle != null">
        update_cycle = #{updateCycle,jdbcType=VARCHAR},
      </if>
      <if test="modelId != null">
        model_id = #{modelId,jdbcType=BIGINT},
      </if>
      <if test="databaseId != null">
        database_id = #{databaseId,jdbcType=BIGINT},
      </if>
      <if test="level != null">
        level = #{level,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="destinationTable != null">
        destination_table = #{destinationTable,jdbcType=VARCHAR},
      </if>
      <if test="principals != null">
        principals = #{principals,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedAt != null">
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="dateInfo != null">
        date_info = #{dateInfo,jdbcType=LONGVARCHAR},
      </if>
      <if test="entities != null">
        entities = #{entities,jdbcType=LONGVARCHAR},
      </if>
      <if test="description != null">
        description = #{description,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDOWithBLOBs">
    update s2_materialization
    set name = #{name,jdbcType=VARCHAR},
      materialized_type = #{materializedType,jdbcType=VARCHAR},
      update_cycle = #{updateCycle,jdbcType=VARCHAR},
      model_id = #{modelId,jdbcType=BIGINT},
      database_id = #{databaseId,jdbcType=BIGINT},
      level = #{level,jdbcType=INTEGER},
      status = #{status,jdbcType=INTEGER},
      destination_table = #{destinationTable,jdbcType=VARCHAR},
      principals = #{principals,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      date_info = #{dateInfo,jdbcType=LONGVARCHAR},
      entities = #{entities,jdbcType=LONGVARCHAR},
      description = #{description,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.tencent.supersonic.semantic.materialization.domain.dataobject.MaterializationDO">
    update s2_materialization
    set name = #{name,jdbcType=VARCHAR},
      materialized_type = #{materializedType,jdbcType=VARCHAR},
      update_cycle = #{updateCycle,jdbcType=VARCHAR},
      model_id = #{modelId,jdbcType=BIGINT},
      database_id = #{databaseId,jdbcType=BIGINT},
      level = #{level,jdbcType=INTEGER},
      status = #{status,jdbcType=INTEGER},
      destination_table = #{destinationTable,jdbcType=VARCHAR},
      principals = #{principals,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>