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

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

package com.dexcoder.dal.batis.build;

import java.util.Map;

import com.dexcoder.dal.batis.xml.SqlNode;

/**
 * Created by liyd on 2015-11-27.
 */
public class DynamicSqlSource implements SqlSource {

    private Configuration configuration;
    private SqlNode       rootSqlNode;

    public DynamicSqlSource(Configuration configuration, SqlNode rootSqlNode) {
        this.configuration = configuration;
        this.rootSqlNode = rootSqlNode;
    }

    public BatisBoundSql getBoundSql(Object parameterObject) {
        DynamicContext context = new DynamicContext(parameterObject);
        rootSqlNode.apply(context);
        SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
        SqlSource sqlSource = sqlSourceParser.parse(context.getSql());
        BatisBoundSql boundSql = sqlSource.getBoundSql(parameterObject);
        for (Map.Entry entry : context.getBindings().entrySet()) {
            boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
        }
        return boundSql;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy