Search in sources :

Example 6 with StaticTextSqlNode

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

the class SqlProvider method batchDelete.

public ReturnValueWrapper batchDelete(MappedStatement ms, SqlInfo sqlInfo) {
    checkPrimaryKey(sqlInfo);
    String sql = new StringBuilder("DELETE FROM ").append(sqlInfo.getTableName()).append(" WHERE ").append(sqlInfo.getPrimaryKey().getDatabaseColumnName()).append(" IN ").toString();
    // 后面的条件交给BatchDeleteParameterObjectResolver去通过反射生成
    return new ReturnValueWrapper(new StaticTextSqlNode(sql), BatchDeleteParameterObjectResolver.getInstance());
}
Also used : StaticTextSqlNode(org.apache.ibatis.scripting.xmltags.StaticTextSqlNode)

Example 7 with StaticTextSqlNode

use of org.apache.ibatis.scripting.xmltags.StaticTextSqlNode 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

StaticTextSqlNode (org.apache.ibatis.scripting.xmltags.StaticTextSqlNode)7 ArrayList (java.util.ArrayList)4 ParameterMapping (org.apache.ibatis.mapping.ParameterMapping)4 PropertyColumnMapping (com.qiuyj.mybatis.PropertyColumnMapping)3 SQL (org.apache.ibatis.jdbc.SQL)3 BeanExampleResolver (com.qiuyj.mybatis.BeanExampleResolver)2 MapperSqlSource (com.qiuyj.mybatis.MapperSqlSource)1 ReturnValueWrapper (com.qiuyj.mybatis.sqlbuild.ReturnValueWrapper)1 StringJoiner (java.util.StringJoiner)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 TypeHandlerRegistry (org.apache.ibatis.type.TypeHandlerRegistry)1