File tree Expand file tree Collapse file tree 5 files changed +37
-1
lines changed
main/java/org/apache/ibatis/builder/xml
test/java/org/apache/ibatis/submitted/includes Expand file tree Collapse file tree 5 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import org .apache .ibatis .builder .IncompleteElementException ;
19
19
import org .apache .ibatis .builder .MapperBuilderAssistant ;
20
+ import org .apache .ibatis .parsing .PropertyParser ;
20
21
import org .apache .ibatis .parsing .XNode ;
21
22
import org .apache .ibatis .session .Configuration ;
22
23
import org .w3c .dom .Node ;
@@ -53,6 +54,7 @@ public void applyIncludes(Node source) {
53
54
}
54
55
55
56
private Node findSqlFragment (String refid ) {
57
+ refid = PropertyParser .parse (refid , configuration .getVariables ());
56
58
refid = builderAssistant .applyCurrentNamespace (refid , true );
57
59
try {
58
60
XNode nodeToInclude = configuration .getSqlFragments ().get (refid );
Original file line number Diff line number Diff line change 28
28
<sql id =" update" >
29
29
update
30
30
</sql >
31
+ <sql id =" values" >
32
+ VALUES (1);
33
+ </sql >
31
34
</mapper >
Original file line number Diff line number Diff line change 22
22
import org .junit .Test ;
23
23
24
24
import java .io .Reader ;
25
+ import org .apache .ibatis .session .SqlSession ;
26
+ import org .junit .Assert ;
25
27
26
28
public class IncludeTest {
27
29
@@ -32,5 +34,13 @@ public void testIncludes() throws Exception {
32
34
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder ();
33
35
SqlSessionFactory sqlMapper = builder .build (reader );
34
36
assertNotNull (sqlMapper );
37
+
38
+ final SqlSession sqlSession = sqlMapper .openSession ();
39
+ try {
40
+ final int result = sqlSession .selectOne ("org.apache.ibatis.submitted.includes.mapper.selectWithProperty" );
41
+ Assert .assertEquals (1 , result );
42
+ } finally {
43
+ sqlSession .close ();
44
+ }
35
45
}
36
46
}
Original file line number Diff line number Diff line change 33
33
<include refid =" sometable" />
34
34
</select >
35
35
36
+ <select id =" selectWithProperty" resultType =" _int" >
37
+ <include refid =" ${ns}.values" />
38
+ </select >
39
+
36
40
<update id =" update" parameterType =" map" >
37
41
<include refid =" org.apache.ibatis.submitted.includes.fragments.update" />
38
42
<include refid =" org.apache.ibatis.submitted.includes.mapper.sometable" />
39
43
set Field2 = #{field2,jdbcType=INTEGER},
40
44
Field3 = #{field3,jdbcType=VARCHAR},
41
45
where field1 = #{field1,jdbcType=INTEGER}
42
46
</update >
43
- </mapper >
47
+ </mapper >
Original file line number Diff line number Diff line change 23
23
24
24
<configuration >
25
25
26
+ <properties >
27
+ <property name =" ns" value =" org.apache.ibatis.submitted.includes.fragments" />
28
+ </properties >
29
+
30
+ <environments default =" development" >
31
+ <environment id =" development" >
32
+ <transactionManager type =" JDBC" >
33
+ <property name =" " value =" " />
34
+ </transactionManager >
35
+ <dataSource type =" UNPOOLED" >
36
+ <property name =" driver" value =" org.hsqldb.jdbcDriver" />
37
+ <property name =" url" value =" jdbc:hsqldb:mem:includes" />
38
+ <property name =" username" value =" sa" />
39
+ </dataSource >
40
+ </environment >
41
+ </environments >
42
+
26
43
<mappers >
27
44
<mapper resource =" org/apache/ibatis/submitted/includes/Fragments.xml" />
28
45
<mapper resource =" org/apache/ibatis/submitted/includes/Mapper.xml" />
You can’t perform that action at this time.
0 commit comments