2323import org .apache .ibatis .builder .SqlSourceBuilder ;
2424import org .apache .ibatis .mapping .BoundSql ;
2525import org .apache .ibatis .mapping .SqlSource ;
26+ import org .apache .ibatis .parsing .PropertyParser ;
2627import org .apache .ibatis .reflection .ParamNameResolver ;
2728import org .apache .ibatis .session .Configuration ;
2829
3233 */
3334public class ProviderSqlSource implements SqlSource {
3435
36+ private final Configuration configuration ;
3537 private final SqlSourceBuilder sqlSourceParser ;
3638 private final Class <?> providerType ;
3739 private Method providerMethod ;
@@ -44,17 +46,18 @@ public class ProviderSqlSource implements SqlSource {
4446 * @deprecated Please use the {@link #ProviderSqlSource(Configuration, Object, Class, Method)} instead of this.
4547 */
4648 @ 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 );
4951 }
5052
5153 /**
5254 * @since 3.4.5
5355 */
54- public ProviderSqlSource (Configuration config , Object provider , Class <?> mapperType , Method mapperMethod ) {
56+ public ProviderSqlSource (Configuration configuration , Object provider , Class <?> mapperType , Method mapperMethod ) {
5557 String providerMethodName ;
5658 try {
57- this .sqlSourceParser = new SqlSourceBuilder (config );
59+ this .configuration = configuration ;
60+ this .sqlSourceParser = new SqlSourceBuilder (configuration );
5861 this .providerType = (Class <?>) provider .getClass ().getMethod ("type" ).invoke (provider );
5962 providerMethodName = (String ) provider .getClass ().getMethod ("method" ).invoke (provider );
6063
@@ -67,7 +70,7 @@ public ProviderSqlSource(Configuration config, Object provider, Class<?> mapperT
6770 + "'. Sql provider method can not overload." );
6871 }
6972 this .providerMethod = m ;
70- this .providerMethodArgumentNames = new ParamNameResolver (config , m ).getNames ();
73+ this .providerMethodArgumentNames = new ParamNameResolver (configuration , m ).getNames ();
7174 this .providerMethodParameterTypes = m .getParameterTypes ();
7275 }
7376 }
@@ -125,7 +128,7 @@ private SqlSource createSqlSource(Object parameterObject) {
125128 + " using a specifying parameterObject. In this case, please specify a 'java.util.Map' object." );
126129 }
127130 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 >());
129132 } catch (BuilderException e ) {
130133 throw e ;
131134 } catch (Exception e ) {
@@ -158,4 +161,8 @@ private Object[] extractProviderMethodArguments(Map<String, Object> params, Stri
158161 return args ;
159162 }
160163
164+ private String replacePlaceholder (String sql ) {
165+ return PropertyParser .parse (sql , configuration .getVariables ());
166+ }
167+
161168}
0 commit comments