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

com.dexcoder.dal.batis.build.BatisBoundSql Maven / Gradle / Ivy

package com.dexcoder.dal.batis.build;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dexcoder.dal.BoundSql;
import com.dexcoder.dal.batis.reflection.MetaObject;

/**
 * Created by liyd on 2015-11-25.
 */
public class BatisBoundSql implements BoundSql {

    private String                 sql;
    private List parameterMappings;
    private Object                 parameterObject;
    private Map    additionalParameters;
    private MetaObject             metaParameters;

    public BatisBoundSql(String sql, List parameterMappings, Object parameterObject) {
        this.sql = sql;
        this.parameterMappings = parameterMappings;
        this.parameterObject = parameterObject;
        this.additionalParameters = new HashMap();
        this.metaParameters = MetaObject.forObject(additionalParameters);
    }

    public List getParameters() {
        List params = new ArrayList();
        if (parameterMappings == null) {
            return params;
        }
        for (ParameterMapping parameterMapping : parameterMappings) {
            String property = parameterMapping.getProperty();
            Object value = getAdditionalParameter(property);
            params.add(value);
        }
        return params;
    }

    public String getSql() {
        return sql;
    }

    public void setAdditionalParameter(String name, Object value) {
        metaParameters.setValue(name, value);
    }

    public Object getAdditionalParameter(String name) {
        return metaParameters.getValue(name);
    }

    public Object getParameterObject() {
        return parameterObject;
    }
}