org.apache.ibatis.builder.xml.dynamic.DynamicContext Maven / Gradle / Ivy
package org.apache.ibatis.builder.xml.dynamic;
import org.apache.ibatis.reflection.MetaObject;
import java.util.*;
public class DynamicContext {
private Map bindings = new HashMap();
private StringBuilder sqlBuilder = new StringBuilder();
private int uniqueNumber = 0;
public DynamicContext(Object parameterObject) {
if (parameterObject instanceof Map) {
bindings.putAll((Map)parameterObject);
} else if (parameterObject != null) {
MetaObject metaObject = MetaObject.forObject(parameterObject);
String[] names = metaObject.getGetterNames();
for(String name : names) {
bindings.put(name,metaObject.getValue(name));
}
}
bindings.put("_parameter", parameterObject);
}
public Map getBindings() {
return bindings;
}
public void bind(String name, Object value) {
bindings.put(name,value);
}
public void appendSql(String sql) {
sqlBuilder.append(sql);
sqlBuilder.append(" ");
}
public String getSql() {
return sqlBuilder.toString().trim();
}
public int getUniqueNumber() {
return uniqueNumber++;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy