Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.ibatis.builder.SqlSourceBuilder;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.parsing.PropertyParser;
import org.apache.ibatis.reflection.ParamNameResolver;
import org.apache.ibatis.session.Configuration;

Expand All @@ -32,6 +33,7 @@
*/
public class ProviderSqlSource implements SqlSource {

private final Configuration configuration;
private final SqlSourceBuilder sqlSourceParser;
private final Class<?> providerType;
private Method providerMethod;
Expand All @@ -44,17 +46,18 @@ public class ProviderSqlSource implements SqlSource {
* @deprecated Please use the {@link #ProviderSqlSource(Configuration, Object, Class, Method)} instead of this.
*/
@Deprecated
public ProviderSqlSource(Configuration config, Object provider) {
this(config, provider, null, null);
public ProviderSqlSource(Configuration configuration, Object provider) {
this(configuration, provider, null, null);
}

/**
* @since 3.4.5
*/
public ProviderSqlSource(Configuration config, Object provider, Class<?> mapperType, Method mapperMethod) {
public ProviderSqlSource(Configuration configuration, Object provider, Class<?> mapperType, Method mapperMethod) {
String providerMethodName;
try {
this.sqlSourceParser = new SqlSourceBuilder(config);
this.configuration = configuration;
this.sqlSourceParser = new SqlSourceBuilder(configuration);
this.providerType = (Class<?>) provider.getClass().getMethod("type").invoke(provider);
providerMethodName = (String) provider.getClass().getMethod("method").invoke(provider);

Expand All @@ -67,7 +70,7 @@ public ProviderSqlSource(Configuration config, Object provider, Class<?> mapperT
+ "'. Sql provider method can not overload.");
}
this.providerMethod = m;
this.providerMethodArgumentNames = new ParamNameResolver(config, m).getNames();
this.providerMethodArgumentNames = new ParamNameResolver(configuration, m).getNames();
this.providerMethodParameterTypes = m.getParameterTypes();
}
}
Expand Down Expand Up @@ -125,7 +128,7 @@ private SqlSource createSqlSource(Object parameterObject) {
+ " using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.");
}
Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
return sqlSourceParser.parse(sql, parameterType, new HashMap<String, Object>());
return sqlSourceParser.parse(replacePlaceholder(sql), parameterType, new HashMap<String, Object>());
} catch (BuilderException e) {
throw e;
} catch (Exception e) {
Expand Down Expand Up @@ -158,4 +161,8 @@ private Object[] extractProviderMethodArguments(Map<String, Object> params, Stri
return args;
}

private String replacePlaceholder(String sql) {
return PropertyParser.parse(sql, configuration.getVariables());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public String buildSelectByIdProviderContextOnly(ProviderContext context) {
FROM(tableName);
WHERE("id = #{id}");
if (!containsLogicalDelete){
WHERE("logical_delete = false");
WHERE("logical_delete = ${Constants.LOGICAL_DELETE_OFF}");
}
}}.toString();
}
Expand All @@ -172,7 +172,7 @@ public String buildSelectByNameOneParamAndProviderContext(ProviderContext contex
WHERE("name like #{name} || '%'");
}
if (!containsLogicalDelete){
WHERE("logical_delete = false");
WHERE("logical_delete = ${LOGICAL_DELETE_OFF:0}");
}
}}.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

<configuration>

<properties>
<property name="Constants.LOGICAL_DELETE_OFF" value="false"/>
<property name="org.apache.ibatis.parsing.PropertyParser.enable-default-value" value="true"/>
</properties>

<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
Expand Down