[MyBatis原始碼分析系列] BoundSql
阿新 • • 發佈:2018-12-14
BoundSql
簡介
從SqlSource
得到的處理了動態內容的真正的SQL。這個SQL可以有?佔位符和一系列引數。
也可以是由動態語言(如loops,bind)建立的額外的引數。
原始碼
public class BoundSql {
private final String sql;
private final List<ParameterMapping> parameterMappings;
private final Object parameterObject;
private final Map<String, Object> additionalParameters;
private final MetaObject metaParameters;
public BoundSql(Configuration configuration, String sql, List<ParameterMapping> parameterMappings, Object parameterObject) {
this.sql = sql;
this.parameterMappings = parameterMappings;
this.parameterObject = parameterObject;
this.additionalParameters = new HashMap<String, Object>();
this.metaParameters = configuration.newMetaObject(additionalParameters);
}
public String getSql(){
return sql;
}
public List<ParameterMapping> getParameterMappings(){
return parameterMappings;
}
public Object getParameterObject (){
return parameterObject;
}
public boolean hasAdditionalParameter(String name){
String paramName = new PropertyTokenizer(name).getName();
return additionalParameters.containsKey(paramName);
}
public void setAdditionalParameter(String name, Object value) {
metaParameters.setValue(name, value);
}
public Object getAdditionalParameter(String name) {
return metaParameters.getValue(name);
}
}