Skip to content

Commit

Permalink
Configuration variables are not expanded when parsing <include> nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrantaM committed Jul 26, 2013
1 parent 17bfc16 commit 77153c9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.ibatis.builder.IncompleteElementException;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.apache.ibatis.parsing.PropertyParser;
import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.session.Configuration;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -53,6 +54,7 @@ public void applyIncludes(Node source) {
}

private Node findSqlFragment(String refid) {
refid = PropertyParser.parse(refid, configuration.getVariables());
refid = builderAssistant.applyCurrentNamespace(refid, true);
try {
XNode nodeToInclude = configuration.getSqlFragments().get(refid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
<sql id="update">
update
</sql>
<sql id="values">
VALUES (1);
</sql>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.junit.Test;

import java.io.Reader;
import org.apache.ibatis.session.SqlSession;
import org.junit.Assert;

public class IncludeTest {

Expand All @@ -32,5 +34,13 @@ public void testIncludes() throws Exception {
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory sqlMapper = builder.build(reader);
assertNotNull(sqlMapper);

final SqlSession sqlSession = sqlMapper.openSession();
try {
final int result = sqlSession.selectOne("org.apache.ibatis.submitted.includes.mapper.selectWithProperty");
Assert.assertEquals(1, result);
} finally {
sqlSession.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
<include refid="sometable"/>
</select>

<select id="selectWithProperty" resultType="_int">
<include refid="${ns}.values"/>
</select>

<update id="update" parameterType="map">
<include refid="org.apache.ibatis.submitted.includes.fragments.update"/>
<include refid="org.apache.ibatis.submitted.includes.mapper.sometable"/>
set Field2 = #{field2,jdbcType=INTEGER},
Field3 = #{field3,jdbcType=VARCHAR},
where field1 = #{field1,jdbcType=INTEGER}
</update>
</mapper>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@

<configuration>

<properties>
<property name="ns" value="org.apache.ibatis.submitted.includes.fragments" />
</properties>

<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value="" />
</transactionManager>
<dataSource type="UNPOOLED">
<property name="driver" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:includes" />
<property name="username" value="sa" />
</dataSource>
</environment>
</environments>

<mappers>
<mapper resource="org/apache/ibatis/submitted/includes/Fragments.xml"/>
<mapper resource="org/apache/ibatis/submitted/includes/Mapper.xml"/>
Expand Down

0 comments on commit 77153c9

Please sign in to comment.