Search in sources :

Example 1 with SqlNode

use of org.apache.ibatis.scripting.xmltags.SqlNode in project qiuyj-code by qiuyuanjun.

the class AbstractSqlGeneratorEngine method generateSqlSource.

/**
 * 生成mybatis实际运行时候的sqlSource
 * @param returnValue 返回值
 * @param args 参数
 * @return 对应的SqlSource
 */
private SqlSource generateSqlSource(SqlInfo sqlInfo, Object returnValue, Object args) {
    if (returnValue instanceof SqlSource) {
        return (SqlSource) returnValue;
    } else if (returnValue instanceof String) {
        return new StaticSqlSource(sqlInfo.getConfiguration(), (String) returnValue, getPrimaryKeyParameterMappings(sqlInfo));
    } else if (returnValue instanceof SqlNode) {
        SqlSource ss;
        // 进一步判断如果是StaticTextSqlNode,那么另外做处理
        if (returnValue instanceof StaticTextSqlNode) {
            DynamicContext context = new DynamicContext(sqlInfo.getConfiguration(), args);
            ((StaticTextSqlNode) returnValue).apply(context);
            ss = new StaticSqlSource(sqlInfo.getConfiguration(), context.getSql(), getPrimaryKeyParameterMappings(sqlInfo));
        } else {
            ss = new DynamicSqlSource(sqlInfo.getConfiguration(), (SqlNode) returnValue);
        }
        return ss;
    } else {
        throw new IllegalStateException("Unsupported return type: " + returnValue.getClass().getName() + ". [SqlSource, String, SqlNode] are support.");
    }
}
Also used : ProviderSqlSource(org.apache.ibatis.builder.annotation.ProviderSqlSource) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource) DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) MapperSqlSource(com.qiuyj.mybatis.MapperSqlSource) DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) StaticTextSqlNode(org.apache.ibatis.scripting.xmltags.StaticTextSqlNode) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource) StaticTextSqlNode(org.apache.ibatis.scripting.xmltags.StaticTextSqlNode) SqlNode(org.apache.ibatis.scripting.xmltags.SqlNode) DynamicContext(org.apache.ibatis.scripting.xmltags.DynamicContext)

Aggregations

MapperSqlSource (com.qiuyj.mybatis.MapperSqlSource)1 StaticSqlSource (org.apache.ibatis.builder.StaticSqlSource)1 ProviderSqlSource (org.apache.ibatis.builder.annotation.ProviderSqlSource)1 DynamicContext (org.apache.ibatis.scripting.xmltags.DynamicContext)1 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)1 SqlNode (org.apache.ibatis.scripting.xmltags.SqlNode)1 StaticTextSqlNode (org.apache.ibatis.scripting.xmltags.StaticTextSqlNode)1