|
@@ -25,7 +25,7 @@ import org.apache.ibatis.reflection.MetaObject;
|
|
import com.baomidou.mybatisplus.core.parser.ISqlParser;
|
|
import com.baomidou.mybatisplus.core.parser.ISqlParser;
|
|
import com.baomidou.mybatisplus.core.parser.SqlInfo;
|
|
import com.baomidou.mybatisplus.core.parser.SqlInfo;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
-import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.toolkit.SqlParserUtils;
|
|
|
|
|
|
import net.sf.jsqlparser.expression.Expression;
|
|
import net.sf.jsqlparser.expression.Expression;
|
|
import net.sf.jsqlparser.expression.Function;
|
|
import net.sf.jsqlparser.expression.Function;
|
|
@@ -76,23 +76,19 @@ public class JsqlParserCountOptimize implements ISqlParser {
|
|
//#95 Github, selectItems contains #{} ${}, which will be translated to ?, and it may be in a function: power(#{myInt},2)
|
|
//#95 Github, selectItems contains #{} ${}, which will be translated to ?, and it may be in a function: power(#{myInt},2)
|
|
for (SelectItem item : plainSelect.getSelectItems()) {
|
|
for (SelectItem item : plainSelect.getSelectItems()) {
|
|
if (item.toString().contains("?")) {
|
|
if (item.toString().contains("?")) {
|
|
- sqlInfo.setSql(SqlUtils.getOriginalCountSql(selectStatement.toString()));
|
|
|
|
- return sqlInfo;
|
|
|
|
|
|
+ return sqlInfo.setSql(SqlParserUtils.getOriginalCountSql(selectStatement.toString()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 包含 distinct、groupBy不优化
|
|
// 包含 distinct、groupBy不优化
|
|
if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
|
|
if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
|
|
- sqlInfo.setSql(SqlUtils.getOriginalCountSql(selectStatement.toString()));
|
|
|
|
- return sqlInfo;
|
|
|
|
|
|
+ return sqlInfo.setSql(SqlParserUtils.getOriginalCountSql(selectStatement.toString()));
|
|
}
|
|
}
|
|
// 优化 SQL
|
|
// 优化 SQL
|
|
plainSelect.setSelectItems(COUNT_SELECT_ITEM);
|
|
plainSelect.setSelectItems(COUNT_SELECT_ITEM);
|
|
- sqlInfo.setSql(selectStatement.toString());
|
|
|
|
- return sqlInfo;
|
|
|
|
|
|
+ return sqlInfo.setSql(selectStatement.toString());
|
|
} catch (Throwable e) {
|
|
} catch (Throwable e) {
|
|
// 无法优化使用原 SQL
|
|
// 无法优化使用原 SQL
|
|
- sqlInfo.setSql(SqlUtils.getOriginalCountSql(sql));
|
|
|
|
- return sqlInfo;
|
|
|
|
|
|
+ return sqlInfo.setSql(SqlParserUtils.getOriginalCountSql(sql));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|