All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ibatis.builder.xml.dynamic.DynamicContext Maven / Gradle / Ivy

There is a newer version: 3.0-beta-10
Show newest version
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