1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.scripting.defaults;
17
18 import java.util.HashMap;
19
20 import org.apache.ibatis.builder.SqlSourceBuilder;
21 import org.apache.ibatis.mapping.BoundSql;
22 import org.apache.ibatis.mapping.SqlSource;
23 import org.apache.ibatis.scripting.xmltags.DynamicContext;
24 import org.apache.ibatis.scripting.xmltags.DynamicSqlSource;
25 import org.apache.ibatis.scripting.xmltags.SqlNode;
26 import org.apache.ibatis.session.Configuration;
27
28
29
30
31
32
33
34
35 public class RawSqlSource implements SqlSource {
36
37 private final SqlSource sqlSource;
38
39 public RawSqlSource(Configuration configuration, SqlNode rootSqlNode, Class<?> parameterType) {
40 this(configuration, getSql(configuration, rootSqlNode), parameterType);
41 }
42
43 public RawSqlSource(Configuration configuration, String sql, Class<?> parameterType) {
44 SqlSourceBuildertml#SqlSourceBuilder">SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
45 Class<?> clazz = parameterType == null ? Object.class : parameterType;
46 sqlSource = sqlSourceParser.parse(sql, clazz, new HashMap<>());
47 }
48
49 private static String getSql(Configuration configuration, SqlNode rootSqlNode) {
50 DynamicContexts/DynamicContext.html#DynamicContext">DynamicContext context = new DynamicContext(configuration, null);
51 rootSqlNode.apply(context);
52 return context.getSql();
53 }
54
55 @Override
56 public BoundSql getBoundSql(Object parameterObject) {
57 return sqlSource.getBoundSql(parameterObject);
58 }
59
60 }