21
21
import org .apache .ibatis .mapping .BoundSql ;
22
22
import org .apache .ibatis .mapping .SqlSource ;
23
23
import org .apache .ibatis .parsing .XNode ;
24
+ import org .apache .ibatis .scripting .xmltags .DynamicContext ;
25
+ import org .apache .ibatis .scripting .xmltags .SqlNode ;
24
26
import org .apache .ibatis .session .Configuration ;
25
27
import org .w3c .dom .Node ;
26
28
import org .w3c .dom .NodeList ;
27
29
28
30
public class RawSqlSource implements SqlSource {
29
31
30
32
private final SqlSource sqlSource ;
33
+
34
+ public RawSqlSource (Configuration configuration , SqlNode rootSqlNode , Class <?> parameterType ) {
35
+ this (configuration , getSql (configuration , rootSqlNode ), parameterType );
36
+ }
31
37
32
38
public RawSqlSource (Configuration configuration , XNode script , Class <?> parameterType ) {
33
- this (configuration , getString (script ), parameterType );
39
+ this (configuration , getStringFromXNode (script ), parameterType );
34
40
}
35
41
36
42
public RawSqlSource (Configuration configuration , String sql , Class <?> parameterType ) {
@@ -39,7 +45,13 @@ public RawSqlSource(Configuration configuration, String sql, Class<?> parameterT
39
45
sqlSource = sqlSourceParser .parse (sql , clazz , new HashMap <String , Object >());
40
46
}
41
47
42
- private static String getString (XNode script ) {
48
+ private static String getSql (Configuration configuration , SqlNode rootSqlNode ) {
49
+ DynamicContext context = new DynamicContext (configuration , null );
50
+ rootSqlNode .apply (context );
51
+ return context .getSql ();
52
+ }
53
+
54
+ private static String getStringFromXNode (XNode script ) {
43
55
StringBuilder contents = new StringBuilder ();
44
56
NodeList children = script .getNode ().getChildNodes ();
45
57
for (int i = 0 ; i < children .getLength (); i ++) {
0 commit comments