瀏覽代碼

Merge branch '3.0' into github-3.0

hubin 4 年之前
父節點
當前提交
110af1d307
共有 77 個文件被更改,包括 488 次插入3034 次删除
  1. 2 0
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/interfaces/Func.java
  2. 0 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/update/LambdaUpdateWrapper.java
  3. 0 1
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/toolkit/sql/SqlScriptUtilsTest.java
  4. 4 9
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/MybatisConfigurationTest.java
  5. 0 1
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/Role.java
  6. 0 1
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/User.java
  7. 2 2
      mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/toolkit/BeanUtilsTest.java
  8. 0 53
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parsers/BlockAttackSqlParser.java
  9. 0 94
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parsers/DynamicTableNameParser.java
  10. 0 42
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parsers/ITableNameHandler.java
  11. 0 367
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/IllegalSQLInterceptor.java
  12. 0 145
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/OptimisticLockerInterceptor.java
  13. 0 332
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/PaginationInterceptor.java
  14. 0 72
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/SqlExplainInterceptor.java
  15. 0 347
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/FakeTenantLineInnerInterceptor.java
  16. 1 1
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/PaginationInnerInterceptor.java
  17. 31 8
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/TenantLineInnerInterceptor.java
  18. 0 54
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/DialectFactory.java
  19. 0 26
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/DmDialect.java
  20. 0 24
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/GBaseDialect.java
  21. 0 24
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/GaussDialect.java
  22. 0 26
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/H2Dialect.java
  23. 0 26
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/HSQLDialect.java
  24. 0 26
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/KingbaseDialect.java
  25. 0 26
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/MariaDBDialect.java
  26. 0 26
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/OscarDialect.java
  27. 0 24
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/PhoenixDialect.java
  28. 0 26
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SQLiteDialect.java
  29. 0 26
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/XuGuDialect.java
  30. 0 70
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/tenant/TenantHandler.java
  31. 0 309
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/tenant/TenantSqlParser.java
  32. 0 19
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/tenant/package-info.java
  33. 49 49
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/parsers/DynamicTableNameParserTest.java
  34. 6 8
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/handlers/FastJsonTypeHandlerTest.java
  35. 6 8
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/handlers/GsonTypeHandlerTest.java
  36. 7 9
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/handlers/JacksonTypeHandlerTest.java
  37. 0 47
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/pagination/DialectFactoryTest.java
  38. 0 94
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/pagination/PaginationInterceptorTest.java
  39. 25 21
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/pagination/SelectBodyToPlainSelectTest.java
  40. 0 36
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/pagination/dialects/DB2DialectTest.java
  41. 0 93
      mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/tenant/TenantSqlParserTest.java
  42. 6 8
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/BaseTest.java
  43. 7 13
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2Delete1Eq1Test.java
  44. 7 13
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2LogicDeleteTest.java
  45. 0 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/cache/service/impl/CacheServiceImpl.java
  46. 3 4
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/DBConfig.java
  47. 6 44
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusConfig.java
  48. 9 9
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusConfigLogicDelete.java
  49. 3 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisXmlConfig.java
  50. 0 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/H2Addr.java
  51. 0 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/H2Student.java
  52. 4 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/H2User.java
  53. 4 9
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/H2UserLogicDelete.java
  54. 2 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuSuperEntity.java
  55. 2 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuSuperEntityCamel.java
  56. 3 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuperEntityCamel.java
  57. 17 15
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/fillperformance/FillPerformanceConfig.java
  58. 7 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/idgenerator/IdGeneratorConfig.java
  59. 5 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/issues/genericid/MybatisPlusConfig.java
  60. 9 7
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/keygenerator/KeyGeneratorConfig.java
  61. 4 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/keygenerator/model/LongKeyGeneratorModel.java
  62. 6 11
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/mapper/H2UserMapper.java
  63. 2 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/mapper/SuperMapper.java
  64. 3 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserService.java
  65. 1 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2StudentServiceImpl.java
  66. 6 7
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserServiceImpl.java
  67. 44 44
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/tenant/CustomCacheExecutor.java
  68. 93 93
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/tenant/TenantConfig.java
  69. 65 65
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/tenant/TenantTest.java
  70. 1 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/config/DBConfig.java
  71. 8 47
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/config/MybatisPlusConfig.java
  72. 0 4
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/phoenix/PhoenixTest.java
  73. 8 13
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/phoenix/config/MybatisPlusConfig.java
  74. 5 5
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/reflection/ExampleObjectFactory.java
  75. 2 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/sharding/ShardingOrder.java
  76. 1 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/sharding/ShardingOrderMapper.java
  77. 12 14
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/sharding/ShardingTest.java

+ 2 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/interfaces/Func.java

@@ -73,6 +73,7 @@ public interface Func<Children, R> extends Serializable {
      * 字段 IN (value.get(0), value.get(1), ...)
      * <p>例: in("id", Arrays.asList(1, 2, 3, 4, 5))</p>
      *
+     * <li> 注意!集合为空若存在逻辑错误,请在 condition 条件中判断 </li>
      * <li> 如果集合为 empty 则不会进行 sql 拼接 </li>
      *
      * @param condition 执行条件
@@ -93,6 +94,7 @@ public interface Func<Children, R> extends Serializable {
      * 字段 IN (v0, v1, ...)
      * <p>例: in("id", 1, 2, 3, 4, 5)</p>
      *
+     * <li> 注意!数组为空若存在逻辑错误,请在 condition 条件中判断 </li>
      * <li> 如果动态数组为 empty 则不会进行 sql 拼接 </li>
      *
      * @param condition 执行条件

+ 0 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/update/LambdaUpdateWrapper.java

@@ -21,7 +21,6 @@ import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-import com.baomidou.mybatisplus.core.toolkit.support.ColumnCache;
 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 
 import java.util.ArrayList;

+ 0 - 1
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/toolkit/sql/SqlScriptUtilsTest.java

@@ -5,7 +5,6 @@ import org.apache.ibatis.type.LocalDateTypeHandler;
 import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * @author miemie

+ 4 - 9
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/MybatisConfigurationTest.java

@@ -25,12 +25,7 @@ import org.apache.ibatis.io.Resources;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.mapping.SqlCommandType;
 import org.apache.ibatis.mapping.StatementType;
-import org.apache.ibatis.session.AutoMappingBehavior;
-import org.apache.ibatis.session.AutoMappingUnknownColumnBehavior;
-import org.apache.ibatis.session.Configuration;
-import org.apache.ibatis.session.ExecutorType;
-import org.apache.ibatis.session.LocalCacheScope;
-import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.*;
 import org.apache.ibatis.type.JdbcType;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
@@ -44,7 +39,7 @@ import java.util.stream.Stream;
  * @author nieqiurong 2019/2/23.
  */
 class MybatisConfigurationTest {
-    
+
     @Test
     void testXml() throws IOException {
         Reader reader = Resources.getResourceAsReader("mybatis-config-empty.xml");
@@ -77,9 +72,9 @@ class MybatisConfigurationTest {
         Assertions.assertNull(configuration.getVfsImpl());
         Assertions.assertTrue(configuration.isUseActualParamName());
         Assertions.assertNull(configuration.getConfigurationFactory());
-        
+
     }
-    
+
     @Test
     void testBean() {
         MybatisConfiguration configuration = new MybatisConfiguration();

+ 0 - 1
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/Role.java

@@ -16,7 +16,6 @@
 package com.baomidou.mybatisplus.test;
 
 import com.baomidou.mybatisplus.annotation.TableField;
-
 import lombok.Data;
 
 @Data

+ 0 - 1
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/User.java

@@ -17,7 +17,6 @@ package com.baomidou.mybatisplus.test;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
-
 import lombok.Data;
 
 @TableName("sys_user")

+ 2 - 2
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/toolkit/BeanUtilsTest.java

@@ -15,14 +15,14 @@
  */
 package com.baomidou.mybatisplus.test.toolkit;
 
-import java.util.Map;
-
 import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
 import lombok.Getter;
 import lombok.Setter;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
+import java.util.Map;
+
 /**
  * 测试 bean utils
  *

+ 0 - 53
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parsers/BlockAttackSqlParser.java

@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.parsers;
-
-import com.baomidou.mybatisplus.core.parser.AbstractJsqlParser;
-import com.baomidou.mybatisplus.core.toolkit.Assert;
-import net.sf.jsqlparser.statement.delete.Delete;
-import net.sf.jsqlparser.statement.insert.Insert;
-import net.sf.jsqlparser.statement.select.SelectBody;
-import net.sf.jsqlparser.statement.update.Update;
-
-/**
- * 攻击 SQL 阻断解析器
- *
- * @author hubin
- * @since 2018-07-17 use {@link com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor}
- */
-@Deprecated
-public class BlockAttackSqlParser extends AbstractJsqlParser {
-
-    @Override
-    public void processInsert(Insert insert) {
-        // to do nothing
-    }
-
-    @Override
-    public void processDelete(Delete delete) {
-        Assert.notNull(delete.getWhere(), "Prohibition of full table deletion");
-    }
-
-    @Override
-    public void processUpdate(Update update) {
-        Assert.notNull(update.getWhere(), "Prohibition of table update operation");
-    }
-
-    @Override
-    public void processSelectBody(SelectBody selectBody) {
-        // to do nothing
-    }
-}

+ 0 - 94
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parsers/DynamicTableNameParser.java

@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.parsers;
-
-import com.baomidou.mybatisplus.core.parser.ISqlParser;
-import com.baomidou.mybatisplus.core.parser.SqlInfo;
-import com.baomidou.mybatisplus.core.toolkit.TableNameParser;
-import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor;
-import lombok.Data;
-import lombok.experimental.Accessors;
-import org.apache.ibatis.reflection.MetaObject;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 动态表名 SQL 解析器
- *
- * @author jobob
- * @since 2019-04-23
- * @deprecated 3.4.0 @2020-07-30 use {@link MybatisPlusInterceptor} {@link DynamicTableNameInnerInterceptor}
- */
-@Data
-@Accessors(chain = true)
-@Deprecated
-public class DynamicTableNameParser implements ISqlParser {
-    private Map<String, ITableNameHandler> tableNameHandlerMap;
-
-    /**
-     * 进行 SQL 表名名替换
-     *
-     * @param metaObject 元对象
-     * @param sql        SQL 语句
-     * @return 返回解析后的 SQL 信息
-     */
-    @Override
-    public SqlInfo parser(MetaObject metaObject, String sql) {
-        // fix-issue:https://gitee.com/baomidou/mybatis-plus/issues/I1K7Q1
-        // Assert.isFalse(CollectionUtils.isEmpty(tableNameHandlerMap), "tableNameHandlerMap is empty.");
-        if (allowProcess(metaObject)) {
-            TableNameParser parser = new TableNameParser(sql);
-            List<TableNameParser.SqlToken> names = new ArrayList<>();
-            parser.accept(names::add);
-            StringBuilder builder = new StringBuilder();
-            int last = 0;
-            for (TableNameParser.SqlToken name : names) {
-                int start = name.getStart();
-                if (start != last) {
-                    builder.append(sql, last, start);
-                    String value = name.getValue();
-                    ITableNameHandler handler = tableNameHandlerMap.get(value);
-                    if (handler != null) {
-                        builder.append(handler.dynamicTableName(metaObject, sql, value));
-                    } else {
-                        builder.append(value);
-                    }
-                }
-                last = name.getEnd();
-            }
-            if (last != sql.length()) {
-                builder.append(sql.substring(last));
-            }
-            return SqlInfo.of(builder.toString());
-        }
-        return null;
-    }
-
-    /**
-     * 判断是否允许执行
-     * <p>例如:逻辑删除只解析 delete , update 操作</p>
-     *
-     * @param metaObject 元对象
-     * @return true
-     */
-    public boolean allowProcess(MetaObject metaObject) {
-        return true;
-    }
-
-}

+ 0 - 42
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parsers/ITableNameHandler.java

@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.parsers;
-
-import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
-import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor;
-import org.apache.ibatis.reflection.MetaObject;
-
-/**
- * 动态表名处理器
- *
- * @author jobob
- * @since 2019-04-23
- * @deprecated 3.4.0 @2020-07-30 use {@link TableNameHandler} {@link MybatisPlusInterceptor} {@link DynamicTableNameInnerInterceptor}
- */
-@Deprecated
-public interface ITableNameHandler {
-
-    /**
-     * 生成动态表名
-     *
-     * @param metaObject 元对象
-     * @param sql        当前执行 SQL
-     * @param tableName  表名
-     * @return String
-     */
-    String dynamicTableName(MetaObject metaObject, String sql, String tableName);
-}

+ 0 - 367
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/IllegalSQLInterceptor.java

@@ -1,367 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins;
-
-import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
-import com.baomidou.mybatisplus.core.parser.SqlParserHelper;
-import com.baomidou.mybatisplus.core.toolkit.EncryptUtils;
-import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-import com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor;
-import lombok.Data;
-import net.sf.jsqlparser.expression.BinaryExpression;
-import net.sf.jsqlparser.expression.Expression;
-import net.sf.jsqlparser.expression.Function;
-import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
-import net.sf.jsqlparser.expression.operators.relational.InExpression;
-import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
-import net.sf.jsqlparser.parser.CCJSqlParserUtil;
-import net.sf.jsqlparser.schema.Column;
-import net.sf.jsqlparser.schema.Table;
-import net.sf.jsqlparser.statement.Statement;
-import net.sf.jsqlparser.statement.delete.Delete;
-import net.sf.jsqlparser.statement.select.Join;
-import net.sf.jsqlparser.statement.select.PlainSelect;
-import net.sf.jsqlparser.statement.select.Select;
-import net.sf.jsqlparser.statement.select.SubSelect;
-import net.sf.jsqlparser.statement.update.Update;
-import org.apache.ibatis.executor.statement.StatementHandler;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
-import org.apache.ibatis.mapping.BoundSql;
-import org.apache.ibatis.mapping.MappedStatement;
-import org.apache.ibatis.mapping.SqlCommandType;
-import org.apache.ibatis.plugin.*;
-import org.apache.ibatis.reflection.MetaObject;
-import org.apache.ibatis.reflection.SystemMetaObject;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * 由于开发人员水平参差不齐,即使订了开发规范很多人也不遵守
- * <p>SQL是影响系统性能最重要的因素,所以拦截掉垃圾SQL语句</p>
- * <br>
- * <p>拦截SQL类型的场景</p>
- * <p>1.必须使用到索引,包含left join连接字段,符合索引最左原则</p>
- * <p>必须使用索引好处,</p>
- * <p>1.1 如果因为动态SQL,bug导致update的where条件没有带上,全表更新上万条数据</p>
- * <p>1.2 如果检查到使用了索引,SQL性能基本不会太差</p>
- * <br>
- * <p>2.SQL尽量单表执行,有查询left join的语句,必须在注释里面允许该SQL运行,否则会被拦截,有left join的语句,如果不能拆成单表执行的SQL,请leader商量在做</p>
- * <p>https://gaoxianglong.github.io/shark</p>
- * <p>SQL尽量单表执行的好处</p>
- * <p>2.1 查询条件简单、易于开理解和维护;</p>
- * <p>2.2 扩展性极强;(可为分库分表做准备)</p>
- * <p>2.3 缓存利用率高;</p>
- * <p>2.在字段上使用函数</p>
- * <br>
- * <p>3.where条件为空</p>
- * <p>4.where条件使用了 !=</p>
- * <p>5.where条件使用了 not 关键字</p>
- * <p>6.where条件使用了 or 关键字</p>
- * <p>7.where条件使用了 使用子查询</p>
- *
- * @author willenfoo
- * @since 2018-03-22
- * @deprecated 3.4.0 please use {@link MybatisPlusInterceptor} {@link IllegalSQLInnerInterceptor}
- */
-@Deprecated
-@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
-public class IllegalSQLInterceptor implements Interceptor {
-
-    /**
-     * 缓存验证结果,提高性能
-     */
-    private static final Set<String> cacheValidResult = new HashSet<>();
-
-    private static final Log logger = LogFactory.getLog(IllegalSQLInterceptor.class);
-
-    /**
-     * 缓存表的索引信息
-     */
-    private static final Map<String, List<IndexInfo>> indexInfoMap = new ConcurrentHashMap<>();
-
-    /**
-     * 验证expression对象是不是 or、not等等
-     *
-     * @param expression ignore
-     */
-    private static void validExpression(Expression expression) {
-        //where条件使用了 or 关键字
-        if (expression instanceof OrExpression) {
-            OrExpression orExpression = (OrExpression) expression;
-            throw new MybatisPlusException("非法SQL,where条件中不能使用【or】关键字,错误or信息:" + orExpression.toString());
-        } else if (expression instanceof NotEqualsTo) {
-            NotEqualsTo notEqualsTo = (NotEqualsTo) expression;
-            throw new MybatisPlusException("非法SQL,where条件中不能使用【!=】关键字,错误!=信息:" + notEqualsTo.toString());
-        } else if (expression instanceof BinaryExpression) {
-            BinaryExpression binaryExpression = (BinaryExpression) expression;
-            // 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());
-            }
-            if (binaryExpression.getRightExpression() instanceof SubSelect) {
-                SubSelect subSelect = (SubSelect) binaryExpression.getRightExpression();
-                throw new MybatisPlusException("非法SQL,where条件中不能使用子查询,错误子查询SQL信息:" + subSelect.toString());
-            }
-        } else if (expression instanceof InExpression) {
-            InExpression inExpression = (InExpression) expression;
-            if (inExpression.getRightItemsList() instanceof SubSelect) {
-                SubSelect subSelect = (SubSelect) inExpression.getRightItemsList();
-                throw new MybatisPlusException("非法SQL,where条件中不能使用子查询,错误子查询SQL信息:" + subSelect.toString());
-            }
-        }
-
-    }
-
-    /**
-     * 如果SQL用了 left Join,验证是否有or、not等等,并且验证是否使用了索引
-     *
-     * @param joins      ignore
-     * @param table      ignore
-     * @param connection ignore
-     */
-    private static void validJoins(List<Join> joins, Table table, Connection connection) {
-        //允许执行join,验证jion是否使用索引等等
-        if (joins != null) {
-            for (Join join : joins) {
-                Table rightTable = (Table) join.getRightItem();
-                Expression expression = join.getOnExpression();
-                validWhere(expression, table, rightTable, connection);
-            }
-        }
-    }
-
-    /**
-     * 检查是否使用索引
-     *
-     * @param table      ignore
-     * @param columnName ignore
-     * @param connection ignore
-     */
-    private static void validUseIndex(Table table, String columnName, Connection connection) {
-        //是否使用索引
-        boolean useIndexFlag = false;
-
-        String tableInfo = table.getName();
-        //表存在的索引
-        String dbName = null;
-        String tableName;
-        String[] tableArray = tableInfo.split("\\.");
-        if (tableArray.length == 1) {
-            tableName = tableArray[0];
-        } else {
-            dbName = tableArray[0];
-            tableName = tableArray[1];
-        }
-        List<IndexInfo> indexInfos = getIndexInfos(dbName, tableName, connection);
-        for (IndexInfo indexInfo : indexInfos) {
-            if (null != columnName && columnName.equalsIgnoreCase(indexInfo.getColumnName())) {
-                useIndexFlag = true;
-                break;
-            }
-        }
-        if (!useIndexFlag) {
-            throw new MybatisPlusException("非法SQL,SQL未使用到索引, table:" + table + ", columnName:" + columnName);
-        }
-    }
-
-    /**
-     * 验证where条件的字段,是否有not、or等等,并且where的第一个字段,必须使用索引
-     *
-     * @param expression ignore
-     * @param table      ignore
-     * @param connection ignore
-     */
-    private static void validWhere(Expression expression, Table table, Connection connection) {
-        validWhere(expression, table, null, connection);
-    }
-
-    /**
-     * 验证where条件的字段,是否有not、or等等,并且where的第一个字段,必须使用索引
-     *
-     * @param expression ignore
-     * @param table      ignore
-     * @param joinTable  ignore
-     * @param connection ignore
-     */
-    private static void validWhere(Expression expression, Table table, Table joinTable, Connection connection) {
-        validExpression(expression);
-        if (expression instanceof BinaryExpression) {
-            //获得左边表达式
-            Expression leftExpression = ((BinaryExpression) expression).getLeftExpression();
-            validExpression(leftExpression);
-
-            //如果左边表达式为Column对象,则直接获得列名
-            if (leftExpression instanceof Column) {
-                Expression rightExpression = ((BinaryExpression) expression).getRightExpression();
-                if (joinTable != null && rightExpression instanceof Column) {
-                    if (Objects.equals(((Column) rightExpression).getTable().getName(), table.getAlias().getName())) {
-                        validUseIndex(table, ((Column) rightExpression).getColumnName(), connection);
-                        validUseIndex(joinTable, ((Column) leftExpression).getColumnName(), connection);
-                    } else {
-                        validUseIndex(joinTable, ((Column) rightExpression).getColumnName(), connection);
-                        validUseIndex(table, ((Column) leftExpression).getColumnName(), connection);
-                    }
-                } else {
-                    //获得列名
-                    validUseIndex(table, ((Column) leftExpression).getColumnName(), connection);
-                }
-            }
-            //如果BinaryExpression,进行迭代
-            else if (leftExpression instanceof BinaryExpression) {
-                validWhere(leftExpression, table, joinTable, connection);
-            }
-
-            //获得右边表达式,并分解
-            Expression rightExpression = ((BinaryExpression) expression).getRightExpression();
-            validExpression(rightExpression);
-        }
-    }
-
-    /**
-     * 得到表的索引信息
-     *
-     * @param dbName    ignore
-     * @param tableName ignore
-     * @param conn      ignore
-     * @return ignore
-     */
-    public static List<IndexInfo> getIndexInfos(String dbName, String tableName, Connection conn) {
-        return getIndexInfos(null, dbName, tableName, conn);
-    }
-
-    /**
-     * 得到表的索引信息
-     *
-     * @param key       ignore
-     * @param dbName    ignore
-     * @param tableName ignore
-     * @param conn      ignore
-     * @return ignore
-     */
-    public static List<IndexInfo> getIndexInfos(String key, String dbName, String tableName, Connection conn) {
-        List<IndexInfo> indexInfos = null;
-        if (StringUtils.isNotBlank(key)) {
-            indexInfos = indexInfoMap.get(key);
-        }
-        if (indexInfos == null || indexInfos.isEmpty()) {
-            ResultSet rs;
-            try {
-                DatabaseMetaData metadata = conn.getMetaData();
-                String catalog = StringUtils.isBlank(dbName) ? conn.getCatalog() : dbName;
-                String schema = StringUtils.isBlank(dbName) ? conn.getSchema() : dbName;
-                rs = metadata.getIndexInfo(catalog, schema, tableName, false, true);
-                indexInfos = new ArrayList<>();
-                while (rs.next()) {
-                    //索引中的列序列号等于1,才有效
-                    if (Objects.equals(rs.getString(8), "1")) {
-                        IllegalSQLInterceptor.IndexInfo indexInfo = new IllegalSQLInterceptor.IndexInfo();
-                        indexInfo.setDbName(rs.getString(1));
-                        indexInfo.setTableName(rs.getString(3));
-                        indexInfo.setColumnName(rs.getString(9));
-                        indexInfos.add(indexInfo);
-                    }
-                }
-                if (StringUtils.isNotBlank(key)) {
-                    indexInfoMap.put(key, indexInfos);
-                }
-            } catch (SQLException e) {
-                e.printStackTrace();
-            }
-        }
-        return indexInfos;
-    }
-
-    @Override
-    public Object intercept(Invocation invocation) throws Throwable {
-        StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
-        MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
-        // 如果是insert操作, 或者 @SqlParser(filter = true) 跳过该方法解析 , 不进行验证
-        MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
-        if (SqlCommandType.INSERT.equals(mappedStatement.getSqlCommandType()) || SqlParserHelper.getSqlParserInfo(metaObject)) {
-            return invocation.proceed();
-        }
-        BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
-        String originalSql = boundSql.getSql();
-        logger.debug("检查SQL是否合规,SQL:" + originalSql);
-        String md5Base64 = EncryptUtils.md5Base64(originalSql);
-        if (cacheValidResult.contains(md5Base64)) {
-            logger.debug("该SQL已验证,无需再次验证,,SQL:" + originalSql);
-            return invocation.proceed();
-        }
-        Connection connection = (Connection) invocation.getArgs()[0];
-        Statement statement = CCJSqlParserUtil.parse(originalSql);
-        Expression where = null;
-        Table table = null;
-        List<Join> joins = null;
-        if (statement instanceof Select) {
-            PlainSelect plainSelect = (PlainSelect) ((Select) statement).getSelectBody();
-            where = plainSelect.getWhere();
-            table = (Table) plainSelect.getFromItem();
-            joins = plainSelect.getJoins();
-        } else if (statement instanceof Update) {
-            Update update = (Update) statement;
-            where = update.getWhere();
-            table = update.getTable();
-            joins = update.getJoins();
-        } else if (statement instanceof Delete) {
-            Delete delete = (Delete) statement;
-            where = delete.getWhere();
-            table = delete.getTable();
-            joins = delete.getJoins();
-        }
-        //where条件不能为空
-        if (where == null) {
-            throw new MybatisPlusException("非法SQL,必须要有where条件");
-        }
-        validWhere(where, table, connection);
-        validJoins(joins, table, connection);
-        //缓存验证结果
-        cacheValidResult.add(md5Base64);
-        return invocation.proceed();
-    }
-
-    @Override
-    public Object plugin(Object target) {
-        if (target instanceof StatementHandler) {
-            return Plugin.wrap(target, this);
-        }
-        return target;
-    }
-
-    /**
-     * 索引对象
-     */
-    @Data
-    private static class IndexInfo {
-
-        private String dbName;
-
-        private String tableName;
-
-        private String columnName;
-    }
-}

+ 0 - 145
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/OptimisticLockerInterceptor.java

@@ -1,145 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins;
-
-import com.baomidou.mybatisplus.annotation.Version;
-import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
-import com.baomidou.mybatisplus.core.metadata.TableInfo;
-import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
-import com.baomidou.mybatisplus.core.toolkit.Constants;
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
-import org.apache.ibatis.executor.Executor;
-import org.apache.ibatis.mapping.MappedStatement;
-import org.apache.ibatis.mapping.SqlCommandType;
-import org.apache.ibatis.plugin.*;
-
-import java.lang.reflect.Field;
-import java.sql.Timestamp;
-import java.time.LocalDateTime;
-import java.util.Date;
-import java.util.Map;
-
-/**
- * Optimistic Lock Light version
- * <p>Intercept on {@link Executor}.update;</p>
- * <p>Support version types: int/Integer, long/Long, java.util.Date, java.sql.Timestamp</p>
- * <p>For extra types, please define a subclass and override {@code getUpdatedVersionVal}() method.</p>
- * <br>
- * <p>How to use?</p>
- * <p>(1) Define an Entity and add {@link Version} annotation on one entity field.</p>
- * <p>(2) Add {@link OptimisticLockerInterceptor} into mybatis plugin.</p>
- * <br>
- * <p>How to work?</p>
- * <p>if update entity with version column=1:</p>
- * <p>(1) no {@link OptimisticLockerInterceptor}:</p>
- * <p>SQL: update tbl_test set name='abc' where id=100001;</p>
- * <p>(2) add {@link OptimisticLockerInterceptor}:</p>
- * <p>SQL: update tbl_test set name='abc',version=2 where id=100001 and version=1;</p>
- *
- * @author yuxiaobin
- * @since 2017/5/24
- * @deprecated 3.4.0 please use {@link MybatisPlusInterceptor} {@link OptimisticLockerInnerInterceptor}
- */
-@Deprecated
-@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
-public class OptimisticLockerInterceptor implements Interceptor {
-
-    private static final String PARAM_UPDATE_METHOD_NAME = "update";
-
-    @Override
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    public Object intercept(Invocation invocation) throws Throwable {
-        Object[] args = invocation.getArgs();
-        MappedStatement ms = (MappedStatement) args[0];
-        if (SqlCommandType.UPDATE != ms.getSqlCommandType()) {
-            return invocation.proceed();
-        }
-        Object param = args[1];
-        if (param instanceof Map) {
-            Map map = (Map) param;
-            //updateById(et), update(et, wrapper);
-            Object et = map.getOrDefault(Constants.ENTITY, null);
-            if (et != null) {
-                // entity
-                String methodId = ms.getId();
-                String methodName = methodId.substring(methodId.lastIndexOf(StringPool.DOT) + 1);
-                TableInfo tableInfo = TableInfoHelper.getTableInfo(et.getClass());
-                if (tableInfo == null || !tableInfo.isWithVersion()) {
-                    return invocation.proceed();
-                }
-                TableFieldInfo fieldInfo = tableInfo.getVersionFieldInfo();
-                Field versionField = fieldInfo.getField();
-                // 旧的 version 值
-                Object originalVersionVal = versionField.get(et);
-                if (originalVersionVal == null) {
-                    return invocation.proceed();
-                }
-                String versionColumn = fieldInfo.getColumn();
-                // 新的 version 值
-                Object updatedVersionVal = this.getUpdatedVersionVal(fieldInfo.getPropertyType(), originalVersionVal);
-                if (PARAM_UPDATE_METHOD_NAME.equals(methodName)) {
-                    AbstractWrapper<?, ?, ?> aw = (AbstractWrapper<?, ?, ?>) map.getOrDefault(Constants.WRAPPER, null);
-                    if (aw == null) {
-                        UpdateWrapper<?> uw = new UpdateWrapper<>();
-                        uw.eq(versionColumn, originalVersionVal);
-                        map.put(Constants.WRAPPER, uw);
-                    } else {
-                        aw.apply(versionColumn + " = {0}", originalVersionVal);
-                    }
-                } else {
-                    map.put(Constants.MP_OPTLOCK_VERSION_ORIGINAL, originalVersionVal);
-                }
-                versionField.set(et, updatedVersionVal);
-                return invocation.proceed();
-            }
-        }
-        return invocation.proceed();
-    }
-
-    /**
-     * This method provides the control for version value.<BR>
-     * Returned value type must be the same as original one.
-     *
-     * @param originalVersionVal ignore
-     * @return updated version val
-     */
-    protected Object getUpdatedVersionVal(Class<?> clazz, Object originalVersionVal) {
-        if (long.class.equals(clazz) || Long.class.equals(clazz)) {
-            return ((long) originalVersionVal) + 1;
-        } else if (int.class.equals(clazz) || Integer.class.equals(clazz)) {
-            return ((int) originalVersionVal) + 1;
-        } else if (Date.class.equals(clazz)) {
-            return new Date();
-        } else if (Timestamp.class.equals(clazz)) {
-            return new Timestamp(System.currentTimeMillis());
-        } else if (LocalDateTime.class.equals(clazz)) {
-            return LocalDateTime.now();
-        }
-        //not supported type, return original val.
-        return originalVersionVal;
-    }
-
-    @Override
-    public Object plugin(Object target) {
-        if (target instanceof Executor) {
-            return Plugin.wrap(target, this);
-        }
-        return target;
-    }
-}

+ 0 - 332
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/PaginationInterceptor.java

@@ -1,332 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins;
-
-import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.core.MybatisParameterHandler;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.metadata.OrderItem;
-import com.baomidou.mybatisplus.core.parser.ISqlParser;
-import com.baomidou.mybatisplus.core.parser.SqlInfo;
-import com.baomidou.mybatisplus.core.toolkit.*;
-import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler;
-import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.pagination.DialectFactory;
-import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
-import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect;
-import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
-import com.baomidou.mybatisplus.extension.toolkit.PropertyMapper;
-import com.baomidou.mybatisplus.extension.toolkit.SqlParserUtils;
-import lombok.Setter;
-import lombok.experimental.Accessors;
-import net.sf.jsqlparser.JSQLParserException;
-import net.sf.jsqlparser.parser.CCJSqlParserUtil;
-import net.sf.jsqlparser.schema.Column;
-import net.sf.jsqlparser.statement.select.*;
-import org.apache.ibatis.executor.statement.StatementHandler;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
-import org.apache.ibatis.mapping.*;
-import org.apache.ibatis.plugin.*;
-import org.apache.ibatis.reflection.MetaObject;
-import org.apache.ibatis.reflection.SystemMetaObject;
-import org.apache.ibatis.session.Configuration;
-import org.apache.ibatis.session.RowBounds;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * 分页拦截器
- *
- * @author hubin
- * @since 2016-01-23
- * @deprecated 3.4.0 please use {@link MybatisPlusInterceptor} {@link PaginationInnerInterceptor}
- */
-@Setter
-@Deprecated
-@Accessors(chain = true)
-@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
-public class PaginationInterceptor extends AbstractSqlParserHandler implements Interceptor {
-
-    protected static final Log logger = LogFactory.getLog(PaginationInterceptor.class);
-    /**
-     * COUNT SQL 解析
-     */
-    protected ISqlParser countSqlParser;
-    /**
-     * 溢出总页数后是否进行处理
-     */
-    protected boolean overflow = false;
-    /**
-     * 单页限制 500 条,小于 0 如 -1 不受限制
-     */
-    protected long limit = 500L;
-    /**
-     * 数据库类型
-     *
-     * @since 3.3.1
-     */
-    private DbType dbType;
-    /**
-     * 方言实现类
-     *
-     * @since 3.3.1
-     */
-    private IDialect dialect;
-    /**
-     * 方言类型(数据库名,全小写) <br>
-     * 如果用的我们支持分页的数据库但获取数据库类型不正确则可以配置该值进行校正
-     *
-     * @deprecated 3.3.1 {@link #setDbType(DbType)}
-     */
-    @Deprecated
-    protected String dialectType;
-    /**
-     * 方言实现类<br>
-     * 注意!实现 com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect 接口的子类
-     *
-     * @deprecated 3.3.1 {@link #setDialect(IDialect)}
-     */
-    @Deprecated
-    protected String dialectClazz;
-
-    /**
-     * 查询SQL拼接Order By
-     *
-     * @param originalSql 需要拼接的SQL
-     * @param page        page对象
-     * @return ignore
-     */
-    public String concatOrderBy(String originalSql, IPage<?> page) {
-        if (CollectionUtils.isNotEmpty(page.orders())) {
-            try {
-                List<OrderItem> orderList = page.orders();
-                Select selectStatement = (Select) CCJSqlParserUtil.parse(originalSql);
-                if (selectStatement.getSelectBody() instanceof PlainSelect) {
-                    PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
-                    List<OrderByElement> orderByElements = plainSelect.getOrderByElements();
-                    List<OrderByElement> orderByElementsReturn = addOrderByElements(orderList, orderByElements);
-                    plainSelect.setOrderByElements(orderByElementsReturn);
-                    return plainSelect.toString();
-                } else if (selectStatement.getSelectBody() instanceof SetOperationList) {
-                    SetOperationList setOperationList = (SetOperationList) selectStatement.getSelectBody();
-                    List<OrderByElement> orderByElements = setOperationList.getOrderByElements();
-                    List<OrderByElement> orderByElementsReturn = addOrderByElements(orderList, orderByElements);
-                    setOperationList.setOrderByElements(orderByElementsReturn);
-                    return setOperationList.toString();
-                } else if (selectStatement.getSelectBody() instanceof WithItem) {
-                    // todo: don't known how to resole
-                    return originalSql;
-                } else {
-                    return originalSql;
-                }
-
-            } catch (JSQLParserException e) {
-                logger.warn("failed to concat orderBy from IPage, exception=" + e.getMessage());
-            }
-        }
-        return originalSql;
-    }
-
-    private static List<OrderByElement> addOrderByElements(List<OrderItem> orderList, List<OrderByElement> orderByElements) {
-        orderByElements = CollectionUtils.isEmpty(orderByElements) ? new ArrayList<>(orderList.size()) : orderByElements;
-        List<OrderByElement> orderByElementList = orderList.stream()
-            .filter(item -> StringUtils.isNotBlank(item.getColumn()))
-            .map(item -> {
-                OrderByElement element = new OrderByElement();
-                element.setExpression(new Column(item.getColumn()));
-                element.setAsc(item.isAsc());
-                element.setAscDescPresent(true);
-                return element;
-            }).collect(Collectors.toList());
-        orderByElements.addAll(orderByElementList);
-        return orderByElements;
-    }
-
-    /**
-     * Physical Page Interceptor for all the queries with parameter {@link RowBounds}
-     */
-    @SuppressWarnings("unchecked")
-    @Override
-    public Object intercept(Invocation invocation) throws Throwable {
-        StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
-        MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
-
-        // SQL 解析
-        this.sqlParser(metaObject);
-
-        // 先判断是不是SELECT操作  (2019-04-10 00:37:31 跳过存储过程)
-        MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
-        if (SqlCommandType.SELECT != mappedStatement.getSqlCommandType()
-            || StatementType.CALLABLE == mappedStatement.getStatementType()) {
-            return invocation.proceed();
-        }
-
-        // 针对定义了rowBounds,做为mapper接口方法的参数
-        BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
-        Object paramObj = boundSql.getParameterObject();
-
-        // 判断参数里是否有page对象
-        IPage<?> page = ParameterUtils.findPage(paramObj).orElse(null);
-
-        /*
-         * 不需要分页的场合,如果 size 小于 0 返回结果集
-         */
-        if (null == page || page.getSize() < 0) {
-            return invocation.proceed();
-        }
-
-        if (this.limit > 0 && this.limit <= page.getSize()) {
-            //处理单页条数限制
-            handlerLimit(page);
-        }
-
-        String originalSql = boundSql.getSql();
-        Connection connection = (Connection) invocation.getArgs()[0];
-
-        if (page.isSearchCount() && !page.isHitCount()) {
-            SqlInfo sqlInfo = SqlParserUtils.getOptimizeCountSql(page.optimizeCountSql(), countSqlParser, originalSql, metaObject);
-            this.queryTotal(sqlInfo.getSql(), mappedStatement, boundSql, page, connection);
-            if (!this.continueLimit(page)) {
-                return null;
-            }
-        }
-        DbType dbType = this.dbType == null ? JdbcUtils.getDbType(connection.getMetaData().getURL()) : this.dbType;
-        IDialect dialect = Optional.ofNullable(this.dialect).orElseGet(() -> DialectFactory.getDialect(dbType));
-        String buildSql = concatOrderBy(originalSql, page);
-        DialectModel model = dialect.buildPaginationSql(buildSql, page.offset(), page.getSize());
-        Configuration configuration = mappedStatement.getConfiguration();
-        List<ParameterMapping> mappings = new ArrayList<>(boundSql.getParameterMappings());
-        Map<String, Object> additionalParameters = (Map<String, Object>) metaObject.getValue("delegate.boundSql.additionalParameters");
-        model.consumers(mappings, configuration, additionalParameters);
-        metaObject.setValue("delegate.boundSql.sql", model.getDialectSql());
-        metaObject.setValue("delegate.boundSql.parameterMappings", mappings);
-        return invocation.proceed();
-    }
-
-    /**
-     * 判断是否继续执行 Limit 逻辑
-     *
-     * @param page 分页对象
-     * @return
-     */
-    protected boolean continueLimit(IPage<?> page) {
-        if (page.getTotal() <= 0) {
-            return false;
-        }
-        if (page.getCurrent() > page.getPages()) {
-            if (this.overflow) {
-                //溢出总页数处理
-                handlerOverflow(page);
-            } else {
-                // 超过最大范围,未设置溢出逻辑中断 list 执行
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * 处理超出分页条数限制,默认归为限制数
-     *
-     * @param page IPage
-     */
-    protected void handlerLimit(IPage<?> page) {
-        page.setSize(this.limit);
-    }
-
-    /**
-     * 查询总记录条数
-     *
-     * @param sql             count sql
-     * @param mappedStatement MappedStatement
-     * @param boundSql        BoundSql
-     * @param page            IPage
-     * @param connection      Connection
-     * @return true 继续执行 false 中断 list 执行
-     */
-    protected void queryTotal(String sql, MappedStatement mappedStatement, BoundSql boundSql, IPage<?> page, Connection connection) {
-        try (PreparedStatement statement = connection.prepareStatement(sql)) {
-            MybatisParameterHandler parameterHandler = new MybatisParameterHandler(mappedStatement, boundSql.getParameterObject(), boundSql);
-            parameterHandler.setParameters(statement);
-            long total = 0;
-            try (ResultSet resultSet = statement.executeQuery()) {
-                if (resultSet.next()) {
-                    total = resultSet.getLong(1);
-                }
-            }
-            page.setTotal(total);
-        } catch (Exception e) {
-            throw ExceptionUtils.mpe("Error: Method queryTotal execution error of sql : \n %s \n", e, sql);
-        }
-    }
-
-    /**
-     * 处理页数溢出,默认设置为第一页
-     *
-     * @param page IPage
-     */
-    protected void handlerOverflow(IPage<?> page) {
-        page.setCurrent(1);
-    }
-
-    @Override
-    public Object plugin(Object target) {
-        if (target instanceof StatementHandler) {
-            return Plugin.wrap(target, this);
-        }
-        return target;
-    }
-
-    @Override
-    public void setProperties(Properties prop) {
-        PropertyMapper.newInstance(prop)
-            .whenNotBlack("countSqlParser", ClassUtils::newInstance, this::setCountSqlParser)
-            .whenNotBlack("overflow", Boolean::parseBoolean, this::setOverflow)
-            .whenNotBlack("dialectType", this::setDialectType)
-            .whenNotBlack("dialectClazz", this::setDialectClazz)
-            .whenNotBlack("dbType", DbType::getDbType, this::setDbType)
-            .whenNotBlack("dialect", ClassUtils::newInstance, this::setDialect)
-            .whenNotBlack("limit", Long::parseLong, this::setLimit);
-    }
-
-    /**
-     * 设置方言类型
-     *
-     * @param dialectType 数据库名,全小写
-     * @deprecated 3.3.1 {@link #setDbType(DbType)}
-     */
-    @Deprecated
-    public void setDialectType(String dialectType) {
-        setDbType(DbType.getDbType(dialectType));
-    }
-
-    /**
-     * 设置方言实现类
-     *
-     * @param dialectClazz 方言实现类
-     * @deprecated 3.3.1 {@link #setDialect(IDialect)}}
-     */
-    @Deprecated
-    public void setDialectClazz(String dialectClazz) {
-        setDialect(DialectFactory.getDialect(dialectClazz));
-    }
-
-}

+ 0 - 72
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/SqlExplainInterceptor.java

@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins;
-
-import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler;
-import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.experimental.Accessors;
-import org.apache.ibatis.executor.Executor;
-import org.apache.ibatis.executor.statement.StatementHandler;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
-import org.apache.ibatis.mapping.MappedStatement;
-import org.apache.ibatis.mapping.SqlCommandType;
-import org.apache.ibatis.plugin.*;
-import org.apache.ibatis.reflection.SystemMetaObject;
-import org.apache.ibatis.session.Configuration;
-import org.apache.ibatis.session.RowBounds;
-
-/**
- * 防止全表更新与删除
- *
- * @author hubin
- * @since 2016-08-16
- * @deprecated 3.4.0 please use {@link MybatisPlusInterceptor} {@link BlockAttackInnerInterceptor}
- */
-@Data
-@Accessors(chain = true)
-@EqualsAndHashCode(callSuper = true)
-@Deprecated
-@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
-public class SqlExplainInterceptor extends AbstractSqlParserHandler implements Interceptor {
-
-    @SuppressWarnings("unused")
-    private static final Log logger = LogFactory.getLog(SqlExplainInterceptor.class);
-
-    @Override
-    public Object intercept(Invocation invocation) throws Throwable {
-        Object[] args = invocation.getArgs();
-        MappedStatement ms = (MappedStatement) args[0];
-        if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
-            Object parameter = args[1];
-            Configuration configuration = ms.getConfiguration();
-            Object target = invocation.getTarget();
-            StatementHandler handler = configuration.newStatementHandler((Executor) target, ms, parameter, RowBounds.DEFAULT, null, null);
-            this.sqlParser(SystemMetaObject.forObject(handler));
-        }
-        return invocation.proceed();
-    }
-
-    @Override
-    public Object plugin(Object target) {
-        if (target instanceof Executor) {
-            return Plugin.wrap(target, this);
-        }
-        return target;
-    }
-}

+ 0 - 347
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/FakeTenantLineInnerInterceptor.java

@@ -1,347 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.inner;
-
-import com.baomidou.mybatisplus.core.parser.SqlParserHelper;
-import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
-import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
-import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-import com.baomidou.mybatisplus.extension.parser.JsqlParserSupport;
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
-import com.baomidou.mybatisplus.extension.toolkit.PropertyMapper;
-import lombok.*;
-import net.sf.jsqlparser.expression.BinaryExpression;
-import net.sf.jsqlparser.expression.Expression;
-import net.sf.jsqlparser.expression.Parenthesis;
-import net.sf.jsqlparser.expression.ValueListExpression;
-import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
-import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
-import net.sf.jsqlparser.expression.operators.relational.*;
-import net.sf.jsqlparser.schema.Column;
-import net.sf.jsqlparser.schema.Table;
-import net.sf.jsqlparser.statement.delete.Delete;
-import net.sf.jsqlparser.statement.insert.Insert;
-import net.sf.jsqlparser.statement.select.*;
-import net.sf.jsqlparser.statement.update.Update;
-import org.apache.ibatis.executor.Executor;
-import org.apache.ibatis.executor.statement.StatementHandler;
-import org.apache.ibatis.mapping.BoundSql;
-import org.apache.ibatis.mapping.MappedStatement;
-import org.apache.ibatis.mapping.SqlCommandType;
-import org.apache.ibatis.session.ResultHandler;
-import org.apache.ibatis.session.RowBounds;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * @author hubin
- * @since 3.4.0
- * @deprecated 只为了过度  TenantSqlParser
- */
-@Deprecated
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@ToString(callSuper = true)
-@EqualsAndHashCode(callSuper = true)
-@SuppressWarnings({"rawtypes"})
-public class FakeTenantLineInnerInterceptor extends JsqlParserSupport implements InnerInterceptor {
-
-    private TenantHandler tenantHandler;
-
-    @Override
-    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
-        if (InterceptorIgnoreHelper.willIgnoreTenantLine(ms.getId())) return;
-        if (SqlParserHelper.getSqlParserInfo(ms)) return;
-        PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql);
-        mpBs.sql(parserSingle(mpBs.sql(), null));
-    }
-
-    @Override
-    public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) {
-        PluginUtils.MPStatementHandler mpSh = PluginUtils.mpStatementHandler(sh);
-        MappedStatement ms = mpSh.mappedStatement();
-        SqlCommandType sct = ms.getSqlCommandType();
-        if (sct == SqlCommandType.INSERT || sct == SqlCommandType.UPDATE || sct == SqlCommandType.DELETE) {
-            if (InterceptorIgnoreHelper.willIgnoreTenantLine(ms.getId())) return;
-            if (SqlParserHelper.getSqlParserInfo(ms)) return;
-            PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
-            mpBs.sql(parserMulti(mpBs.sql(), null));
-        }
-    }
-
-    @Override
-    protected void processSelect(Select select, int index, String sql, Object obj) {
-        processSelectBody(select.getSelectBody());
-    }
-
-    protected void processSelectBody(SelectBody selectBody) {
-        if (selectBody instanceof PlainSelect) {
-            processPlainSelect((PlainSelect) selectBody);
-        } else if (selectBody instanceof WithItem) {
-            WithItem withItem = (WithItem) selectBody;
-            if (withItem.getSelectBody() != null) {
-                processSelectBody(withItem.getSelectBody());
-            }
-        } else {
-            SetOperationList operationList = (SetOperationList) selectBody;
-            if (operationList.getSelects() != null && operationList.getSelects().size() > 0) {
-                operationList.getSelects().forEach(this::processSelectBody);
-            }
-        }
-    }
-
-    @Override
-    protected void processInsert(Insert insert, int index, String sql, Object obj) {
-        if (tenantHandler.doTableFilter(insert.getTable().getName())) {
-            // 过滤退出执行
-            return;
-        }
-        insert.getColumns().add(new Column(tenantHandler.getTenantIdColumn()));
-        if (insert.getSelect() != null) {
-            processPlainSelect((PlainSelect) insert.getSelect().getSelectBody(), true);
-        } else if (insert.getItemsList() != null) {
-            // fixed github pull/295
-            ItemsList itemsList = insert.getItemsList();
-            if (itemsList instanceof MultiExpressionList) {
-                ((MultiExpressionList) itemsList).getExprList().forEach(el -> el.getExpressions().add(tenantHandler.getTenantId(false)));
-            } else {
-                ((ExpressionList) insert.getItemsList()).getExpressions().add(tenantHandler.getTenantId(false));
-            }
-        } else {
-            throw ExceptionUtils.mpe("Failed to process multiple-table update, please exclude the tableName or statementId");
-        }
-    }
-
-    /**
-     * update 语句处理
-     */
-    @Override
-    protected void processUpdate(Update update, int index, String sql, Object obj) {
-        final Table table = update.getTable();
-        if (tenantHandler.doTableFilter(table.getName())) {
-            // 过滤退出执行
-            return;
-        }
-        update.setWhere(this.andExpression(table, update.getWhere()));
-    }
-
-    /**
-     * delete 语句处理
-     */
-    @Override
-    protected void processDelete(Delete delete, int index, String sql, Object obj) {
-        if (tenantHandler.doTableFilter(delete.getTable().getName())) {
-            // 过滤退出执行
-            return;
-        }
-        delete.setWhere(this.andExpression(delete.getTable(), delete.getWhere()));
-    }
-
-    /**
-     * delete update 语句 where 处理
-     */
-    protected BinaryExpression andExpression(Table table, Expression where) {
-        //获得where条件表达式
-        EqualsTo equalsTo = new EqualsTo();
-        equalsTo.setLeftExpression(this.getAliasColumn(table));
-        equalsTo.setRightExpression(tenantHandler.getTenantId(false));
-        if (null != where) {
-            if (where instanceof OrExpression) {
-                return new AndExpression(equalsTo, new Parenthesis(where));
-            } else {
-                return new AndExpression(equalsTo, where);
-            }
-        }
-        return equalsTo;
-    }
-
-    /**
-     * 处理 PlainSelect
-     */
-    protected void processPlainSelect(PlainSelect plainSelect) {
-        processPlainSelect(plainSelect, false);
-    }
-
-    /**
-     * 处理 PlainSelect
-     *
-     * @param plainSelect ignore
-     * @param addColumn   是否添加租户列,insert into select语句中需要
-     */
-    protected void processPlainSelect(PlainSelect plainSelect, boolean addColumn) {
-        FromItem fromItem = plainSelect.getFromItem();
-        if (fromItem instanceof Table) {
-            Table fromTable = (Table) fromItem;
-            if (!tenantHandler.doTableFilter(fromTable.getName())) {
-                //#1186 github
-                plainSelect.setWhere(builderExpression(plainSelect.getWhere(), fromTable));
-                if (addColumn) {
-                    plainSelect.getSelectItems().add(new SelectExpressionItem(new Column(tenantHandler.getTenantIdColumn())));
-                }
-            }
-        } else {
-            processFromItem(fromItem);
-        }
-        List<Join> joins = plainSelect.getJoins();
-        if (joins != null && joins.size() > 0) {
-            joins.forEach(j -> {
-                processJoin(j);
-                processFromItem(j.getRightItem());
-            });
-        }
-    }
-
-    /**
-     * 处理子查询等
-     */
-    protected void processFromItem(FromItem fromItem) {
-        if (fromItem instanceof SubJoin) {
-            SubJoin subJoin = (SubJoin) fromItem;
-            if (subJoin.getJoinList() != null) {
-                subJoin.getJoinList().forEach(this::processJoin);
-            }
-            if (subJoin.getLeft() != null) {
-                processFromItem(subJoin.getLeft());
-            }
-        } else if (fromItem instanceof SubSelect) {
-            SubSelect subSelect = (SubSelect) fromItem;
-            if (subSelect.getSelectBody() != null) {
-                processSelectBody(subSelect.getSelectBody());
-            }
-        } else if (fromItem instanceof ValuesList) {
-            logger.debug("Perform a subquery, if you do not give us feedback");
-        } else if (fromItem instanceof LateralSubSelect) {
-            LateralSubSelect lateralSubSelect = (LateralSubSelect) fromItem;
-            if (lateralSubSelect.getSubSelect() != null) {
-                SubSelect subSelect = lateralSubSelect.getSubSelect();
-                if (subSelect.getSelectBody() != null) {
-                    processSelectBody(subSelect.getSelectBody());
-                }
-            }
-        }
-    }
-
-    /**
-     * 处理联接语句
-     */
-    protected void processJoin(Join join) {
-        if (join.getRightItem() instanceof Table) {
-            Table fromTable = (Table) join.getRightItem();
-            if (this.tenantHandler.doTableFilter(fromTable.getName())) {
-                // 过滤退出执行
-                return;
-            }
-            join.setOnExpression(builderExpression(join.getOnExpression(), fromTable));
-        }
-    }
-
-    /**
-     * 处理条件:
-     * 支持 getTenantHandler().getTenantId()是一个完整的表达式:tenant in (1,2)
-     * 默认tenantId的表达式: LongValue(1)这种依旧支持
-     */
-    protected Expression builderExpression(Expression currentExpression, Table table) {
-        final Expression tenantExpression = tenantHandler.getTenantId(true);
-        Expression appendExpression = this.processTableAlias4CustomizedTenantIdExpression(tenantExpression, table);
-        if (currentExpression == null) {
-            return appendExpression;
-        }
-        if (currentExpression instanceof BinaryExpression) {
-            BinaryExpression binaryExpression = (BinaryExpression) currentExpression;
-            doExpression(binaryExpression.getLeftExpression());
-            doExpression(binaryExpression.getRightExpression());
-        } else if (currentExpression instanceof InExpression) {
-            InExpression inExp = (InExpression) currentExpression;
-            ItemsList rightItems = inExp.getRightItemsList();
-            if (rightItems instanceof SubSelect) {
-                processSelectBody(((SubSelect) rightItems).getSelectBody());
-            }
-        }
-        if (currentExpression instanceof OrExpression) {
-            return new AndExpression(new Parenthesis(currentExpression), appendExpression);
-        } else {
-            return new AndExpression(currentExpression, appendExpression);
-        }
-    }
-
-    protected void doExpression(Expression expression) {
-        if (expression instanceof FromItem) {
-            processFromItem((FromItem) expression);
-        } else if (expression instanceof InExpression) {
-            InExpression inExp = (InExpression) expression;
-            ItemsList rightItems = inExp.getRightItemsList();
-            if (rightItems instanceof SubSelect) {
-                processSelectBody(((SubSelect) rightItems).getSelectBody());
-            }
-        }
-    }
-
-    /**
-     * 目前: 针对自定义的tenantId的条件表达式[tenant_id in (1,2,3)],无法处理多租户的字段加上表别名
-     * select a.id, b.name
-     * from a
-     * join b on b.aid = a.id and [b.]tenant_id in (1,2) --别名[b.]无法加上 TODO
-     *
-     * @param expression
-     * @param table
-     * @return 加上别名的多租户字段表达式
-     */
-    protected Expression processTableAlias4CustomizedTenantIdExpression(Expression expression, Table table) {
-        Expression target;
-        if (expression instanceof ValueListExpression) {
-            InExpression inExpression = new InExpression();
-            inExpression.setLeftExpression(this.getAliasColumn(table));
-            inExpression.setRightItemsList(((ValueListExpression) expression).getExpressionList());
-            target = inExpression;
-        } else {
-            EqualsTo equalsTo = new EqualsTo();
-            equalsTo.setLeftExpression(this.getAliasColumn(table));
-            equalsTo.setRightExpression(expression);
-            target = equalsTo;
-        }
-        return target;
-    }
-
-    /**
-     * 租户字段别名设置
-     * <p>tenantId 或 tableAlias.tenantId</p>
-     *
-     * @param table 表对象
-     * @return 字段
-     */
-    protected Column getAliasColumn(Table table) {
-        StringBuilder column = new StringBuilder();
-        if (table.getAlias() != null) {
-            column.append(table.getAlias().getName()).append(StringPool.DOT);
-        }
-        column.append(tenantHandler.getTenantIdColumn());
-        return new Column(column.toString());
-    }
-
-    @Override
-    public void setProperties(Properties properties) {
-        PropertyMapper.newInstance(properties)
-            .whenNotBlack("tenantHandler", ClassUtils::newInstance, this::setTenantHandler);
-    }
-}
-
-

+ 1 - 1
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/PaginationInnerInterceptor.java

@@ -371,7 +371,7 @@ public class PaginationInnerInterceptor implements InnerInterceptor {
      * @param originalSql 需要拼接的SQL
      * @return ignore
      */
-    protected String concatOrderBy(String originalSql, List<OrderItem> orderList) {
+    public String concatOrderBy(String originalSql, List<OrderItem> orderList) {
         try {
             Select select = (Select) CCJSqlParserUtil.parse(originalSql);
             SelectBody selectBody = select.getSelectBody();

+ 31 - 8
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/TenantLineInnerInterceptor.java

@@ -124,6 +124,16 @@ public class TenantLineInnerInterceptor extends JsqlParserSupport implements Inn
             return;
         }
         columns.add(new Column(tenantLineHandler.getTenantIdColumn()));
+
+        // fixed gitee pulls/141 duplicate update
+        List<Expression> duplicateUpdateColumns = insert.getDuplicateUpdateExpressionList();
+        if (CollectionUtils.isNotEmpty(duplicateUpdateColumns)) {
+            EqualsTo equalsTo = new EqualsTo();
+            equalsTo.setLeftExpression(new StringValue(tenantLineHandler.getTenantIdColumn()));
+            equalsTo.setRightExpression(tenantLineHandler.getTenantId());
+            duplicateUpdateColumns.add(equalsTo);
+        }
+
         Select select = insert.getSelect();
         if (select != null) {
             this.processInsertSelect(select.getSelectBody());
@@ -312,18 +322,31 @@ public class TenantLineInnerInterceptor extends JsqlParserSupport implements Inn
             if (selectExpressionItem.getExpression() instanceof SubSelect) {
                 processSelectBody(((SubSelect) selectExpressionItem.getExpression()).getSelectBody());
             } else if (selectExpressionItem.getExpression() instanceof Function) {
-                ExpressionList parameters = ((Function) selectExpressionItem.getExpression()).getParameters();
-                if (parameters != null) {
-                    parameters.getExpressions().forEach(expression -> {
-                        if (expression instanceof SubSelect) {
-                            processSelectBody(((SubSelect) expression).getSelectBody());
-                        }
-                    });
-                }
+                processFunction((Function)selectExpressionItem.getExpression());
             }
         }
     }
 
+    /**
+     * 处理函数
+     * <p>支持: 1. select fun(args..) 2. select fun1(fun2(args..),args..)<p>
+     * <p> fixed gitee pulls/141</p>
+     *
+     * @param function
+     */
+    protected void processFunction(Function function) {
+        ExpressionList parameters = function.getParameters();
+        if (parameters != null) {
+            parameters.getExpressions().forEach(expression -> {
+                if (expression instanceof SubSelect) {
+                    processSelectBody(((SubSelect)expression).getSelectBody());
+                } else if (expression instanceof Function) {
+                    processFunction((Function)expression);
+                }
+            });
+        }
+    }
+
     /**
      * 处理子查询等
      */

+ 0 - 54
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/DialectFactory.java

@@ -16,18 +16,11 @@
 package com.baomidou.mybatisplus.extension.plugins.pagination;
 
 import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.DialectRegistry;
 import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect;
-import org.apache.ibatis.session.RowBounds;
 
-import java.util.Map;
 import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * 分页方言工厂类
@@ -39,53 +32,6 @@ public class DialectFactory {
 
     private static final DialectRegistry DIALECT_REGISTRY = new DialectRegistry();
 
-    /**
-     * 自定义方言缓存
-     */
-    private static final Map<String, IDialect> DIALECT_CACHE = new ConcurrentHashMap<>();
-
-    /**
-     * Physical Page Interceptor for all the queries with parameter
-     * {@link RowBounds}
-     *
-     * @param page         翻页对象
-     * @param buildSql     编译 SQL
-     * @param dbType       数据类型
-     * @param dialectClazz 数据库方言
-     * @return 分页模型
-     * @deprecated 3.3.1
-     */
-    @Deprecated
-    public static DialectModel buildPaginationSql(IPage<?> page, String buildSql, DbType dbType, String dialectClazz) {
-        // fix #196
-        return getDialect(dbType, dialectClazz).buildPaginationSql(buildSql, page.offset(), page.getSize());
-    }
-
-    /**
-     * 获取数据库方言
-     *
-     * @param dbType       数据库类型
-     * @param dialectClazz 自定义方言实现类
-     * @return ignore
-     * @deprecated 3.3.1 {@link #getDialect(String)}
-     */
-    @Deprecated
-    private static IDialect getDialect(DbType dbType, String dialectClazz) {
-        //这里需要注意一下,就的版本是把dbType和dialectClazz同时传进来的,所以会存在dbType是一定会有值,dialectClazz可能为空的情况,兼容需要先判断dialectClazz
-        return StringUtils.isBlank(dialectClazz) ? DIALECT_REGISTRY.getDialect(dbType) : CollectionUtils.computeIfAbsent(DIALECT_CACHE, dialectClazz, ClassUtils::newInstance);
-    }
-
-    /**
-     * 获取实现方言
-     *
-     * @param dialectClazz 方言全类名
-     * @return 方言实现对象
-     * @since 3.3.1
-     */
-    public static IDialect getDialect(String dialectClazz) {
-        return CollectionUtils.computeIfAbsent(DIALECT_CACHE, dialectClazz, ClassUtils::newInstance);
-    }
-
     public static IDialect getDialect(DbType dbType) {
         return Optional.ofNullable(DIALECT_REGISTRY.getDialect(dbType))
             .orElseThrow(() -> ExceptionUtils.mpe("%s database not supported.", dbType.getDb()));

+ 0 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/DmDialect.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * 达梦数据库完全继承 Oracle
- *
- * @author hubin
- * @since 2018-08-21
- */
-@Deprecated
-public class DmDialect extends OracleDialect {
-}

+ 0 - 24
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/GBaseDialect.java

@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * @author wangzhongkai
- * @since 2020/5/26
- */
-@Deprecated
-public class GBaseDialect extends MySqlDialect {
-}

+ 0 - 24
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/GaussDialect.java

@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * @author lhx
- * @since 2020/3/26
- */
-@Deprecated
-public class GaussDialect extends OracleDialect {
-}

+ 0 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/H2Dialect.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * H2 数据库分页方言
- *
- * @author hubin
- * @since 2016-11-10
- */
-@Deprecated
-public class H2Dialect extends PostgreDialect {
-}

+ 0 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/HSQLDialect.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * HSQL 数据库分页语句组装实现
- *
- * @author hubin
- * @since 2016-01-23
- */
-@Deprecated
-public class HSQLDialect extends PostgreDialect {
-}

+ 0 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/KingbaseDialect.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * Kingbase 数据库分页语句组装实现
- *
- * @author kingbase
- * @since 2019-10-12
- */
-@Deprecated
-public class KingbaseDialect extends PostgreDialect {
-}

+ 0 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/MariaDBDialect.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * MariaDB 数据库分页语句组装实现
- *
- * @author Caratacus
- * @since 2018-04-24
- */
-@Deprecated
-public class MariaDBDialect extends MySqlDialect {
-}

+ 0 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/OscarDialect.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * 神通数据分页方言
- *
- * @author wangheli
- * @since 2020-07-25 9:13
- */
-@Deprecated
-public class OscarDialect extends MySqlDialect {
-}

+ 0 - 24
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/PhoenixDialect.java

@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * @author fly
- * @since 2019/12/20
- */
-@Deprecated
-public class PhoenixDialect extends PostgreDialect {
-}

+ 0 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SQLiteDialect.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * SQLite 数据库分页语句组装实现
- *
- * @author hubin
- * @since 2016-01-23
- */
-@Deprecated
-public class SQLiteDialect extends PostgreDialect {
-}

+ 0 - 26
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/XuGuDialect.java

@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
-
-/**
- * 虚谷数据库分页语句组装实现
- *
- * @author https://github.com/mj7788
- * @since 2019-08-29
- */
-@Deprecated
-public class XuGuDialect extends MySqlDialect {
-}

+ 0 - 70
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/tenant/TenantHandler.java

@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.tenant;
-
-import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
-import com.baomidou.mybatisplus.extension.plugins.inner.FakeTenantLineInnerInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
-import net.sf.jsqlparser.expression.Expression;
-import net.sf.jsqlparser.expression.ValueListExpression;
-
-/**
- * 租户处理器( TenantId 行级 )
- *
- * @author hubin
- * @since 2017-08-31
- * @deprecated 3.4.0 please use {@link MybatisPlusInterceptor} {@link TenantLineInnerInterceptor} {@link TenantLineHandler}
- * or {@link FakeTenantLineInnerInterceptor}
- */
-@Deprecated
-public interface TenantHandler {
-
-    /**
-     * 获取租户 ID 值表达式,支持多个 ID 条件查询
-     * <p>
-     * 支持自定义表达式,比如:tenant_id in (1,2) @since 2019-8-2
-     * 多参请使用 {@link ValueListExpression}
-     *
-     * @param select 参数 true 表示为 select 下的 where 条件,false 表示 insert/update/delete 下的条件
-     *               只有 select 下才允许多参,否则只支持单参
-     * @return 租户 ID 值表达式
-     */
-    Expression getTenantId(boolean select);
-
-    /**
-     * 获取租户字段名
-     * <p>
-     * 默认字段名叫: tenant_id
-     *
-     * @return 租户字段名
-     */
-    default String getTenantIdColumn() {
-        return "tenant_id";
-    }
-
-    /**
-     * 根据表名判断是否进行过滤
-     * <p>
-     * 默认都要进行解析
-     *
-     * @param tableName 表名
-     * @return 是否进行过滤, true:表示忽略,false:需要解析多租户字段
-     */
-    default boolean doTableFilter(String tableName) {
-        return false;
-    }
-}

+ 0 - 309
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/tenant/TenantSqlParser.java

@@ -1,309 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.extension.plugins.tenant;
-
-import com.baomidou.mybatisplus.core.parser.AbstractJsqlParser;
-import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.NoArgsConstructor;
-import lombok.experimental.Accessors;
-import net.sf.jsqlparser.expression.BinaryExpression;
-import net.sf.jsqlparser.expression.Expression;
-import net.sf.jsqlparser.expression.Parenthesis;
-import net.sf.jsqlparser.expression.ValueListExpression;
-import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
-import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
-import net.sf.jsqlparser.expression.operators.relational.*;
-import net.sf.jsqlparser.schema.Column;
-import net.sf.jsqlparser.schema.Table;
-import net.sf.jsqlparser.statement.delete.Delete;
-import net.sf.jsqlparser.statement.insert.Insert;
-import net.sf.jsqlparser.statement.select.*;
-import net.sf.jsqlparser.statement.update.Update;
-
-import java.util.List;
-
-/**
- * 租户 SQL 解析器( TenantId 行级 )
- *
- * @author hubin
- * @since 2017-09-01
- * @deprecated 3.4.0
- */
-@Data
-@Deprecated
-@NoArgsConstructor
-@AllArgsConstructor
-@Accessors(chain = true)
-@EqualsAndHashCode(callSuper = true)
-public class TenantSqlParser extends AbstractJsqlParser {
-
-    private TenantHandler tenantHandler;
-
-    /**
-     * select 语句处理
-     */
-    @Override
-    public void processSelectBody(SelectBody selectBody) {
-        if (selectBody instanceof PlainSelect) {
-            processPlainSelect((PlainSelect) selectBody);
-        } else if (selectBody instanceof WithItem) {
-            WithItem withItem = (WithItem) selectBody;
-            if (withItem.getSelectBody() != null) {
-                processSelectBody(withItem.getSelectBody());
-            }
-        } else {
-            SetOperationList operationList = (SetOperationList) selectBody;
-            if (operationList.getSelects() != null && operationList.getSelects().size() > 0) {
-                operationList.getSelects().forEach(this::processSelectBody);
-            }
-        }
-    }
-
-    /**
-     * insert 语句处理
-     */
-    @Override
-    public void processInsert(Insert insert) {
-        if (tenantHandler.doTableFilter(insert.getTable().getName())) {
-            // 过滤退出执行
-            return;
-        }
-        insert.getColumns().add(new Column(tenantHandler.getTenantIdColumn()));
-        if (insert.getSelect() != null) {
-            processPlainSelect((PlainSelect) insert.getSelect().getSelectBody(), true);
-        } else if (insert.getItemsList() != null) {
-            // fixed github pull/295
-            ItemsList itemsList = insert.getItemsList();
-            if (itemsList instanceof MultiExpressionList) {
-                ((MultiExpressionList) itemsList).getExprList().forEach(el -> el.getExpressions().add(tenantHandler.getTenantId(false)));
-            } else {
-                ((ExpressionList) insert.getItemsList()).getExpressions().add(tenantHandler.getTenantId(false));
-            }
-        } else {
-            throw ExceptionUtils.mpe("Failed to process multiple-table update, please exclude the tableName or statementId");
-        }
-    }
-
-    /**
-     * update 语句处理
-     */
-    @Override
-    public void processUpdate(Update update) {
-        final Table table = update.getTable();
-        if (tenantHandler.doTableFilter(table.getName())) {
-            // 过滤退出执行
-            return;
-        }
-        update.setWhere(this.andExpression(table, update.getWhere()));
-    }
-
-    /**
-     * delete 语句处理
-     */
-    @Override
-    public void processDelete(Delete delete) {
-        if (tenantHandler.doTableFilter(delete.getTable().getName())) {
-            // 过滤退出执行
-            return;
-        }
-        delete.setWhere(this.andExpression(delete.getTable(), delete.getWhere()));
-    }
-
-    /**
-     * delete update 语句 where 处理
-     */
-    protected BinaryExpression andExpression(Table table, Expression where) {
-        //获得where条件表达式
-        EqualsTo equalsTo = new EqualsTo();
-        equalsTo.setLeftExpression(this.getAliasColumn(table));
-        equalsTo.setRightExpression(tenantHandler.getTenantId(false));
-        if (null != where) {
-            if (where instanceof OrExpression) {
-                return new AndExpression(equalsTo, new Parenthesis(where));
-            } else {
-                return new AndExpression(equalsTo, where);
-            }
-        }
-        return equalsTo;
-    }
-
-    /**
-     * 处理 PlainSelect
-     */
-    protected void processPlainSelect(PlainSelect plainSelect) {
-        processPlainSelect(plainSelect, false);
-    }
-
-    /**
-     * 处理 PlainSelect
-     *
-     * @param plainSelect ignore
-     * @param addColumn   是否添加租户列,insert into select语句中需要
-     */
-    protected void processPlainSelect(PlainSelect plainSelect, boolean addColumn) {
-        FromItem fromItem = plainSelect.getFromItem();
-        if (fromItem instanceof Table) {
-            Table fromTable = (Table) fromItem;
-            if (!tenantHandler.doTableFilter(fromTable.getName())) {
-                //#1186 github
-                plainSelect.setWhere(builderExpression(plainSelect.getWhere(), fromTable));
-                if (addColumn) {
-                    plainSelect.getSelectItems().add(new SelectExpressionItem(new Column(tenantHandler.getTenantIdColumn())));
-                }
-            }
-        } else {
-            processFromItem(fromItem);
-        }
-        List<Join> joins = plainSelect.getJoins();
-        if (joins != null && joins.size() > 0) {
-            joins.forEach(j -> {
-                processJoin(j);
-                processFromItem(j.getRightItem());
-            });
-        }
-    }
-
-    /**
-     * 处理子查询等
-     */
-    protected void processFromItem(FromItem fromItem) {
-        if (fromItem instanceof SubJoin) {
-            SubJoin subJoin = (SubJoin) fromItem;
-            if (subJoin.getJoinList() != null) {
-                subJoin.getJoinList().forEach(this::processJoin);
-            }
-            if (subJoin.getLeft() != null) {
-                processFromItem(subJoin.getLeft());
-            }
-        } else if (fromItem instanceof SubSelect) {
-            SubSelect subSelect = (SubSelect) fromItem;
-            if (subSelect.getSelectBody() != null) {
-                processSelectBody(subSelect.getSelectBody());
-            }
-        } else if (fromItem instanceof ValuesList) {
-            logger.debug("Perform a subquery, if you do not give us feedback");
-        } else if (fromItem instanceof LateralSubSelect) {
-            LateralSubSelect lateralSubSelect = (LateralSubSelect) fromItem;
-            if (lateralSubSelect.getSubSelect() != null) {
-                SubSelect subSelect = lateralSubSelect.getSubSelect();
-                if (subSelect.getSelectBody() != null) {
-                    processSelectBody(subSelect.getSelectBody());
-                }
-            }
-        }
-    }
-
-    /**
-     * 处理联接语句
-     */
-    protected void processJoin(Join join) {
-        if (join.getRightItem() instanceof Table) {
-            Table fromTable = (Table) join.getRightItem();
-            if (this.tenantHandler.doTableFilter(fromTable.getName())) {
-                // 过滤退出执行
-                return;
-            }
-            join.setOnExpression(builderExpression(join.getOnExpression(), fromTable));
-        }
-    }
-
-    /**
-     * 处理条件:
-     * 支持 getTenantHandler().getTenantId()是一个完整的表达式:tenant in (1,2)
-     * 默认tenantId的表达式: LongValue(1)这种依旧支持
-     */
-    protected Expression builderExpression(Expression currentExpression, Table table) {
-        final Expression tenantExpression = tenantHandler.getTenantId(true);
-        Expression appendExpression = this.processTableAlias4CustomizedTenantIdExpression(tenantExpression, table);
-        if (currentExpression == null) {
-            return appendExpression;
-        }
-        if (currentExpression instanceof BinaryExpression) {
-            BinaryExpression binaryExpression = (BinaryExpression) currentExpression;
-            doExpression(binaryExpression.getLeftExpression());
-            doExpression(binaryExpression.getRightExpression());
-        } else if (currentExpression instanceof InExpression) {
-            InExpression inExp = (InExpression) currentExpression;
-            ItemsList rightItems = inExp.getRightItemsList();
-            if (rightItems instanceof SubSelect) {
-                processSelectBody(((SubSelect) rightItems).getSelectBody());
-            }
-        }
-        if (currentExpression instanceof OrExpression) {
-            return new AndExpression(new Parenthesis(currentExpression), appendExpression);
-        } else {
-            return new AndExpression(currentExpression, appendExpression);
-        }
-    }
-
-    protected void doExpression(Expression expression) {
-        if (expression instanceof FromItem) {
-            processFromItem((FromItem) expression);
-        } else if (expression instanceof InExpression) {
-            InExpression inExp = (InExpression) expression;
-            ItemsList rightItems = inExp.getRightItemsList();
-            if (rightItems instanceof SubSelect) {
-                processSelectBody(((SubSelect) rightItems).getSelectBody());
-            }
-        }
-    }
-
-    /**
-     * 目前: 针对自定义的tenantId的条件表达式[tenant_id in (1,2,3)],无法处理多租户的字段加上表别名
-     * select a.id, b.name
-     * from a
-     * join b on b.aid = a.id and [b.]tenant_id in (1,2) --别名[b.]无法加上 TODO
-     *
-     * @param expression
-     * @param table
-     * @return 加上别名的多租户字段表达式
-     */
-    protected Expression processTableAlias4CustomizedTenantIdExpression(Expression expression, Table table) {
-        Expression target;
-        if (expression instanceof ValueListExpression) {
-            InExpression inExpression = new InExpression();
-            inExpression.setLeftExpression(this.getAliasColumn(table));
-            inExpression.setRightItemsList(((ValueListExpression) expression).getExpressionList());
-            target = inExpression;
-        } else {
-            EqualsTo equalsTo = new EqualsTo();
-            equalsTo.setLeftExpression(this.getAliasColumn(table));
-            equalsTo.setRightExpression(expression);
-            target = equalsTo;
-        }
-        return target;
-    }
-
-    /**
-     * 租户字段别名设置
-     * <p>tenantId 或 tableAlias.tenantId</p>
-     *
-     * @param table 表对象
-     * @return 字段
-     */
-    protected Column getAliasColumn(Table table) {
-        StringBuilder column = new StringBuilder();
-        if (table.getAlias() != null) {
-            column.append(table.getAlias().getName()).append(StringPool.DOT);
-        }
-        column.append(tenantHandler.getTenantIdColumn());
-        return new Column(column.toString());
-    }
-}

+ 0 - 19
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/tenant/package-info.java

@@ -1,19 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * mybatis 租户插件实现类
- */
-package com.baomidou.mybatisplus.extension.plugins.tenant;

+ 49 - 49
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/parsers/DynamicTableNameParserTest.java

@@ -1,49 +1,49 @@
-package com.baomidou.mybatisplus.extension.parsers;
-
-import org.junit.jupiter.api.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-/**
- * Create by hcl at 2020/6/30
- */
-class DynamicTableNameParserTest {
-
-    @Test
-    void parser() {
-        DynamicTableNameParser parser = new DynamicTableNameParser();
-        Map<String, ITableNameHandler> tableNameHandlerMap = new HashMap<>();
-        tableNameHandlerMap.put("t_user",
-                // https://github.com/baomidou/mybatis-plus/issues/2411
-                (metaObject, sql, tableName) -> {
-                    if ("t_user".equals(tableName)) {
-                        return "t_user_2019";
-                    }
-                    return tableName;
-                });
-        parser.setTableNameHandlerMap(tableNameHandlerMap);
-
-        String before = "select a.* from t_user a join t_userrole b on b.userid = a.gid";
-        String after = "select a.* from t_user_2019 a join t_userrole b on b.userid = a.gid";
-        assertEquals(after, parser.parser(null, before).getSql());
-
-        before = "select * from t_user";
-        after = "select * from t_user_2019";
-        assertEquals(after, parser.parser(null, before).getSql());
-
-        before = "insert into t_user(id,name) values('1','zhangsan')";
-        after = "insert into t_user_2019(id,name) values('1','zhangsan')";
-        assertEquals(after, parser.parser(null, before).getSql());
-        before = "select a.*,\n" +
-                "        (select count(1) from t_user) as cnt\n" +
-                "        from t_xxx a";
-        after = "select a.*,\n" +
-                "        (select count(1) from t_user_2019) as cnt\n" +
-                "        from t_xxx a";
-        assertEquals(after, parser.parser(null, before).getSql());
-    }
-
-}
+//package com.baomidou.mybatisplus.extension.parsers;
+//
+//import org.junit.jupiter.api.Test;
+//
+//import java.util.HashMap;
+//import java.util.Map;
+//
+//import static org.junit.jupiter.api.Assertions.assertEquals;
+//
+///**
+// * Create by hcl at 2020/6/30
+// */
+//class DynamicTableNameParserTest {
+//
+//    @Test
+//    void parser() {
+//        DynamicTableNameParser parser = new DynamicTableNameParser();
+//        Map<String, ITableNameHandler> tableNameHandlerMap = new HashMap<>();
+//        tableNameHandlerMap.put("t_user",
+//                // https://github.com/baomidou/mybatis-plus/issues/2411
+//                (metaObject, sql, tableName) -> {
+//                    if ("t_user".equals(tableName)) {
+//                        return "t_user_2019";
+//                    }
+//                    return tableName;
+//                });
+//        parser.setTableNameHandlerMap(tableNameHandlerMap);
+//
+//        String before = "select a.* from t_user a join t_userrole b on b.userid = a.gid";
+//        String after = "select a.* from t_user_2019 a join t_userrole b on b.userid = a.gid";
+//        assertEquals(after, parser.parser(null, before).getSql());
+//
+//        before = "select * from t_user";
+//        after = "select * from t_user_2019";
+//        assertEquals(after, parser.parser(null, before).getSql());
+//
+//        before = "insert into t_user(id,name) values('1','zhangsan')";
+//        after = "insert into t_user_2019(id,name) values('1','zhangsan')";
+//        assertEquals(after, parser.parser(null, before).getSql());
+//        before = "select a.*,\n" +
+//                "        (select count(1) from t_user) as cnt\n" +
+//                "        from t_xxx a";
+//        after = "select a.*,\n" +
+//                "        (select count(1) from t_user_2019) as cnt\n" +
+//                "        from t_xxx a";
+//        assertEquals(after, parser.parser(null, before).getSql());
+//    }
+//
+//}

+ 6 - 8
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/handlers/FastJsonTypeHandlerTest.java

@@ -9,18 +9,16 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 /**
  * @author nieqiurong 2020/2/28.
  */
 @ExtendWith(MockitoExtension.class)
 public class FastJsonTypeHandlerTest extends BaseTypeHandlerTest {
-    
+
     private static final FastjsonTypeHandler FASTJSON_TYPE_HANDLER = new FastjsonTypeHandler(UserBean.class);
-    
+
     @Test
     @Override
     public void setParameter() throws Exception {
@@ -31,7 +29,7 @@ public class FastJsonTypeHandlerTest extends BaseTypeHandlerTest {
         FASTJSON_TYPE_HANDLER.setParameter(preparedStatement, 3, "{}", JdbcType.VARCHAR);
         verify(preparedStatement).setString(3, "\"{}\"");
     }
-    
+
     @Test
     @Override
     public void getResultFromResultSetByColumnName() throws Exception {
@@ -47,7 +45,7 @@ public class FastJsonTypeHandlerTest extends BaseTypeHandlerTest {
         assertEquals(bean.getId(), 123L);
         assertEquals(bean.getName(), "测试");
     }
-    
+
     @Test
     @Override
     public void getResultFromResultSetByColumnIndex() throws Exception {
@@ -63,7 +61,7 @@ public class FastJsonTypeHandlerTest extends BaseTypeHandlerTest {
         assertEquals(bean.getId(), 123L);
         assertEquals(bean.getName(), "测试");
     }
-    
+
     @Test
     @Override
     public void getResultFromCallableStatement() throws Exception {

+ 6 - 8
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/handlers/GsonTypeHandlerTest.java

@@ -9,18 +9,16 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 /**
  * @author nieqiurong 2020/2/28.
  */
 @ExtendWith(MockitoExtension.class)
 public class GsonTypeHandlerTest extends BaseTypeHandlerTest {
-    
+
     private static final GsonTypeHandler GSON_TYPE_HANDLER = new GsonTypeHandler(UserBean.class);
-    
+
     @Test
     @Override
     public void setParameter() throws Exception {
@@ -31,7 +29,7 @@ public class GsonTypeHandlerTest extends BaseTypeHandlerTest {
         GSON_TYPE_HANDLER.setParameter(preparedStatement, 3, "{}", JdbcType.VARCHAR);
         verify(preparedStatement).setString(3, "\"{}\"");
     }
-    
+
     @Test
     @Override
     public void getResultFromResultSetByColumnName() throws Exception {
@@ -47,7 +45,7 @@ public class GsonTypeHandlerTest extends BaseTypeHandlerTest {
         assertEquals(bean.getId(), 123L);
         assertEquals(bean.getName(), "测试");
     }
-    
+
     @Test
     @Override
     public void getResultFromResultSetByColumnIndex() throws Exception {
@@ -63,7 +61,7 @@ public class GsonTypeHandlerTest extends BaseTypeHandlerTest {
         assertEquals(bean.getId(), 123L);
         assertEquals(bean.getName(), "测试");
     }
-    
+
     @Test
     @Override
     public void getResultFromCallableStatement() throws Exception {

+ 7 - 9
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/handlers/JacksonTypeHandlerTest.java

@@ -9,18 +9,16 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 /**
  * @author nieqiurong 2020/2/28.
  */
 @ExtendWith(MockitoExtension.class)
 public class JacksonTypeHandlerTest extends BaseTypeHandlerTest {
-    
+
     private static final JacksonTypeHandler JACKSON_TYPE_HANDLER = new JacksonTypeHandler(UserBean.class);
-    
+
     @Test
     @Override
     public void setParameter() throws Exception {
@@ -31,7 +29,7 @@ public class JacksonTypeHandlerTest extends BaseTypeHandlerTest {
         JACKSON_TYPE_HANDLER.setParameter(preparedStatement, 3, "{}", JdbcType.VARCHAR);
         verify(preparedStatement).setString(3, "\"{}\"");
     }
-    
+
     @Test
     @Override
     public void getResultFromResultSetByColumnName() throws Exception {
@@ -47,7 +45,7 @@ public class JacksonTypeHandlerTest extends BaseTypeHandlerTest {
         assertEquals(bean.getId(), 123L);
         assertEquals(bean.getName(), "测试");
     }
-    
+
     @Test
     @Override
     public void getResultFromResultSetByColumnIndex() throws Exception {
@@ -63,7 +61,7 @@ public class JacksonTypeHandlerTest extends BaseTypeHandlerTest {
         assertEquals(bean.getId(), 123L);
         assertEquals(bean.getName(), "测试");
     }
-    
+
     @Test
     @Override
     public void getResultFromCallableStatement() throws Exception {
@@ -79,5 +77,5 @@ public class JacksonTypeHandlerTest extends BaseTypeHandlerTest {
         assertEquals(bean.getId(), 123L);
         assertEquals(bean.getName(), "测试");
     }
-    
+
 }

+ 0 - 47
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/pagination/DialectFactoryTest.java

@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.test.plugins.pagination;
-
-import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.DialectFactory;
-import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.MySqlDialect;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-/**
- * @author nieqiuqiu
- */
-class DialectFactoryTest {
-
-    @Test
-    void test() {
-        DialectModel dialectModel;
-        IPage<Object> page = new Page<>();
-        //使用默认方言
-        dialectModel = DialectFactory.buildPaginationSql(page, "select * from test ", com.baomidou.mybatisplus.annotation.DbType.MYSQL, null);
-        Assertions.assertEquals(dialectModel.getDialectSql(), "select * from test  LIMIT ?");
-        dialectModel = DialectFactory.buildPaginationSql(page, "select * from test ", DbType.MYSQL, null);
-        Assertions.assertEquals(dialectModel.getDialectSql(), "select * from test  LIMIT ?");
-        //使用默认自定义方言
-        dialectModel = DialectFactory.buildPaginationSql(page, "select * from test ", com.baomidou.mybatisplus.annotation.DbType.H2, MySqlDialect.class.getName());
-        Assertions.assertEquals(dialectModel.getDialectSql(), "select * from test  LIMIT ?");
-        dialectModel = DialectFactory.buildPaginationSql(page, "select * from test ", DbType.H2, MySqlDialect.class.getName());
-        Assertions.assertEquals(dialectModel.getDialectSql(), "select * from test  LIMIT ?");
-    }
-}

+ 0 - 94
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/pagination/PaginationInterceptorTest.java

@@ -1,94 +0,0 @@
-package com.baomidou.mybatisplus.test.plugins.pagination;
-
-import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.DB2Dialect;
-import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.MySqlDialect;
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
-import org.apache.ibatis.reflection.MetaObject;
-import org.apache.ibatis.reflection.SystemMetaObject;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Properties;
-
-
-/**
- * @author nieqiurong 2020/4/10.
- */
-@ExtendWith(MockitoExtension.class)
-class PaginationInterceptorTest {
-    
-    @Test
-    void testSetCountSqlParser() {
-        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
-        MetaObject metaObject = SystemMetaObject.forObject(paginationInterceptor);
-        Assertions.assertNull(metaObject.getValue("countSqlParser"));
-        Properties properties = new Properties();
-        properties.setProperty("countSqlParser", BlockAttackSqlParser.class.getName());
-        paginationInterceptor.setProperties(properties);
-        Assertions.assertEquals(metaObject.getValue("countSqlParser").getClass().getName(), BlockAttackSqlParser.class.getName());
-        paginationInterceptor.setCountSqlParser(new TenantSqlParser());
-        Assertions.assertEquals(metaObject.getValue("countSqlParser").getClass().getName(), TenantSqlParser.class.getName());
-    }
-    
-    @Test
-    void testSetOverflow() {
-        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
-        MetaObject metaObject = SystemMetaObject.forObject(paginationInterceptor);
-        Assertions.assertFalse((Boolean) metaObject.getValue("overflow"));
-        Properties properties = new Properties();
-        properties.setProperty("overflow", "true");
-        paginationInterceptor.setProperties(properties);
-        Assertions.assertTrue((Boolean) metaObject.getValue("overflow"));
-        paginationInterceptor.setOverflow(false);
-        Assertions.assertFalse((Boolean) metaObject.getValue("overflow"));
-    }
-    
-    @Test
-    void testSetDbType() {
-        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
-        MetaObject metaObject = SystemMetaObject.forObject(paginationInterceptor);
-        Assertions.assertNull(metaObject.getValue("dialectType"));
-        Properties properties = new Properties();
-        properties.setProperty("dialectType", "mysql");
-        paginationInterceptor.setProperties(properties);
-        Assertions.assertEquals(DbType.MYSQL, metaObject.getValue("dbType"));
-        paginationInterceptor.setDbType(DbType.DB2);
-        Assertions.assertEquals(DbType.DB2, metaObject.getValue("dbType"));
-        paginationInterceptor.setDialectType("mysql");
-        Assertions.assertEquals(DbType.MYSQL, metaObject.getValue("dbType"));
-    }
-    
-    @Test
-    void testSetDialect() {
-        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
-        MetaObject metaObject = SystemMetaObject.forObject(paginationInterceptor);
-        Assertions.assertNull(metaObject.getValue("dialectClazz"));
-        Properties properties = new Properties();
-        properties.setProperty("dialectClazz", MySqlDialect.class.getName());
-        paginationInterceptor.setProperties(properties);
-        Assertions.assertEquals(MySqlDialect.class.getName(), metaObject.getValue("dialect").getClass().getName());
-        paginationInterceptor.setDialect(new DB2Dialect());
-        Assertions.assertEquals(DB2Dialect.class.getName(), metaObject.getValue("dialect").getClass().getName());
-        paginationInterceptor.setDialectClazz(MySqlDialect.class.getName());
-        Assertions.assertEquals(MySqlDialect.class.getName(), metaObject.getValue("dialect").getClass().getName());
-    }
-    
-    @Test
-    void testSetLimit(){
-        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
-        MetaObject metaObject = SystemMetaObject.forObject(paginationInterceptor);
-        Assertions.assertEquals(500L, metaObject.getValue("limit"));
-        Properties properties = new Properties();
-        properties.setProperty("limit", "10086");
-        paginationInterceptor.setProperties(properties);
-        Assertions.assertEquals(10086L, metaObject.getValue("limit"));
-        paginationInterceptor.setLimit(10010L);
-        Assertions.assertEquals(10010L, metaObject.getValue("limit"));
-    }
-    
-}

+ 25 - 21
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/pagination/SelectBodyToPlainSelectTest.java

@@ -1,8 +1,7 @@
 package com.baomidou.mybatisplus.test.plugins.pagination;
 
 import com.baomidou.mybatisplus.core.metadata.OrderItem;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import net.sf.jsqlparser.JSQLParserException;
 import net.sf.jsqlparser.parser.CCJSqlParserUtil;
 import net.sf.jsqlparser.statement.select.PlainSelect;
@@ -22,6 +21,12 @@ import static org.assertj.core.api.Assertions.assertThat;
  */
 class SelectBodyToPlainSelectTest {
 
+    private static final List<OrderItem> ITEMS = new ArrayList<>();
+
+    static {
+        ITEMS.add(OrderItem.asc("column"));
+    }
+
     /**
      * 报错的测试
      */
@@ -41,8 +46,6 @@ class SelectBodyToPlainSelectTest {
         });
     }
 
-    private Page<?> page = new Page<>();
-
     @BeforeEach
     void setup() {
         List<OrderItem> orderItems = new ArrayList<>();
@@ -54,53 +57,54 @@ class SelectBodyToPlainSelectTest {
         orderEmptyColumn.setAsc(false);
         orderEmptyColumn.setColumn("");
         orderItems.add(orderEmptyColumn);
-        page.setOrders(orderItems);
     }
 
     @Test
     void testPaginationInterceptorConcatOrderByBefore() {
-        String actualSql = new PaginationInterceptor()
-            .concatOrderBy("select * from test", page);
+        String actualSql = new PaginationInnerInterceptor()
+            .concatOrderBy("select * from test", ITEMS);
 
         assertThat(actualSql).isEqualTo("SELECT * FROM test ORDER BY column ASC");
 
-        String actualSqlWhere = new PaginationInterceptor()
-            .concatOrderBy("select * from test where 1 = 1", page);
+        String actualSqlWhere = new PaginationInnerInterceptor()
+            .concatOrderBy("select * from test where 1 = 1", ITEMS);
 
         assertThat(actualSqlWhere).isEqualTo("SELECT * FROM test WHERE 1 = 1 ORDER BY column ASC");
     }
 
     @Test
     void testPaginationInterceptorConcatOrderByFix() {
-        String actualSql = new PaginationInterceptor()
-            .concatOrderBy("select * from test union select * from test2", page);
+        List<OrderItem> orderList = new ArrayList<>();
+        orderList.add(OrderItem.asc("column"));
+        String actualSql = new PaginationInnerInterceptor()
+            .concatOrderBy("select * from test union select * from test2", orderList);
         assertThat(actualSql).isEqualTo("SELECT * FROM test UNION SELECT * FROM test2 ORDER BY column ASC");
 
-        String actualSqlUnionAll = new PaginationInterceptor()
-            .concatOrderBy("select * from test union all select * from test2", page);
+        String actualSqlUnionAll = new PaginationInnerInterceptor()
+            .concatOrderBy("select * from test union all select * from test2", orderList);
         assertThat(actualSqlUnionAll).isEqualTo("SELECT * FROM test UNION ALL SELECT * FROM test2 ORDER BY column ASC");
     }
 
     @Test
     void testPaginationInterceptorConcatOrderByFixWithWhere() {
-        String actualSqlWhere = new PaginationInterceptor()
-            .concatOrderBy("select * from test where 1 = 1 union select * from test2 where 1 = 1", page);
+        String actualSqlWhere = new PaginationInnerInterceptor()
+            .concatOrderBy("select * from test where 1 = 1 union select * from test2 where 1 = 1", ITEMS);
         assertThat(actualSqlWhere).isEqualTo("SELECT * FROM test WHERE 1 = 1 UNION SELECT * FROM test2 WHERE 1 = 1 ORDER BY column ASC");
 
-        String actualSqlUnionAll = new PaginationInterceptor()
-            .concatOrderBy("select * from test where 1 = 1 union all select * from test2 where 1 = 1 ", page);
+        String actualSqlUnionAll = new PaginationInnerInterceptor()
+            .concatOrderBy("select * from test where 1 = 1 union all select * from test2 where 1 = 1 ", ITEMS);
         assertThat(actualSqlUnionAll).isEqualTo("SELECT * FROM test WHERE 1 = 1 UNION ALL SELECT * FROM test2 WHERE 1 = 1 ORDER BY column ASC");
     }
 
     @Test
     void testPaginationInterceptorOrderByEmptyColumnFix() {
-        String actualSql = new PaginationInterceptor()
-            .concatOrderBy("select * from test", page);
+        String actualSql = new PaginationInnerInterceptor()
+            .concatOrderBy("select * from test", ITEMS);
 
         assertThat(actualSql).isEqualTo("SELECT * FROM test ORDER BY column ASC");
 
-        String actualSqlWhere = new PaginationInterceptor()
-            .concatOrderBy("select * from test where 1 = 1", page);
+        String actualSqlWhere = new PaginationInnerInterceptor()
+            .concatOrderBy("select * from test where 1 = 1", ITEMS);
 
         assertThat(actualSqlWhere).isEqualTo("SELECT * FROM test WHERE 1 = 1 ORDER BY column ASC");
     }

+ 0 - 36
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/pagination/dialects/DB2DialectTest.java

@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2011-2019, hubin (jobob@qq.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * <p>
- * https://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.baomidou.mybatisplus.test.plugins.pagination.dialects;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import org.junit.jupiter.api.Test;
-
-/**
- * @author miemie
- * @since 2018-11-01
- */
-class DB2DialectTest {
-
-    /**
-     * TODO 需要修复的单元测试
-     */
-    @Test
-    void m1() {
-        Page<?> page = new Page<>(2, 10);
-        System.out.println(page.offset() + 1);
-        System.out.println(page.getSize() + page.offset());
-    }
-}

+ 0 - 93
mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/test/plugins/tenant/TenantSqlParserTest.java

@@ -1,93 +0,0 @@
-package com.baomidou.mybatisplus.test.plugins.tenant;
-
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
-import net.sf.jsqlparser.JSQLParserException;
-import net.sf.jsqlparser.expression.Expression;
-import net.sf.jsqlparser.expression.LongValue;
-import net.sf.jsqlparser.expression.ValueListExpression;
-import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
-import net.sf.jsqlparser.parser.CCJSqlParserUtil;
-import net.sf.jsqlparser.statement.Statement;
-import net.sf.jsqlparser.statement.insert.Insert;
-import net.sf.jsqlparser.statement.select.Select;
-import net.sf.jsqlparser.statement.update.Update;
-import org.junit.jupiter.api.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * @author miemie
- * @since 2019-11-02
- */
-
-public class TenantSqlParserTest {
-
-    private final TenantSqlParser parser = new TenantSqlParser()
-        .setTenantHandler(new TenantHandler() {
-            @Override
-            public Expression getTenantId(boolean select) {
-                if (!select) {
-                    return new LongValue(1);
-                }
-                ValueListExpression expression = new ValueListExpression();
-                ExpressionList list = new ExpressionList(new LongValue(1), new LongValue(2));
-                expression.setExpressionList(list);
-                return expression;
-            }
-
-            @Override
-            public String getTenantIdColumn() {
-                return "t_id";
-            }
-
-            @Override
-            public boolean doTableFilter(String tableName) {
-                return false;
-            }
-        });
-
-    @Test
-    public void processSelectBody() throws JSQLParserException {
-        select("select * from user",
-            "select * from user where t_id in (1, 2)");
-        select("select * from user u",
-            "select * from user u where u.t_id in (1, 2)");
-        select("select * from user where id in (select id from user)",
-            "select * from user where id in (select id from user where t_id in (1, 2)) and t_id in (1, 2)");
-        select("select * from user where id = 1 and id in (select id from user)",
-            "select * from user where id = 1 and id in (select id from user where t_id in (1, 2)) and t_id in (1, 2)");
-        select("select * from user where id = 1 or id in (select id from user)",
-            "select * from user where (id = 1 or id in (select id from user where t_id in (1, 2))) and t_id in (1, 2)");
-
-        select("select * from user group by date(date_time)",
-            "select * from user where t_id in (1, 2) group by date(date_time)");
-
-        update("update user set age = 1",
-            "update user set age = 1 where t_id = 1");
-
-        insert("insert into user (id, age) values (?, ?)",
-            "insert into user (id, age, t_id) values (?, ?, 1)");
-    }
-
-    private void select(String sql, String target) throws JSQLParserException {
-        Statement statement = CCJSqlParserUtil.parse(sql);
-        Select select = (Select) statement;
-        parser.processSelectBody(select.getSelectBody());
-        assertThat(select.toString().toLowerCase()).isEqualTo(target);
-    }
-
-    private void update(String sql, String target) throws JSQLParserException {
-        Statement statement = CCJSqlParserUtil.parse(sql);
-        Update update = (Update) statement;
-        parser.processUpdate(update);
-        assertThat(update.toString().toLowerCase()).isEqualTo(target);
-    }
-
-    private void insert(String sql, String target) throws JSQLParserException {
-        Statement statement = CCJSqlParserUtil.parse(sql);
-        Insert insert = (Insert) statement;
-        parser.processInsert(insert);
-        assertThat(insert.toString().toLowerCase()).isEqualTo(target);
-    }
-}

+ 6 - 8
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/BaseTest.java

@@ -15,20 +15,18 @@
  */
 package com.baomidou.mybatisplus.test.h2;
 
-import java.lang.reflect.Field;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
 import com.baomidou.mybatisplus.core.metadata.TableInfo;
 import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+import com.baomidou.mybatisplus.test.h2.entity.H2User;
+import com.baomidou.mybatisplus.test.h2.enums.AgeEnum;
 import org.junit.jupiter.api.AfterAll;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.test.annotation.DirtiesContext;
 
-import com.baomidou.mybatisplus.test.h2.entity.H2User;
-import com.baomidou.mybatisplus.test.h2.enums.AgeEnum;
+import javax.annotation.Resource;
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.Map;
 
 @DirtiesContext
 public class BaseTest {

+ 7 - 13
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2Delete1Eq1Test.java

@@ -15,25 +15,19 @@
  */
 package com.baomidou.mybatisplus.test.h2;
 
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.MethodOrderer;
-import org.junit.jupiter.api.Order;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestMethodOrder;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.test.h2.entity.H2Student;
 import com.baomidou.mybatisplus.test.h2.entity.H2User;
 import com.baomidou.mybatisplus.test.h2.enums.AgeEnum;
 import com.baomidou.mybatisplus.test.h2.mapper.H2StudentMapper;
 import com.baomidou.mybatisplus.test.h2.mapper.H2UserMapper;
+import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * Mybatis Plus H2 Junit Test

+ 7 - 13
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2LogicDeleteTest.java

@@ -15,23 +15,17 @@
  */
 package com.baomidou.mybatisplus.test.h2;
 
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.MethodOrderer;
-import org.junit.jupiter.api.Order;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestMethodOrder;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
 import com.baomidou.mybatisplus.test.h2.entity.H2User;
 import com.baomidou.mybatisplus.test.h2.entity.H2UserLogicDelete;
 import com.baomidou.mybatisplus.test.h2.enums.AgeEnum;
 import com.baomidou.mybatisplus.test.h2.mapper.H2UserLogicDeleteMapper;
+import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * Mybatis Plus H2 Junit Test

+ 0 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/cache/service/impl/CacheServiceImpl.java

@@ -1,6 +1,5 @@
 package com.baomidou.mybatisplus.test.h2.cache.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.enums.SqlMethod;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.test.h2.cache.mapper.CacheMapper;
@@ -9,7 +8,6 @@ import com.baomidou.mybatisplus.test.h2.cache.service.ICacheService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 

+ 3 - 4
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/DBConfig.java

@@ -15,10 +15,6 @@
  */
 package com.baomidou.mybatisplus.test.h2.config;
 
-import java.io.IOException;
-
-import javax.sql.DataSource;
-
 import org.h2.Driver;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -31,6 +27,9 @@ import org.springframework.jdbc.datasource.init.DatabasePopulator;
 import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
+import javax.sql.DataSource;
+import java.io.IOException;
+
 /**
  * H2 Memory Database config
  *

+ 6 - 44
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusConfig.java

@@ -16,26 +16,18 @@
 package com.baomidou.mybatisplus.test.h2.config;
 
 import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.core.MybatisConfiguration;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.injector.AbstractMethod;
 import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
-import com.baomidou.mybatisplus.core.parser.AbstractJsqlParser;
-import com.baomidou.mybatisplus.core.parser.ISqlParser;
 import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;
 import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
 import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill;
 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.SqlExplainInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
 import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import com.baomidou.mybatisplus.test.h2.H2MetaObjectHandler;
-import net.sf.jsqlparser.statement.delete.Delete;
-import net.sf.jsqlparser.statement.insert.Insert;
-import net.sf.jsqlparser.statement.select.SelectBody;
-import net.sf.jsqlparser.statement.update.Update;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.apache.ibatis.type.EnumOrdinalTypeHandler;
@@ -43,10 +35,8 @@ import org.apache.ibatis.type.JdbcType;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ResourceLoader;
 
 import javax.sql.DataSource;
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -60,14 +50,11 @@ import java.util.List;
 public class MybatisPlusConfig {
 
     @Bean("mybatisSqlSession")
-    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ResourceLoader resourceLoader, GlobalConfig globalConfig) throws Exception {
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig) throws Exception {
         MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
         sqlSessionFactory.setDataSource(dataSource);
-//        sqlSessionFactory.setConfigLocation(resourceLoader.getResource("classpath:mybatis-config-object-factory.xml"));
         sqlSessionFactory.setTypeAliasesPackage("com.baomidou.mybatisplus.test.h2.entity.persistent");
         MybatisConfiguration configuration = new MybatisConfiguration();
-//        configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
-//        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
         configuration.setJdbcTypeForNull(JdbcType.NULL);
         /*
          * 下划线转驼峰开启
@@ -76,37 +63,12 @@ public class MybatisPlusConfig {
         configuration.setDefaultExecutorType(ExecutorType.REUSE);
         configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);  //默认枚举处理
         sqlSessionFactory.setConfiguration(configuration);
-        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
-        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
-        SqlExplainInterceptor sqlExplainInterceptor = new SqlExplainInterceptor();
-        List<ISqlParser> sqlParserList = new ArrayList<>();
-        sqlParserList.add(new AbstractJsqlParser() {
 
-            @Override
-            public void processInsert(Insert insert) {
-
-            }
-
-            @Override
-            public void processDelete(Delete delete) {
-
-            }
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
 
-            @Override
-            public void processUpdate(Update update) {
-
-            }
-
-            @Override
-            public void processSelectBody(SelectBody selectBody) {
-
-            }
-        });
-        sqlExplainInterceptor.setSqlParserList(sqlParserList);
-        OptimisticLockerInterceptor optLock = new OptimisticLockerInterceptor();
-        sqlSessionFactory.setPlugins(interceptor,
-            optLock,
-            sqlExplainInterceptor);
         globalConfig.setMetaObjectHandler(new H2MetaObjectHandler());
         globalConfig.setSqlInjector(new DefaultSqlInjector() {
 

+ 9 - 9
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisPlusConfigLogicDelete.java

@@ -24,10 +24,10 @@ import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
 import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;
 import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
 import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill;
-import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
-import org.apache.ibatis.plugin.Interceptor;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.apache.ibatis.type.EnumOrdinalTypeHandler;
@@ -67,12 +67,12 @@ public class MybatisPlusConfigLogicDelete {
         configuration.setDefaultExecutorType(ExecutorType.REUSE);
         configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);  //默认枚举处理
         sqlSessionFactory.setConfiguration(configuration);
-        PaginationInterceptor pagination = new PaginationInterceptor();
-        OptimisticLockerInterceptor optLock = new OptimisticLockerInterceptor();
-        sqlSessionFactory.setPlugins(new Interceptor[]{
-            pagination,
-            optLock
-        });
+
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
+
         globalConfig.setSqlInjector(new DefaultSqlInjector() {
 
             /**

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/config/MybatisXmlConfig.java

@@ -15,14 +15,14 @@
  */
 package com.baomidou.mybatisplus.test.h2.config;
 
-import javax.sql.DataSource;
-
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.io.ClassPathResource;
-import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
+
+import javax.sql.DataSource;
 
 /**
  * @author nieqiurong 2018/8/14 13:18.

+ 0 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/H2Addr.java

@@ -18,7 +18,6 @@ package com.baomidou.mybatisplus.test.h2.entity;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
-
 import lombok.Data;
 import lombok.experimental.Accessors;
 

+ 0 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/H2Student.java

@@ -19,7 +19,6 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
-
 import com.baomidou.mybatisplus.test.h2.enums.GenderEnum;
 import com.baomidou.mybatisplus.test.h2.enums.GradeEnum;
 import lombok.AllArgsConstructor;

+ 4 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/H2User.java

@@ -15,7 +15,10 @@
  */
 package com.baomidou.mybatisplus.test.h2.entity;
 
-import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.Version;
 import com.baomidou.mybatisplus.test.h2.enums.AgeEnum;
 import lombok.Data;
 import lombok.EqualsAndHashCode;

+ 4 - 9
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/H2UserLogicDelete.java

@@ -15,19 +15,14 @@
  */
 package com.baomidou.mybatisplus.test.h2.entity;
 
-import java.math.BigDecimal;
-import java.util.Date;
-
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.*;
 import com.baomidou.mybatisplus.test.h2.enums.AgeEnum;
-
 import lombok.Data;
 import lombok.experimental.Accessors;
 
+import java.math.BigDecimal;
+import java.util.Date;
+
 /**
  * 测试用户类
  *

+ 2 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuSuperEntity.java

@@ -15,14 +15,13 @@
  */
 package com.baomidou.mybatisplus.test.h2.entity;
 
-import java.util.Date;
-
 import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
-
 import lombok.Data;
 import lombok.experimental.Accessors;
 
+import java.util.Date;
+
 /**
  * 多层集成测试
  * <p>github #170</p>

+ 2 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuSuperEntityCamel.java

@@ -15,11 +15,11 @@
  */
 package com.baomidou.mybatisplus.test.h2.entity;
 
-import java.util.Date;
-
 import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 
+import java.util.Date;
+
 
 /**
  * 多层集成测试

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/entity/SuperEntityCamel.java

@@ -15,10 +15,10 @@
  */
 package com.baomidou.mybatisplus.test.h2.entity;
 
-import java.io.Serializable;
-
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import java.io.Serializable;
+
 
 /**
  * 测试父类情况
@@ -32,7 +32,7 @@ public class SuperEntityCamel extends SuSuperEntityCamel implements Serializable
 	 * serialVersionUID
 	 */
 	private static final long serialVersionUID = -531147777357149891L;
-	
+
 	/* 主键ID 注解,value 字段名,type 用户输入ID */
     @TableId(value = "testId")
     private Long id;

+ 17 - 15
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/fillperformance/FillPerformanceConfig.java

@@ -3,8 +3,8 @@ package com.baomidou.mybatisplus.test.h2.fillperformance;
 import com.baomidou.mybatisplus.core.MybatisConfiguration;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
-import com.baomidou.mybatisplus.core.handlers.StrictFill;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import org.apache.ibatis.reflection.MetaObject;
 import org.apache.ibatis.session.ExecutorType;
@@ -16,7 +16,6 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 import javax.sql.DataSource;
-import java.util.Arrays;
 
 @Configuration
 @MapperScan("com.baomidou.mybatisplus.test.h2.fillperformance.mapper")
@@ -33,8 +32,11 @@ public class FillPerformanceConfig {
         configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);
         sqlSessionFactory.setConfiguration(configuration);
         sqlSessionFactory.setGlobalConfig(new GlobalConfig().setMetaObjectHandler(metaObjectHandler()));
-        PaginationInterceptor pagination = new PaginationInterceptor();
-        sqlSessionFactory.setPlugins(pagination);
+
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
+
         return sqlSessionFactory.getObject();
     }
 
@@ -53,16 +55,16 @@ public class FillPerformanceConfig {
 //                strictInsertFill(metaObject,"j",String.class,"1234567890");
 //                strictInsertFill(metaObject,"l",String.class,"1234567890");
 //                strictInsertFill(metaObject,"m",String.class,"1234567890");
-                setFieldValByName("c","1234567890",metaObject);
-                setFieldValByName("d","1234567890",metaObject);
-                setFieldValByName("e","1234567890",metaObject);
-                setFieldValByName("f","1234567890",metaObject);
-                setFieldValByName("g","1234567890",metaObject);
-                setFieldValByName("h","1234567890",metaObject);
-                setFieldValByName("i","1234567890",metaObject);
-                setFieldValByName("j","1234567890",metaObject);
-                setFieldValByName("l","1234567890",metaObject);
-                setFieldValByName("m","1234567890",metaObject);
+                setFieldValByName("c", "1234567890", metaObject);
+                setFieldValByName("d", "1234567890", metaObject);
+                setFieldValByName("e", "1234567890", metaObject);
+                setFieldValByName("f", "1234567890", metaObject);
+                setFieldValByName("g", "1234567890", metaObject);
+                setFieldValByName("h", "1234567890", metaObject);
+                setFieldValByName("i", "1234567890", metaObject);
+                setFieldValByName("j", "1234567890", metaObject);
+                setFieldValByName("l", "1234567890", metaObject);
+                setFieldValByName("m", "1234567890", metaObject);
 //                setInsertFieldValByName("c","1234567890",metaObject);
 //                setInsertFieldValByName("d","1234567890",metaObject);
 //                setInsertFieldValByName("e","1234567890",metaObject);

+ 7 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/idgenerator/IdGeneratorConfig.java

@@ -2,7 +2,8 @@ package com.baomidou.mybatisplus.test.h2.idgenerator;
 
 import com.baomidou.mybatisplus.core.MybatisConfiguration;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -28,8 +29,11 @@ public class IdGeneratorConfig {
         configuration.setDefaultExecutorType(ExecutorType.REUSE);
         configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);
         sqlSessionFactory.setConfiguration(configuration);
-        PaginationInterceptor pagination = new PaginationInterceptor();
-        sqlSessionFactory.setPlugins(pagination);
+
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
+
         sqlSessionFactory.setGlobalConfig(globalConfig);
         return sqlSessionFactory.getObject();
     }

+ 5 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/issues/genericid/MybatisPlusConfig.java

@@ -1,7 +1,8 @@
 package com.baomidou.mybatisplus.test.h2.issues.genericid;
 
 import com.baomidou.mybatisplus.core.MybatisConfiguration;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -33,8 +34,9 @@ public class MybatisPlusConfig {
         configuration.setDefaultExecutorType(ExecutorType.REUSE);
         configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);
         sqlSessionFactory.setConfiguration(configuration);
-        PaginationInterceptor pagination = new PaginationInterceptor();
-        sqlSessionFactory.setPlugins(pagination);
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
         return sqlSessionFactory.getObject();
     }
 

+ 9 - 7
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/keygenerator/KeyGeneratorConfig.java

@@ -18,8 +18,9 @@ package com.baomidou.mybatisplus.test.h2.keygenerator;
 import com.baomidou.mybatisplus.core.MybatisConfiguration;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.SqlExplainInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -45,11 +46,12 @@ public class KeyGeneratorConfig {
         configuration.setDefaultExecutorType(ExecutorType.REUSE);
         configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);
         sqlSessionFactory.setConfiguration(configuration);
-        PaginationInterceptor pagination = new PaginationInterceptor();
-        SqlExplainInterceptor sqlExplainInterceptor = new SqlExplainInterceptor();
-        sqlSessionFactory.setPlugins(
-            pagination,
-            sqlExplainInterceptor);
+
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
+
         sqlSessionFactory.setGlobalConfig(globalConfig);
         return sqlSessionFactory.getObject();
     }

+ 4 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/keygenerator/model/LongKeyGeneratorModel.java

@@ -15,7 +15,10 @@
  */
 package com.baomidou.mybatisplus.test.h2.keygenerator.model;
 
-import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.KeySequence;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
 @Data

+ 6 - 11
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/mapper/H2UserMapper.java

@@ -15,20 +15,15 @@
  */
 package com.baomidou.mybatisplus.test.h2.mapper;
 
-import java.util.List;
-import java.util.Map;
-
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import org.apache.ibatis.annotations.Insert;
-import org.apache.ibatis.annotations.Options;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.Update;
-import org.apache.ibatis.mapping.StatementType;
-
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.test.h2.entity.H2Addr;
 import com.baomidou.mybatisplus.test.h2.entity.H2User;
+import org.apache.ibatis.annotations.*;
+import org.apache.ibatis.mapping.StatementType;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * 这里继承自定义父类 SuperMapper

+ 2 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/mapper/SuperMapper.java

@@ -15,10 +15,10 @@
  */
 package com.baomidou.mybatisplus.test.h2.mapper;
 
-import java.util.List;
-
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * 自定义父类 SuperMapper
  *

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/service/IH2UserService.java

@@ -15,13 +15,13 @@
  */
 package com.baomidou.mybatisplus.test.h2.service;
 
-import java.util.List;
-import java.util.Map;
-
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.test.h2.entity.H2User;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * Service层测试
  *

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2StudentServiceImpl.java

@@ -18,8 +18,8 @@ package com.baomidou.mybatisplus.test.h2.service.impl;
 import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
-import com.baomidou.mybatisplus.test.h2.mapper.H2StudentMapper;
 import com.baomidou.mybatisplus.test.h2.entity.H2Student;
+import com.baomidou.mybatisplus.test.h2.mapper.H2StudentMapper;
 import com.baomidou.mybatisplus.test.h2.service.IH2StudentService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;

+ 6 - 7
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/service/impl/H2UserServiceImpl.java

@@ -15,13 +15,6 @@
  */
 package com.baomidou.mybatisplus.test.h2.service.impl;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.OrderItem;
@@ -30,6 +23,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.test.h2.entity.H2User;
 import com.baomidou.mybatisplus.test.h2.mapper.H2UserMapper;
 import com.baomidou.mybatisplus.test.h2.service.IH2UserService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 
 /**
  * Service层测试

+ 44 - 44
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/tenant/CustomCacheExecutor.java

@@ -1,44 +1,44 @@
-package com.baomidou.mybatisplus.test.h2.tenant;
-
-import com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor;
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
-import org.apache.ibatis.cache.CacheKey;
-import org.apache.ibatis.executor.Executor;
-import org.apache.ibatis.mapping.BoundSql;
-import org.apache.ibatis.mapping.MappedStatement;
-import org.apache.ibatis.mapping.SqlCommandType;
-import org.apache.ibatis.session.RowBounds;
-
-import java.util.Objects;
-
-
-/**
- * @author nieqiuqiu 2020/6/15
- */
-public class CustomCacheExecutor extends MybatisCachingExecutor {
-
-    private TenantHandler tenantHandler;
-
-    public CustomCacheExecutor(Executor delegate, TenantHandler tenantHandler) {
-        super(delegate);
-        this.tenantHandler = tenantHandler;
-    }
-
-    @Override
-    public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
-        if (ms.getSqlCommandType() == SqlCommandType.SELECT) {
-            CacheKey cacheKey = super.createCacheKey(ms, parameterObject, rowBounds, boundSql);
-            cacheKey.update(Objects.toString(tenantHandler.getTenantId(true)));
-            return cacheKey;
-        }
-        return super.createCacheKey(ms, parameterObject, rowBounds, boundSql);
-    }
-
-    @Override
-    protected CacheKey getCountCacheKey(MappedStatement mappedStatement, BoundSql boundSql, Object parameterObject, RowBounds rowBounds) {
-        CacheKey countCacheKey = super.getCountCacheKey(mappedStatement, boundSql, parameterObject, rowBounds);
-        countCacheKey.update(Objects.toString(tenantHandler.getTenantId(true)));
-        return countCacheKey;
-    }
-
-}
+//package com.baomidou.mybatisplus.test.h2.tenant;
+//
+//import com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor;
+//import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
+//import org.apache.ibatis.cache.CacheKey;
+//import org.apache.ibatis.executor.Executor;
+//import org.apache.ibatis.mapping.BoundSql;
+//import org.apache.ibatis.mapping.MappedStatement;
+//import org.apache.ibatis.mapping.SqlCommandType;
+//import org.apache.ibatis.session.RowBounds;
+//
+//import java.util.Objects;
+//
+//
+///**
+// * @author nieqiuqiu 2020/6/15
+// */
+//public class CustomCacheExecutor extends MybatisCachingExecutor {
+//
+//    private TenantHandler tenantHandler;
+//
+//    public CustomCacheExecutor(Executor delegate, TenantHandler tenantHandler) {
+//        super(delegate);
+//        this.tenantHandler = tenantHandler;
+//    }
+//
+//    @Override
+//    public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
+//        if (ms.getSqlCommandType() == SqlCommandType.SELECT) {
+//            CacheKey cacheKey = super.createCacheKey(ms, parameterObject, rowBounds, boundSql);
+//            cacheKey.update(Objects.toString(tenantHandler.getTenantId(true)));
+//            return cacheKey;
+//        }
+//        return super.createCacheKey(ms, parameterObject, rowBounds, boundSql);
+//    }
+//
+//    @Override
+//    protected CacheKey getCountCacheKey(MappedStatement mappedStatement, BoundSql boundSql, Object parameterObject, RowBounds rowBounds) {
+//        CacheKey countCacheKey = super.getCountCacheKey(mappedStatement, boundSql, parameterObject, rowBounds);
+//        countCacheKey.update(Objects.toString(tenantHandler.getTenantId(true)));
+//        return countCacheKey;
+//    }
+//
+//}

+ 93 - 93
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/tenant/TenantConfig.java

@@ -1,93 +1,93 @@
-package com.baomidou.mybatisplus.test.h2.tenant;
-
-import com.baomidou.mybatisplus.core.MybatisConfiguration;
-import com.baomidou.mybatisplus.core.executor.MybatisBatchExecutor;
-import com.baomidou.mybatisplus.core.executor.MybatisReuseExecutor;
-import com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor;
-import com.baomidou.mybatisplus.core.parser.ISqlParser;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
-import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
-import net.sf.jsqlparser.expression.Expression;
-import net.sf.jsqlparser.expression.LongValue;
-import org.apache.ibatis.executor.Executor;
-import org.apache.ibatis.session.ExecutorType;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.apache.ibatis.transaction.Transaction;
-import org.apache.ibatis.type.EnumOrdinalTypeHandler;
-import org.apache.ibatis.type.JdbcType;
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import javax.sql.DataSource;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author nieqiuqiu 2019/12/8
- */
-@Configuration
-@MapperScan("com.baomidou.mybatisplus.test.h2.tenant.mapper")
-public class TenantConfig {
-
-    //模拟用户切换
-    static Long TENANT_ID = 1L;
-
-    @Bean
-    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
-        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
-        sqlSessionFactory.setDataSource(dataSource);
-        TenantSqlParser tenantSqlParser = new TenantSqlParser();
-        tenantSqlParser.setTenantHandler(new TenantHandler() {
-            @Override
-            public Expression getTenantId(boolean select) {
-                return new LongValue(TENANT_ID);
-            }
-
-            @Override
-            public String getTenantIdColumn() {
-                return "tenant_id";
-            }
-
-            @Override
-            public boolean doTableFilter(String tableName) {
-                return false;
-            }
-        });
-        MybatisConfiguration configuration = new MybatisConfiguration() {
-            @Override
-            public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
-                executorType = executorType == null ? defaultExecutorType : executorType;
-                executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
-                Executor executor;
-                if (ExecutorType.BATCH == executorType) {
-                    executor = new MybatisBatchExecutor(this, transaction);
-                } else if (ExecutorType.REUSE == executorType) {
-                    executor = new MybatisReuseExecutor(this, transaction);
-                } else {
-                    executor = new MybatisSimpleExecutor(this, transaction);
-                }
-                if (cacheEnabled) {
-                    executor = new CustomCacheExecutor(executor, tenantSqlParser.getTenantHandler());
-                }
-                executor = (Executor) interceptorChain.pluginAll(executor);
-                return executor;
-            }
-        };
-        configuration.setJdbcTypeForNull(JdbcType.NULL);
-        configuration.setMapUnderscoreToCamelCase(true);
-        configuration.setDefaultExecutorType(ExecutorType.REUSE);
-        configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);
-        configuration.setCacheEnabled(true);
-        sqlSessionFactory.setConfiguration(configuration);
-        PaginationInterceptor pagination = new PaginationInterceptor();
-        List<ISqlParser> sqlParserList = new ArrayList<>();
-        sqlParserList.add(tenantSqlParser);
-        pagination.setSqlParserList(sqlParserList);
-        sqlSessionFactory.setPlugins(pagination);
-        return sqlSessionFactory.getObject();
-    }
-
-}
+//package com.baomidou.mybatisplus.test.h2.tenant;
+//
+//import com.baomidou.mybatisplus.core.MybatisConfiguration;
+//import com.baomidou.mybatisplus.core.executor.MybatisBatchExecutor;
+//import com.baomidou.mybatisplus.core.executor.MybatisReuseExecutor;
+//import com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor;
+//import com.baomidou.mybatisplus.core.parser.ISqlParser;
+//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+//import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
+//import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
+//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
+//import net.sf.jsqlparser.expression.Expression;
+//import net.sf.jsqlparser.expression.LongValue;
+//import org.apache.ibatis.executor.Executor;
+//import org.apache.ibatis.session.ExecutorType;
+//import org.apache.ibatis.session.SqlSessionFactory;
+//import org.apache.ibatis.transaction.Transaction;
+//import org.apache.ibatis.type.EnumOrdinalTypeHandler;
+//import org.apache.ibatis.type.JdbcType;
+//import org.mybatis.spring.annotation.MapperScan;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//
+//import javax.sql.DataSource;
+//import java.util.ArrayList;
+//import java.util.List;
+//
+///**
+// * @author nieqiuqiu 2019/12/8
+// */
+//@Configuration
+//@MapperScan("com.baomidou.mybatisplus.test.h2.tenant.mapper")
+//public class TenantConfig {
+//
+//    //模拟用户切换
+//    static Long TENANT_ID = 1L;
+//
+//    @Bean
+//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
+//        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
+//        sqlSessionFactory.setDataSource(dataSource);
+//        TenantSqlParser tenantSqlParser = new TenantSqlParser();
+//        tenantSqlParser.setTenantHandler(new TenantHandler() {
+//            @Override
+//            public Expression getTenantId(boolean select) {
+//                return new LongValue(TENANT_ID);
+//            }
+//
+//            @Override
+//            public String getTenantIdColumn() {
+//                return "tenant_id";
+//            }
+//
+//            @Override
+//            public boolean doTableFilter(String tableName) {
+//                return false;
+//            }
+//        });
+//        MybatisConfiguration configuration = new MybatisConfiguration() {
+//            @Override
+//            public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
+//                executorType = executorType == null ? defaultExecutorType : executorType;
+//                executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
+//                Executor executor;
+//                if (ExecutorType.BATCH == executorType) {
+//                    executor = new MybatisBatchExecutor(this, transaction);
+//                } else if (ExecutorType.REUSE == executorType) {
+//                    executor = new MybatisReuseExecutor(this, transaction);
+//                } else {
+//                    executor = new MybatisSimpleExecutor(this, transaction);
+//                }
+//                if (cacheEnabled) {
+//                    executor = new CustomCacheExecutor(executor, tenantSqlParser.getTenantHandler());
+//                }
+//                executor = (Executor) interceptorChain.pluginAll(executor);
+//                return executor;
+//            }
+//        };
+//        configuration.setJdbcTypeForNull(JdbcType.NULL);
+//        configuration.setMapUnderscoreToCamelCase(true);
+//        configuration.setDefaultExecutorType(ExecutorType.REUSE);
+//        configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);
+//        configuration.setCacheEnabled(true);
+//        sqlSessionFactory.setConfiguration(configuration);
+//        PaginationInterceptor pagination = new PaginationInterceptor();
+//        List<ISqlParser> sqlParserList = new ArrayList<>();
+//        sqlParserList.add(tenantSqlParser);
+//        pagination.setSqlParserList(sqlParserList);
+//        sqlSessionFactory.setPlugins(pagination);
+//        return sqlSessionFactory.getObject();
+//    }
+//
+//}

+ 65 - 65
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/tenant/TenantTest.java

@@ -1,65 +1,65 @@
-package com.baomidou.mybatisplus.test.h2.tenant;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.test.h2.tenant.model.Student;
-import com.baomidou.mybatisplus.test.h2.tenant.service.IStudentService;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.MethodOrderer;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestMethodOrder;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
-import java.util.List;
-
-/**
- * @author nieqiuqiu 2019/12/8
- */
-@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
-@ExtendWith(SpringExtension.class)
-@ContextConfiguration(locations = {"classpath:h2/spring-tenant-h2.xml"})
-class TenantTest {
-
-    @Autowired
-    private IStudentService studentService;
-
-    @Test
-    void testSimple() {
-        TenantConfig.TENANT_ID = 2L;
-        Student student1 = studentService.getById(1L);
-        Assertions.assertNull(student1);
-        student1 = studentService.getById(1L);
-        Assertions.assertNull(student1);
-        TenantConfig.TENANT_ID = 1L;
-        Student student2 = studentService.getById(1L);
-        Assertions.assertNotNull(student2);
-        student2 = studentService.getById(1L);
-        Assertions.assertNotNull(student2);
-    }
-
-    @Test
-    void testPage() {
-        TenantConfig.TENANT_ID = 2L;
-        Page<Student> page1 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
-        Assertions.assertEquals(page1.getTotal(), 1);
-        page1 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
-        Assertions.assertEquals(page1.getTotal(), 1);
-        TenantConfig.TENANT_ID = 3L;
-        Page<Student> page2 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
-        Assertions.assertEquals(page2.getTotal(), 0);
-        page2 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
-        Assertions.assertEquals(page2.getTotal(), 0);
-    }
-
-    @Test
-    void testBatch() {
-        TenantConfig.TENANT_ID = 1L;
-        List<Student> list = studentService.list();
-        list.forEach(student -> student.setName("小红"));
-        studentService.updateBatchById(list);
-        studentService.list().forEach(student -> Assertions.assertEquals("小红", student.getName()));
-    }
-}
+//package com.baomidou.mybatisplus.test.h2.tenant;
+//
+//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+//import com.baomidou.mybatisplus.test.h2.tenant.model.Student;
+//import com.baomidou.mybatisplus.test.h2.tenant.service.IStudentService;
+//import org.junit.jupiter.api.Assertions;
+//import org.junit.jupiter.api.MethodOrderer;
+//import org.junit.jupiter.api.Test;
+//import org.junit.jupiter.api.TestMethodOrder;
+//import org.junit.jupiter.api.extension.ExtendWith;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.test.context.ContextConfiguration;
+//import org.springframework.test.context.junit.jupiter.SpringExtension;
+//
+//import java.util.List;
+//
+///**
+// * @author nieqiuqiu 2019/12/8
+// */
+//@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+//@ExtendWith(SpringExtension.class)
+//@ContextConfiguration(locations = {"classpath:h2/spring-tenant-h2.xml"})
+//class TenantTest {
+//
+//    @Autowired
+//    private IStudentService studentService;
+//
+//    @Test
+//    void testSimple() {
+//        TenantConfig.TENANT_ID = 2L;
+//        Student student1 = studentService.getById(1L);
+//        Assertions.assertNull(student1);
+//        student1 = studentService.getById(1L);
+//        Assertions.assertNull(student1);
+//        TenantConfig.TENANT_ID = 1L;
+//        Student student2 = studentService.getById(1L);
+//        Assertions.assertNotNull(student2);
+//        student2 = studentService.getById(1L);
+//        Assertions.assertNotNull(student2);
+//    }
+//
+//    @Test
+//    void testPage() {
+//        TenantConfig.TENANT_ID = 2L;
+//        Page<Student> page1 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
+//        Assertions.assertEquals(page1.getTotal(), 1);
+//        page1 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
+//        Assertions.assertEquals(page1.getTotal(), 1);
+//        TenantConfig.TENANT_ID = 3L;
+//        Page<Student> page2 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
+//        Assertions.assertEquals(page2.getTotal(), 0);
+//        page2 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
+//        Assertions.assertEquals(page2.getTotal(), 0);
+//    }
+//
+//    @Test
+//    void testBatch() {
+//        TenantConfig.TENANT_ID = 1L;
+//        List<Student> list = studentService.list();
+//        list.forEach(student -> student.setName("小红"));
+//        studentService.updateBatchById(list);
+//        studentService.list().forEach(student -> Assertions.assertEquals("小红", student.getName()));
+//    }
+//}

+ 1 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/config/DBConfig.java

@@ -25,9 +25,8 @@ import org.springframework.jdbc.datasource.init.DatabasePopulator;
 import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
-import java.io.IOException;
-
 import javax.sql.DataSource;
+import java.io.IOException;
 
 /**
  * @author miemie

+ 8 - 47
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/config/MybatisPlusConfig.java

@@ -20,19 +20,15 @@ import com.baomidou.mybatisplus.core.MybatisConfiguration;
 import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.injector.AbstractMethod;
 import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
-import com.baomidou.mybatisplus.core.parser.ISqlParser;
 import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
 import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;
 import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
 import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill;
-import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
-import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import com.baomidou.mybatisplus.test.mysql.MysqlMetaObjectHandler;
-import net.sf.jsqlparser.expression.Expression;
-import net.sf.jsqlparser.expression.LongValue;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.apache.ibatis.type.JdbcType;
 import org.mybatis.spring.annotation.MapperScan;
@@ -41,7 +37,6 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 
 import javax.sql.DataSource;
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -55,8 +50,7 @@ import java.util.List;
 public class MybatisPlusConfig {
 
     @Bean("mybatisSqlSession")
-    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig,
-                                               PaginationInterceptor paginationInterceptor) throws Exception {
+    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig) throws Exception {
         MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
         /* 数据源 */
         sqlSessionFactory.setDataSource(dataSource);
@@ -71,10 +65,10 @@ public class MybatisPlusConfig {
         configuration.setJdbcTypeForNull(JdbcType.NULL);
         /* 驼峰转下划线 */
         configuration.setMapUnderscoreToCamelCase(true);
-        /* 分页插件 */
-        configuration.addInterceptor(paginationInterceptor);
-        /* 乐观锁插件 */
-        configuration.addInterceptor(new OptimisticLockerInterceptor());
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
         /* map 下划线转驼峰 */
         configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
         sqlSessionFactory.setConfiguration(configuration);
@@ -107,37 +101,4 @@ public class MybatisPlusConfig {
         conf.setSqlInjector(logicSqlInjector);
         return conf;
     }
-
-    @Bean
-    public PaginationInterceptor paginationInterceptor() {
-        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
-        /*
-         * 【测试多租户】 SQL 解析处理拦截器<br>
-         * 这里固定写成住户 1 实际情况你可以从cookie读取,因此数据看不到 【 麻花藤 】 这条记录( 注意观察 SQL )<br>
-         */
-        List<ISqlParser> sqlParserList = new ArrayList<>();
-        TenantSqlParser tenantSqlParser = new TenantSqlParser();
-        tenantSqlParser.setTenantHandler(new TenantHandler() {
-
-            @Override
-            public Expression getTenantId(boolean select) {
-                return new LongValue(1L);
-            }
-
-            @Override
-            public String getTenantIdColumn() {
-                return "tenant_id";
-            }
-
-            @Override
-            public boolean doTableFilter(String tableName) {
-                // 这里可以判断是否过滤表
-                return "common_logic_data".equals(tableName) || "mysql_data".equals(tableName)
-                    || "result_map_entity".equals(tableName);
-            }
-        });
-        sqlParserList.add(tenantSqlParser);
-        paginationInterceptor.setSqlParserList(sqlParserList);
-        return paginationInterceptor;
-    }
 }

+ 0 - 4
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/phoenix/PhoenixTest.java

@@ -2,16 +2,13 @@ package com.baomidou.mybatisplus.test.phoenix;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.injector.methods.Upsert;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
 import com.baomidou.mybatisplus.test.phoenix.entity.PhoenixTestInfo;
 import com.baomidou.mybatisplus.test.phoenix.mapper.PhoenixTestInfoMapper;
-import com.mysql.cj.xdevapi.SqlStatement;
 import org.apache.ibatis.session.SqlSession;
 import org.junit.jupiter.api.MethodOrderer;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInfo;
 import org.junit.jupiter.api.TestMethodOrder;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.test.annotation.DirtiesContext;
@@ -19,7 +16,6 @@ import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import javax.annotation.Resource;
-import java.util.List;
 
 import static com.baomidou.mybatisplus.core.enums.SqlMethod.UPSERT_ONE;
 import static org.junit.jupiter.api.Assertions.assertEquals;

+ 8 - 13
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/phoenix/config/MybatisPlusConfig.java

@@ -21,15 +21,15 @@ import com.baomidou.mybatisplus.core.injector.AbstractMethod;
 import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
 import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
 import com.baomidou.mybatisplus.extension.injector.methods.Upsert;
-import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.apache.ibatis.type.JdbcType;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 
 import javax.sql.DataSource;
 import java.util.List;
@@ -47,8 +47,7 @@ public class MybatisPlusConfig {
     @Bean("mybatisSqlSession")
     public SqlSessionFactory sqlSessionFactory(
         DataSource dataSource,
-        GlobalConfig globalConfig,
-        PaginationInterceptor paginationInterceptor
+        GlobalConfig globalConfig
     ) throws Exception {
         MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
         /* 数据源 */
@@ -61,9 +60,10 @@ public class MybatisPlusConfig {
         configuration.setJdbcTypeForNull(JdbcType.NULL);
         /* 驼峰转下划线 */
         configuration.setMapUnderscoreToCamelCase(true);
-        /* 乐观锁插件 */
-        configuration.addInterceptor(new OptimisticLockerInterceptor());
-        configuration.addInterceptor(paginationInterceptor);
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
+        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
+        sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
         /* map 下划线转驼峰 */
         configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
         sqlSessionFactory.setConfiguration(configuration);
@@ -90,9 +90,4 @@ public class MybatisPlusConfig {
         conf.setSqlInjector(phoenixSqlInjector);
         return conf;
     }
-
-    @Bean
-    PaginationInterceptor paginationInterceptor() {
-        return new PaginationInterceptor();
-    }
 }

+ 5 - 5
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/reflection/ExampleObjectFactory.java

@@ -15,14 +15,14 @@
  */
 package com.baomidou.mybatisplus.test.reflection;
 
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
-
 import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+
 /**
  * 对象工厂
  * @author nieqiurong 2018/8/14 13:12.
@@ -33,7 +33,7 @@ public class ExampleObjectFactory extends DefaultObjectFactory {
 	 * serialVersionUID
 	 */
 	private static final long serialVersionUID = -2878759377109110945L;
-	
+
 	private static final Logger LOGGER = LoggerFactory.getLogger(ExampleObjectFactory.class);
 
     public <T> T create(Class<T> type) {

+ 2 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/sharding/ShardingOrder.java

@@ -1,12 +1,11 @@
 package com.baomidou.mybatisplus.test.sharding;
 
-import java.time.LocalDateTime;
-
 import com.baomidou.mybatisplus.annotation.TableId;
-
 import lombok.Data;
 import lombok.experimental.Accessors;
 
+import java.time.LocalDateTime;
+
 /**
  * @author miemie
  * @since 2020-06-24

+ 1 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/sharding/ShardingOrderMapper.java

@@ -1,8 +1,7 @@
 package com.baomidou.mybatisplus.test.sharding;
 
-import org.apache.ibatis.annotations.Param;
-
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * @author zengzhihong

+ 12 - 14
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/sharding/ShardingTest.java

@@ -1,18 +1,5 @@
 package com.baomidou.mybatisplus.test.sharding;
 
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.time.LocalDateTime;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.ibatis.plugin.Interceptor;
-import org.assertj.core.util.Lists;
-import org.junit.jupiter.api.MethodOrderer;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestMethodOrder;
-
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -22,8 +9,19 @@ import com.baomidou.mybatisplus.extension.plugins.handler.sharding.ShardingRuleE
 import com.baomidou.mybatisplus.extension.plugins.handler.sharding.ShardingStrategy;
 import com.baomidou.mybatisplus.extension.plugins.inner.ShardingInnerInterceptor;
 import com.baomidou.mybatisplus.test.BaseDbTest;
-
 import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.plugin.Interceptor;
+import org.assertj.core.util.Lists;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import java.time.LocalDateTime;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
 
 /**
  * @author zengzhihong