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

io.github.wujun728.sql.context.Context Maven / Gradle / Ivy

The newest version!
package io.github.wujun728.sql.context;

import java.util.*;

import io.github.wujun728.sql.util.OgnlUtil;


public class Context {

    StringBuilder sqlBuilder = new StringBuilder();
    List jdbcParameters = new ArrayList<>();
    Set paramNames = new HashSet<>();

    //    List jdbcParameterNames = new ArrayList<>();
    Map data;

    public Context(Map data) {
        this.data = data;
    }

    public void appendSql(String text) {
        if (text != null)
            sqlBuilder.append(text);
    }

    public void addParameter(Object o) {
        jdbcParameters.add(o);
    }

    public void addParameterName(String o) {
        paramNames.add(o);
    }

    /**
     * 通过ognl表达式获取值
     *
     * @param expression
     * @return
     */
    public Object getOgnlValue(String expression) {
        return OgnlUtil.getValue(expression, data);
    }

    public Boolean getOgnlBooleanValue(String expression) {
        return OgnlUtil.getBooleanValue(expression, data);
    }

    public String getSql() {
        return sqlBuilder.toString();
    }

    public void setSql(String text) {
        sqlBuilder = new StringBuilder(text);
    }

    public List getJdbcParameters() {
        return jdbcParameters;
    }

    public Map getData() {
        return data;
    }

}