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