<?xml version="1.0" encoding="UTF-8"?>
<!--

       Copyright ${license.git.copyrightYears} the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.

-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.apache.ibatis.submitted.xml_external_ref.SameIdPersonMapper">
	<cache-ref namespace="org.apache.ibatis.submitted.xml_external_ref.SameIdPetMapper" />
	<resultMap type="org.apache.ibatis.submitted.xml_external_ref.Person"
		id="personResult">
		<id property="id" column="person_id" />
		<result property="name" column="person_name" />
	</resultMap>
	<resultMap type="org.apache.ibatis.submitted.xml_external_ref.Person"
		id="resultWithPets" extends="personResult">
		<collection property="pets"
			ofType="org.apache.ibatis.submitted.xml_external_ref.Pet"
			resultMap="org.apache.ibatis.submitted.xml_external_ref.SameIdPetMapper.petResult" />
	</resultMap>
	<sql id="columns">
		person_id, person_name
	</sql>
	<!-- Referencing a sql fragment in another file -->
	<select id="select" parameterType="java.lang.Integer" resultMap="resultWithPets">
		SELECT
		<include refid="columns" />
		,
		<include
			refid="org.apache.ibatis.submitted.xml_external_ref.SameIdPetMapper.columns" />
		FROM person, pet
		WHERE person_id = #{id}
		AND person_id = owner_id
		ORDER BY pet_id
	</select>
	<!-- Referencing a sql fragment and a result map in another file -->
	<select id="selectPet" parameterType="java.lang.Integer"
		resultMap="org.apache.ibatis.submitted.xml_external_ref.SameIdPetMapper.petResult">
		SELECT
		<include
			refid="org.apache.ibatis.submitted.xml_external_ref.SameIdPetMapper.columns" />
		FROM pet
		WHERE pet_id = #{id}
	</select>
</mapper>
