<?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="kohgylw.kiftd.server.mapper.NodeMapper">
	<resultMap id="BaseResultMap" type="kohgylw.kiftd.server.model.Node">
		<result column="file_id" jdbcType="VARCHAR" property="fileId" />
		<result column="file_name" jdbcType="VARCHAR" property="fileName" />
		<result column="file_size" jdbcType="VARCHAR" property="fileSize" />
		<result column="file_parent_folder" jdbcType="VARCHAR"
			property="fileParentFolder" />
		<result column="file_creation_date" jdbcType="VARCHAR"
			property="fileCreationDate" />
		<result column="file_creator" jdbcType="VARCHAR" property="fileCreator" />
		<result column="file_path" jdbcType="VARCHAR" property="filePath" />
	</resultMap>

	<select id="queryByParentFolderId" parameterType="java.lang.String"
		resultMap="BaseResultMap">
		SELECT * FROM FILE WHERE file_parent_folder =
		#{pfid,jdbcType=VARCHAR}
	</select>

	<insert id="insert" parameterType="kohgylw.kiftd.server.model.Node">
		INSERT INTO FILE
		VALUES(#{fileId,jdbcType=VARCHAR},#{fileName,jdbcType=VARCHAR},#{fileSize,jdbcType=VARCHAR},#{fileParentFolder,jdbcType=VARCHAR},#{fileCreationDate,jdbcType=VARCHAR},#{fileCreator,jdbcType=VARCHAR},#{filePath,jdbcType=VARCHAR})
	</insert>

	<update id="update" parameterType="kohgylw.kiftd.server.model.Node">
		UPDATE FILE SET file_name =
		#{fileName,jdbcType=VARCHAR},file_size =
		#{fileSize,jdbcType=VARCHAR},file_parent_folder =
		#{fileParentFolder,jdbcType=VARCHAR},file_creation_date =
		#{fileCreationDate,jdbcType=VARCHAR},file_creator =
		#{fileCreator,jdbcType=VARCHAR},file_path =
		#{filePath,jdbcType=VARCHAR} WHERE file_id =
		#{fileId,jdbcType=VARCHAR}
	</update>

	<delete id="deleteByParentFolderId" parameterType="java.lang.String">
		DELETE FROM
		FILE WHERE file_parent_folder = #{pfid,jdbcType=VARCHAR}
	</delete>

	<delete id="deleteById" parameterType="java.lang.String">
		DELETE FROM FILE WHERE
		file_id = #{fileId,jdbcType=VARCHAR}
	</delete>

	<select id="queryById" parameterType="java.lang.String"
		resultMap="BaseResultMap">
		SELECT * FROM FILE WHERE file_id =
		#{fileId,jdbcType=VARCHAR}
	</select>

	<update id="updateFileNameById" parameterType="java.util.Map">
		UPDATE FILE SET
		file_name = #{newFileName,jdbcType=VARCHAR} WHERE file_id =
		#{fileId,jdbcType=VARCHAR}
	</update>

	<select id="queryAll" resultMap="BaseResultMap">
		SELECT * FROM FILE
	</select>

	<select id="queryByPath" parameterType="java.lang.String"
		resultMap="BaseResultMap">
		SELECT * FROM FILE WHERE file_path =
		#{path,jdbcType=VARCHAR}
	</select>

	<select id="queryBySomeFolder" parameterType="java.lang.String"
		resultMap="BaseResultMap">
		SELECT * FROM FILE WHERE file_parent_folder in (SELECT
		file_parent_folder
		FROM FILE WHERE file_id =
		#{fileId,jdbcType=VARCHAR})
	</select>

	<update id="moveById" parameterType="java.util.Map">
		UPDATE FILE SET
		file_parent_folder = #{locationpath,jdbcType=VARCHAR} WHERE file_id =
		#{fileId,jdbcType=VARCHAR}
	</update>

</mapper>