<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * @version 0.0.1
 * @since 0.0.1
 * @author Auto Generated <br />
 * Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br />
 * Apr 11, 2015 11:12:10 AM
 */
-->
<!DOCTYPE mapper PUBLIC
	"-//mybatis.org//DTD Mapper 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.com.flaginfo.echat.mappers.TableTestMapper">

	<resultMap id="modelMap" type="TableTest">
		<id column="id" property="id" />
		<id column="name" property="name" />
		<result column="date_created" property="dateCreated" />
		<result column="date_updated" property="dateUpdated" />
		<result column="type" property="type" />
	</resultMap>

    <!-- variables -->
	<sql id="columns">
	   id, name, date_created, date_updated
	</sql>
	<sql id="table">
	   table_test
	</sql>
	<sql id="updateClause">
        update <include refid="table" />
        <set>
        <if test="model.name != null">
            name = #{model.name}
        </if>
        </set>
	</sql>
    <!-- /variables -->

    <!-- methods -->
    <!-- Insert Models -->
	<insert id="insert">
        insert into <include refid="table" />
        (<include refid="columns" />) values
        <foreach item="model" collection="models" separator=", ">
            (#{model.id}, #{model.name}, #{model.dateCreated}, #{model.dateUpdated})
        </foreach>
	</insert>

    <!-- Update By Key -->
	<update id="update">
        <foreach item="model" collection="models" separator="; ">
            <include refid="updateClause" />
        where id = #{model.id}
        </foreach>
	</update>

    <!-- Update By Condition -->
	<update id="updateBy">
        <bind name="key" value="'id'" />
        <include refid="updateClause" />
		<include refid="Commons.search" />
	</update>

    <!-- Delete -->
	<delete id="delete">
        <bind name="key" value="'id'" />
		delete from <include refid="table" />
		<include refid="Commons.search" />
	</delete>

    <!-- Find One -->
	<select id="find" resultMap="modelMap">
        <bind name="key" value="'id'" />
        <include refid="Commons.selectAllFromTable" />
		<include refid="Commons.search" />
	</select>

    <!-- List -->
	<select id="list" resultMap="modelMap">
        <bind name="key" value="'id'" />
		<include refid="Commons.selectAllFromTable" />
		<include refid="Commons.search" />
	</select>

    <!-- List Page All -->
	<select id="listPage" resultMap="modelMap">
		<!-- Default List All -->
		<include refid="Commons.selectAllFromTable" />
	</select>

    <!-- List Page By Condition -->
	<select id="listPageBy" resultMap="modelMap">
		<include refid="Commons.selectAllFromTable" />
		<include refid="Commons.search" />
		<!-- TODO: Your Query Logics Are Here, For Example: -->
        <!-- <if test="s != null"> -->
        <!-- where name like #{s} -->
        <!-- </if> -->
	</select>
    <!-- /methods -->
</mapper>
