MyBatis/iBatis - reusable sql fragments in a separate SQL Map file?
Say, you have some
<mapper namespace="Common">
<sql id="idsIn">
${column} IN
<foreach item="id" collection="ids" separator="," open="(" close=")">
#{id}
</foreach>
</sql>
</mapper>
Than in another mapper you can use it like:
<mapper namespace="OtherMapper">
<sql id="someSql">
...
<include refid="Common.idsIn">
<property name="column" value="${column}"/>
<!-- OR hardcode: <property name="column" value="id"/> -->
<property name="filterPksTable" value="${filterPksTable}"/>
</include>
...
</sql>
</mapper>
Also, you can have a look here
This is exactly what a project I used to work on did. Common fragments were defined in a separate file which was included in the main iBATIS config file.
We had a SQL map file at the root named Core.ism.xml
which looked like this:
<sqlMap namespace="Core" >
<sql id="fragmentBasicAuditFieldNames">
CreateDate, CreateUser,
UpdateDate, UpdateUser, UpdateCode
</sql>
....
And then in our SQL map files we could reference it like this:
<include refid="Core.fragmentBasicAuditFieldNames" />
I hope I've understood what you were asking correctly!