<?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="org.diagbot.mapper.KnowledgeMapper">
  <resultMap id="BaseResultMap" type="org.diagbot.entity.node.base.BaseNode">
    <id column="id" jdbcType="BIGINT" property="nodeId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
  </resultMap>
  <select id="findNodebyName" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--MATCH (n:Movie) return id(n) as id, n.title as title, n.released as released limit 25-->
    <!--MATCH (n) WHERE n.name =~ '.*#{name}.*' RETURN id(n) as id, n.name as name-->
  </select>

  <update id="updateRelation" parameterType="org.diagbot.vo.AmendRelationVo">
    MATCH (s
    <if test = "old_start_type != ''">
      :#{old_start_type}
    </if>
    <if test = "old_start_name != ''">
      {name:{#{old_start_name}}
    </if>
    -[r:#{old_rel_name}]->(e
    <if test = "old_end_type != ''">
      :#{old_end_type}
    </if>
    <if test = "old_end_name != ''">
      {name:{#{old_end_name}}
    </if>
    ),
    (e1
    <if test = "new_end_type != ''">
      :#{new_end_type}
    </if>
    <if test = "new_end_name != ''">
      {name:{#{new_end_name}}
    </if>
    ) create (s)-[r1:#{new_rel_name}]->(e1) set r1=r with r delete r
  </update>
</mapper>