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

com.revengemission.plugins.mybatis.DynamicSqlSourceX.txt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version

import org.apache.ibatis.builder.xml.XMLMapperEntityResolver;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.parsing.XPathParser;
import org.apache.ibatis.scripting.xmltags.XMLScriptBuilder;
import org.apache.ibatis.session.Configuration;

import java.util.Map;

public class DynamicSqlSourceX implements SqlSource {
    private final Configuration configuration;


    public DynamicSqlSourceX(Configuration configuration) {
        this.configuration = configuration;
    }

    @SuppressWarnings("unchecked")
    @Override
    public BoundSql getBoundSql(Object parameterObject) {
        Map parames = (Map) parameterObject;
        String scriptSql = "";
        parames.remove("sql");
        XPathParser parser = new XPathParser(scriptSql, false, configuration.getVariables(), new XMLMapperEntityResolver());
        XNode xNode = parser.evalNode("/script");
        XMLScriptBuilder xmlScriptBuilder = new XMLScriptBuilder(configuration, xNode);
        return xmlScriptBuilder.parseScriptNode().getBoundSql(parames);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy