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());
}
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.");
}
}
Aggregations