Bläddra i källkod

升级 jsqlparser 2.1

hubin 6 år sedan
förälder
incheckning
a9635c933a

+ 1 - 1
build.gradle

@@ -24,7 +24,7 @@ ext {
         mybatisSpringBootStarterVersion = '2.1.0',
         springVersion = '5.1.6.RELEASE',
         springBootVersion = '2.1.6.RELEASE',
-        jsqlparserVersion = '1.2',
+        jsqlparserVersion = '2.1',
         junitVersion = '5.4.0',
     ]
 

+ 4 - 3
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/IllegalSQLInterceptor.java

@@ -110,9 +110,10 @@ public class IllegalSQLInterceptor implements Interceptor {
             throw new MybatisPlusException("非法SQL,where条件中不能使用【!=】关键字,错误!=信息:" + notEqualsTo.toString());
         } else if (expression instanceof BinaryExpression) {
             BinaryExpression binaryExpression = (BinaryExpression) expression;
-            if (binaryExpression.isNot()) {
-                throw new MybatisPlusException("非法SQL,where条件中不能使用【not】关键字,错误not信息:" + binaryExpression.toString());
-            }
+            // TODO 升级 jsqlparser 后待实现
+//            if (binaryExpression.isNot()) {
+//                throw new MybatisPlusException("非法SQL,where条件中不能使用【not】关键字,错误not信息:" + binaryExpression.toString());
+//            }
             if (binaryExpression.getLeftExpression() instanceof Function) {
                 Function function = (Function) binaryExpression.getLeftExpression();
                 throw new MybatisPlusException("非法SQL,where条件中不能使用数据库函数,错误函数信息:" + function.toString());

+ 3 - 3
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/optimize/JsqlParserCountOptimize.java

@@ -82,11 +82,11 @@ public class JsqlParserCountOptimize implements ISqlParser {
             Select selectStatement = (Select) CCJSqlParserUtil.parse(sql);
             PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
             Distinct distinct = plainSelect.getDistinct();
-            List<Expression> groupBy = plainSelect.getGroupByColumnReferences();
+            GroupByElement groupBy = plainSelect.getGroupBy();
             List<OrderByElement> orderBy = plainSelect.getOrderByElements();
 
             // 添加包含groupBy 不去除orderBy
-            if (CollectionUtils.isEmpty(groupBy) && CollectionUtils.isNotEmpty(orderBy)) {
+            if (null == groupBy && CollectionUtils.isNotEmpty(orderBy)) {
                 plainSelect.setOrderByElements(null);
                 sqlInfo.setOrderBy(false);
             }
@@ -97,7 +97,7 @@ public class JsqlParserCountOptimize implements ISqlParser {
                 }
             }
             // 包含 distinct、groupBy不优化
-            if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
+            if (distinct != null || null != groupBy) {
                 return sqlInfo.setSql(SqlParserUtils.getOriginalCountSql(selectStatement.toString()));
             }
             // 包含 join 连表,进行判断是否移除 join 连表