23
23
import org .apache .ibatis .builder .SqlSourceBuilder ;
24
24
import org .apache .ibatis .mapping .BoundSql ;
25
25
import org .apache .ibatis .mapping .SqlSource ;
26
+ import org .apache .ibatis .parsing .PropertyParser ;
26
27
import org .apache .ibatis .reflection .ParamNameResolver ;
27
28
import org .apache .ibatis .session .Configuration ;
28
29
32
33
*/
33
34
public class ProviderSqlSource implements SqlSource {
34
35
36
+ private final Configuration configuration ;
35
37
private final SqlSourceBuilder sqlSourceParser ;
36
38
private final Class <?> providerType ;
37
39
private Method providerMethod ;
@@ -44,17 +46,18 @@ public class ProviderSqlSource implements SqlSource {
44
46
* @deprecated Please use the {@link #ProviderSqlSource(Configuration, Object, Class, Method)} instead of this.
45
47
*/
46
48
@ Deprecated
47
- public ProviderSqlSource (Configuration config , Object provider ) {
48
- this (config , provider , null , null );
49
+ public ProviderSqlSource (Configuration configuration , Object provider ) {
50
+ this (configuration , provider , null , null );
49
51
}
50
52
51
53
/**
52
54
* @since 3.4.5
53
55
*/
54
- public ProviderSqlSource (Configuration config , Object provider , Class <?> mapperType , Method mapperMethod ) {
56
+ public ProviderSqlSource (Configuration configuration , Object provider , Class <?> mapperType , Method mapperMethod ) {
55
57
String providerMethodName ;
56
58
try {
57
- this .sqlSourceParser = new SqlSourceBuilder (config );
59
+ this .configuration = configuration ;
60
+ this .sqlSourceParser = new SqlSourceBuilder (configuration );
58
61
this .providerType = (Class <?>) provider .getClass ().getMethod ("type" ).invoke (provider );
59
62
providerMethodName = (String ) provider .getClass ().getMethod ("method" ).invoke (provider );
60
63
@@ -67,7 +70,7 @@ public ProviderSqlSource(Configuration config, Object provider, Class<?> mapperT
67
70
+ "'. Sql provider method can not overload." );
68
71
}
69
72
this .providerMethod = m ;
70
- this .providerMethodArgumentNames = new ParamNameResolver (config , m ).getNames ();
73
+ this .providerMethodArgumentNames = new ParamNameResolver (configuration , m ).getNames ();
71
74
this .providerMethodParameterTypes = m .getParameterTypes ();
72
75
}
73
76
}
@@ -125,7 +128,7 @@ private SqlSource createSqlSource(Object parameterObject) {
125
128
+ " using a specifying parameterObject. In this case, please specify a 'java.util.Map' object." );
126
129
}
127
130
Class <?> parameterType = parameterObject == null ? Object .class : parameterObject .getClass ();
128
- return sqlSourceParser .parse (sql , parameterType , new HashMap <String , Object >());
131
+ return sqlSourceParser .parse (replacePlaceholder ( sql ) , parameterType , new HashMap <String , Object >());
129
132
} catch (BuilderException e ) {
130
133
throw e ;
131
134
} catch (Exception e ) {
@@ -158,4 +161,8 @@ private Object[] extractProviderMethodArguments(Map<String, Object> params, Stri
158
161
return args ;
159
162
}
160
163
164
+ private String replacePlaceholder (String sql ) {
165
+ return PropertyParser .parse (sql , configuration .getVariables ());
166
+ }
167
+
161
168
}
0 commit comments