瀏覽代碼

Merge remote-tracking branch 'origin/3.0' into 3.0

聂秋秋 5 年之前
父節點
當前提交
753af410e4
共有 53 個文件被更改,包括 427 次插入1386 次删除
  1. 1 2
      build.gradle
  2. 3 0
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/executor/AbstractBaseExecutor.java
  3. 78 7
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/executor/MybatisCachingExecutor.java
  4. 1 0
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/incrementer/IdGenerator.java
  5. 4 0
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/incrementer/SnowflakeIdGenerator.java
  6. 4 4
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/AbstractMethod.java
  7. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/DeleteBatchByIds.java
  8. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/DeleteById.java
  9. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/SelectBatchByIds.java
  10. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/SelectById.java
  11. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/UpdateById.java
  12. 11 2
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/PageList.java
  13. 17 9
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java
  14. 5 7
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/override/MybatisMapperMethod.java
  15. 4 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/EnumUtils.java
  16. 54 37
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/handlers/MybatisEnumTypeHandler.java
  17. 1 1
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/additional/AlwaysUpdateSomeColumnById.java
  18. 3 3
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/additional/LogicDeleteByIdWithFill.java
  19. 9 6
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java
  20. 2 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/SampleTest.java
  21. 0 386
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/BaseDbTest.java
  22. 24 0
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/CacheTest.java
  23. 12 8
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2KeyGeneratorTest.java
  24. 6 8
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/keygenerator/mapper/IntegerKeyGeneratorMapper.java
  25. 11 23
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/keygenerator/model/IntegerKeyGeneratorModel.java
  26. 1 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/MyBaseMapper.java
  27. 90 283
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/MysqlTestDataMapperTest.java
  28. 4 4
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/SelectCountDistinctTest.java
  29. 2 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/config/MybatisPlusConfig.java
  30. 2 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/CommonData.java
  31. 1 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/CommonLogicData.java
  32. 39 0
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/FillTenantEnumVersion.java
  33. 4 4
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/ResultMapEntity.java
  34. 1 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/enums/TestEnum.java
  35. 1 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/MysqlDataMapper.java
  36. 3 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/children/CommonDataChildrenMapper.java
  37. 3 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/children/CommonLogicDataChildrenMapper.java
  38. 2 2
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/commons/CommonDataCopyMapper.java
  39. 3 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/commons/CommonDataMapper.java
  40. 3 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/commons/CommonLogicDataMapper.java
  41. 3 3
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/commons/ResultMapEntityMapper.java
  42. 1 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/type/JsonTypeHandler.java
  43. 1 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/type/ListTypeHandler.java
  44. 1 1
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/type/MapTypeHandler.java
  45. 0 60
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/PostgresMetaObjectHandler.java
  46. 0 231
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/PostgresTestDataMapperTest.java
  47. 0 72
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/config/DBConfig.java
  48. 0 111
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/config/MybatisPlusConfig.java
  49. 0 36
      mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/entity/PgData.java
  50. 1 1
      mybatis-plus/src/test/resources/logback.xml
  51. 6 6
      mybatis-plus/src/test/resources/mapper/ResultMapEntityMapper.xml
  52. 0 9
      mybatis-plus/src/test/resources/postgres/spring-test-postgres.xml
  53. 0 30
      mybatis-plus/src/test/resources/postgres/test_data.ddl.sql

+ 1 - 2
build.gradle

@@ -81,7 +81,7 @@ ext {
 
 allprojects {
     group = 'com.baomidou'
-    version = "3.2.0"
+    version = "3.2.1.1-SNAPSHOT"
 }
 
 description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"
@@ -171,7 +171,6 @@ subprojects {
         dependsOn("cleanTest", "generatePomFileForMavenJavaPublication")
         useJUnitPlatform()
         exclude("**/generator/**")
-        exclude("**/postgres/**")
         exclude("**/mysql/**")
     }
 

+ 3 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/executor/AbstractBaseExecutor.java

@@ -61,11 +61,14 @@ public abstract class AbstractBaseExecutor extends BaseExecutor {
                 IPage<?> page = (IPage) optional.get().getValue();
                 offset = page.getCurrent();
                 limit = page.getSize();
+                //折磨人的小妖精,只能当缓存条件了,避免缓存错误命中.
+                cacheKey.update(page.isSearchCount());
             }
         } else if (parameterObject instanceof IPage) {
             IPage<?> page = (IPage) parameterObject;
             offset = page.getCurrent();
             limit = page.getSize();
+            cacheKey.update(page.isSearchCount());
         }
         cacheKey.update(offset);
         cacheKey.update(limit);

+ 78 - 7
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/executor/MybatisCachingExecutor.java

@@ -15,9 +15,9 @@
  */
 package com.baomidou.mybatisplus.core.executor;
 
-import com.baomidou.mybatisplus.core.metadata.CachePage;
-import com.baomidou.mybatisplus.core.metadata.CachePageResult;
+import com.baomidou.mybatisplus.core.metadata.PageList;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import org.apache.ibatis.cache.Cache;
 import org.apache.ibatis.cache.CacheKey;
 import org.apache.ibatis.cache.TransactionalCacheManager;
@@ -27,9 +27,11 @@ import org.apache.ibatis.executor.Executor;
 import org.apache.ibatis.executor.ExecutorException;
 import org.apache.ibatis.mapping.*;
 import org.apache.ibatis.reflection.MetaObject;
+import org.apache.ibatis.session.Configuration;
 import org.apache.ibatis.session.ResultHandler;
 import org.apache.ibatis.session.RowBounds;
 import org.apache.ibatis.transaction.Transaction;
+import org.apache.ibatis.type.TypeHandlerRegistry;
 
 import java.sql.SQLException;
 import java.util.List;
@@ -115,23 +117,92 @@ public class MybatisCachingExecutor implements Executor {
                 ensureNoOutParams(ms, boundSql);
                 Object result = tcm.getObject(cache, key);
                 if (result == null) {
-                    result = delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
                     if (page != null) {
+                        CacheKey countCacheKey = null;
+                        if (page.isSearchCount()) {
+                            // 这里的执行sql为原select语句,标准一点的是需要将此转换为count语句当做缓存key的,留做当优化把.
+                            countCacheKey = getCountCacheKey(ms, boundSql, parameterObject, RowBounds.DEFAULT);
+                        }
+                        // 切勿将这提取至上方,如果先查的话,需要提前将boundSql拷贝一份
+                        result = delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
                         List<E> records = (List<E>) result;
-                        CachePage<E> cachePage = new CachePage<>(records, page.getTotal());
                         page.setRecords(records);
-                        tcm.putObject(cache, key, cachePage);
-                        return new CachePageResult((cachePage));
+                        tcm.putObject(cache, key, records);
+                        if (countCacheKey != null) {
+                            tcm.putObject(cache, countCacheKey, page.getTotal());
+                        }
+                        return new PageList(records, page.getTotal());
                     } else {
+                        result = delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
                         tcm.putObject(cache, key, result); // issue #578 and #116
+                        return (List<E>) result;
+                    }
+                } else {
+                    Long count;
+                    if (page != null) {
+                        if (page.isSearchCount()) {
+                            CacheKey cacheKey = getCountCacheKey(ms, boundSql, parameterObject, RowBounds.DEFAULT);
+                            count = (Long) tcm.getObject(cache, cacheKey);
+                            return new PageList((List) result, count);
+                        }
+                        return new PageList((List) result, 0L);
+                    } else {
+                        return (List<E>) result;
                     }
                 }
-                return page != null ? new CachePageResult((CachePage) result) : (List<E>) result;
             }
         }
         return delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
     }
 
+    private MappedStatement buildCountMappedStatement(MappedStatement mappedStatement) {
+        // 暂时补充点属性,留着后面分离count查询,这里暂时用到的也就只有id,所以不会影响后面的流程.
+        return new MappedStatement.Builder(mappedStatement.getConfiguration(), mappedStatement.getId() + StringPool.DOT + "count", mappedStatement.getSqlSource(), SqlCommandType.SELECT)
+            .useCache(true)
+            .flushCacheRequired(false)
+            .lang(mappedStatement.getLang())
+            .resource(mappedStatement.getResource())
+            .databaseId(mappedStatement.getDatabaseId())
+            .cache(mappedStatement.getCache())
+            .build();
+    }
+
+    private CacheKey getCountCacheKey(MappedStatement mappedStatement, BoundSql boundSql, Object parameterObject, RowBounds rowBounds) {
+        Configuration configuration = mappedStatement.getConfiguration();
+//        BoundSql sourceSql = new BoundSql(mappedStatement.getConfiguration(), boundSql.getSql(), boundSql.getParameterMappings(), boundSql.getParameterObject());
+        MappedStatement statement = buildCountMappedStatement(mappedStatement);
+        CacheKey cacheKey = new CacheKey();
+        cacheKey.update(statement.getId());
+        cacheKey.update(rowBounds.getOffset());
+        cacheKey.update(rowBounds.getLimit());
+        cacheKey.update(boundSql.getSql());
+        List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
+        TypeHandlerRegistry typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
+        // mimic DefaultParameterHandler logic
+        for (ParameterMapping parameterMapping : parameterMappings) {
+            if (parameterMapping.getMode() != ParameterMode.OUT) {
+                Object value;
+                String propertyName = parameterMapping.getProperty();
+                if (boundSql.hasAdditionalParameter(propertyName)) {
+                    value = boundSql.getAdditionalParameter(propertyName);
+                } else if (parameterObject == null) {
+                    value = null;
+                } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
+                    value = parameterObject;
+                } else {
+                    MetaObject metaObject = configuration.newMetaObject(parameterObject);
+                    value = metaObject.getValue(propertyName);
+                }
+                cacheKey.update(value);
+            }
+        }
+        if (configuration.getEnvironment() != null) {
+            // issue #176
+            cacheKey.update(configuration.getEnvironment().getId());
+        }
+        return cacheKey;
+    }
+
     @Override
     public List<BatchResult> flushStatements() throws SQLException {
         return delegate.flushStatements();

+ 1 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/incrementer/IdGenerator.java

@@ -23,6 +23,7 @@ package com.baomidou.mybatisplus.core.incrementer;
  * @date 2019/10/15
  */
 public interface IdGenerator {
+
     /**
      * 生成Id
      *

+ 4 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/incrementer/SnowflakeIdGenerator.java

@@ -35,6 +35,10 @@ public class SnowflakeIdGenerator implements IdGenerator {
         this.sequence = new Sequence(workerId, dataCenterId);
     }
 
+    public SnowflakeIdGenerator(Sequence sequence) {
+        this.sequence = sequence;
+    }
+
     @Override
     public long nextId(Object entity) {
         return sequence.nextId();

+ 4 - 4
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/AbstractMethod.java

@@ -81,7 +81,7 @@ public abstract class AbstractMethod implements Constants {
      * @return sql set 片段
      */
     protected String sqlLogicSet(TableInfo table) {
-        return "SET " + table.getLogicDeleteSql(false, true);
+        return "SET " + table.getLogicDeleteSql(false, false);
     }
 
     /**
@@ -169,7 +169,7 @@ public abstract class AbstractMethod implements Constants {
                 " ${k} = #{v} ");
             sqlScript = SqlScriptUtils.convertForeach(sqlScript, "cm", "k", "v", "AND");
             sqlScript = SqlScriptUtils.convertIf(sqlScript, "cm != null and !cm.isEmpty", true);
-            sqlScript += (NEWLINE + table.getLogicDeleteSql(true, false));
+            sqlScript += (NEWLINE + table.getLogicDeleteSql(true, true));
             sqlScript = SqlScriptUtils.convertWhere(sqlScript);
             return sqlScript;
         } else {
@@ -195,7 +195,7 @@ public abstract class AbstractMethod implements Constants {
             String sqlScript = table.getAllSqlWhere(true, true, WRAPPER_ENTITY_DOT);
             sqlScript = SqlScriptUtils.convertIf(sqlScript, String.format("%s != null", WRAPPER_ENTITY),
                 true);
-            sqlScript += (NEWLINE + table.getLogicDeleteSql(true, false) + NEWLINE);
+            sqlScript += (NEWLINE + table.getLogicDeleteSql(true, true) + NEWLINE);
             String normalSqlScript = SqlScriptUtils.convertIf(String.format("AND ${%s}", WRAPPER_SQLSEGMENT),
                 String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT,
                     WRAPPER_NONEMPTYOFNORMAL), true);
@@ -205,7 +205,7 @@ public abstract class AbstractMethod implements Constants {
                     WRAPPER_EMPTYOFNORMAL), true);
             sqlScript += normalSqlScript;
             sqlScript = SqlScriptUtils.convertChoose(String.format("%s != null", WRAPPER), sqlScript,
-                table.getLogicDeleteSql(false, false));
+                table.getLogicDeleteSql(false, true));
             sqlScript = SqlScriptUtils.convertWhere(sqlScript);
             return newLine ? NEWLINE + sqlScript : sqlScript;
         } else {

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/DeleteBatchByIds.java

@@ -38,7 +38,7 @@ public class DeleteBatchByIds extends AbstractMethod {
             sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
                 tableInfo.getKeyColumn(),
                 SqlScriptUtils.convertForeach("#{item}", COLLECTION, null, "item", COMMA),
-                tableInfo.getLogicDeleteSql(true, false));
+                tableInfo.getLogicDeleteSql(true, true));
             SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
             return addUpdateMappedStatement(mapperClass, modelClass, getMethod(sqlMethod), sqlSource);
         } else {

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/DeleteById.java

@@ -36,7 +36,7 @@ public class DeleteById extends AbstractMethod {
         if (tableInfo.isLogicDelete()) {
             sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
                 tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
-                tableInfo.getLogicDeleteSql(true, false));
+                tableInfo.getLogicDeleteSql(true, true));
             SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);
             return addUpdateMappedStatement(mapperClass, modelClass, getMethod(sqlMethod), sqlSource);
         } else {

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/SelectBatchByIds.java

@@ -36,7 +36,7 @@ public class SelectBatchByIds extends AbstractMethod {
         SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(),
             sqlSelectColumns(tableInfo, false), tableInfo.getTableName(), tableInfo.getKeyColumn(),
             SqlScriptUtils.convertForeach("#{item}", COLLECTION, null, "item", COMMA),
-            tableInfo.getLogicDeleteSql(true, false)), Object.class);
+            tableInfo.getLogicDeleteSql(true, true)), Object.class);
         return addSelectMappedStatementForTable(mapperClass, getMethod(sqlMethod), sqlSource, tableInfo);
     }
 }

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/SelectById.java

@@ -36,7 +36,7 @@ public class SelectById extends AbstractMethod {
         SqlSource sqlSource = new RawSqlSource(configuration, String.format(sqlMethod.getSql(),
             sqlSelectColumns(tableInfo, false),
             tableInfo.getTableName(), tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
-            tableInfo.getLogicDeleteSql(true, false)), Object.class);
+            tableInfo.getLogicDeleteSql(true, true)), Object.class);
         return this.addSelectMappedStatementForTable(mapperClass, getMethod(sqlMethod), sqlSource, tableInfo);
     }
 }

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/methods/UpdateById.java

@@ -33,7 +33,7 @@ public class UpdateById extends AbstractMethod {
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
         boolean logicDelete = tableInfo.isLogicDelete();
         SqlMethod sqlMethod = SqlMethod.UPDATE_BY_ID;
-        final String additional = optlockVersion() + tableInfo.getLogicDeleteSql(true, false);
+        final String additional = optlockVersion() + tableInfo.getLogicDeleteSql(true, true);
         String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(),
             sqlSet(logicDelete, false, tableInfo, false, ENTITY, ENTITY_DOT),
             tableInfo.getKeyColumn(), ENTITY_DOT + tableInfo.getKeyProperty(), additional);

+ 11 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/CachePageResult.java → mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/PageList.java

@@ -20,6 +20,7 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 受限于SqlSession#selectList(java.lang.String, java.lang.Object)
@@ -30,8 +31,16 @@ import java.util.ArrayList;
 @Data
 @AllArgsConstructor
 @EqualsAndHashCode(callSuper = true)
-public final class CachePageResult extends ArrayList {
+public final class PageList<T> extends ArrayList<T> {
 
-    private CachePage cachePage;
+    /**
+     * 记录数
+     */
+    private List<T> records;
+
+    /**
+     * 总数
+     */
+    private long total;
 
 }

+ 17 - 9
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java

@@ -324,14 +324,14 @@ public class TableInfo implements Constants {
      * 获取逻辑删除字段的 sql 脚本
      *
      * @param startWithAnd 是否以 and 开头
-     * @param deleteValue  是否需要的是逻辑删除值
+     * @param isWhere      是否需要的是逻辑删除值
      * @return sql 脚本
      */
-    public String getLogicDeleteSql(boolean startWithAnd, boolean deleteValue) {
+    public String getLogicDeleteSql(boolean startWithAnd, boolean isWhere) {
         if (logicDelete) {
             TableFieldInfo field = fieldList.stream().filter(TableFieldInfo::isLogicDelete).findFirst()
                 .orElseThrow(() -> ExceptionUtils.mpe("can't find the logicFiled from table {%s}", tableName));
-            String logicDeleteSql = formatLogicDeleteSql(field, deleteValue);
+            String logicDeleteSql = formatLogicDeleteSql(field, isWhere);
             if (startWithAnd) {
                 logicDeleteSql = " AND " + logicDeleteSql;
             }
@@ -344,16 +344,24 @@ public class TableInfo implements Constants {
      * format logic delete SQL, can be overrided by subclass
      * github #1386
      *
-     * @param field       TableFieldInfo
-     * @param deleteValue true: logicDeleteValue, false: logicNotDeleteValue
+     * @param field   TableFieldInfo
+     * @param isWhere true: logicDeleteValue, false: logicNotDeleteValue
      * @return
      */
-    protected String formatLogicDeleteSql(TableFieldInfo field, boolean deleteValue) {
-        String value = deleteValue ? field.getLogicDeleteValue() : field.getLogicNotDeleteValue();
+    protected String formatLogicDeleteSql(TableFieldInfo field, boolean isWhere) {
+        final String value = isWhere ? field.getLogicNotDeleteValue() : field.getLogicDeleteValue();
+        if (isWhere) {
+            if (NULL.equalsIgnoreCase(value)) {
+                return field.getColumn() + " IS NULL";
+            } else {
+                return field.getColumn() + EQUALS + String.format(field.isCharSequence() ? "'%s'" : "%s", value);
+            }
+        }
+        final String targetStr = field.getColumn() + EQUALS;
         if (NULL.equalsIgnoreCase(value)) {
-            return field.getColumn() + " is NULL";
+            return targetStr + NULL;
         } else {
-            return field.getColumn() + EQUALS + String.format(field.isCharSequence() ? "'%s'" : "%s", value);
+            return targetStr + String.format(field.isCharSequence() ? "'%s'" : "%s", value);
         }
     }
 

+ 5 - 7
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/override/MybatisMapperMethod.java

@@ -15,8 +15,7 @@
  */
 package com.baomidou.mybatisplus.core.override;
 
-import com.baomidou.mybatisplus.core.metadata.CachePage;
-import com.baomidou.mybatisplus.core.metadata.CachePageResult;
+import com.baomidou.mybatisplus.core.metadata.PageList;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.binding.BindingException;
 import org.apache.ibatis.binding.MapperMethod;
@@ -95,11 +94,10 @@ public class MybatisMapperMethod {
                         }
                         assert page != null;
                         result = executeForIPage(sqlSession, args);
-                        if (result instanceof CachePageResult) {
-                            CachePageResult cachePageResult = (CachePageResult) result;
-                            CachePage cachePage = cachePageResult.getCachePage();
-                            page.setRecords(cachePage.getRecords());
-                            page.setTotal(cachePage.getTotal());
+                        if (result instanceof PageList) {
+                            PageList pageList = (PageList) result;
+                            page.setRecords(pageList.getRecords());
+                            page.setTotal(pageList.getTotal());
                             result = page;
                         } else {
                             List list = (List<Object>) result;

+ 4 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/EnumUtils.java

@@ -27,7 +27,9 @@ import java.util.Objects;
  *
  * @author hubin
  * @since 2017-10-11
+ * @deprecated 3.2.1
  */
+@Deprecated
 public class EnumUtils {
 
     /**
@@ -37,8 +39,9 @@ public class EnumUtils {
      * @param value     枚举值
      * @param method    取值方法
      * @param <E>       对应枚举
-     * @return
+     * @return @deprecated 3.2.1
      */
+    @Deprecated
     public static <E extends Enum<?>> E valueOf(Class<E> enumClass, Object value, Method method) {
         E[] es = enumClass.getEnumConstants();
         for (E e : es) {

+ 54 - 37
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/handlers/MybatisEnumTypeHandler.java

@@ -17,23 +17,21 @@ package com.baomidou.mybatisplus.extension.handlers;
 
 import com.baomidou.mybatisplus.annotation.EnumValue;
 import com.baomidou.mybatisplus.core.enums.IEnum;
-import com.baomidou.mybatisplus.core.toolkit.EnumUtils;
 import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
+import org.apache.ibatis.reflection.*;
+import org.apache.ibatis.reflection.invoker.Invoker;
 import org.apache.ibatis.type.BaseTypeHandler;
 import org.apache.ibatis.type.JdbcType;
 
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import java.math.BigDecimal;
 import java.sql.CallableStatement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -45,49 +43,39 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 public class MybatisEnumTypeHandler<E extends Enum<?>> extends BaseTypeHandler<Enum<?>> {
 
-    private static final Log LOGGER = LogFactory.getLog(MybatisEnumTypeHandler.class);
-    
-    private static final Map<Class<?>, Method> TABLE_METHOD_OF_ENUM_TYPES = new ConcurrentHashMap<>();
-    
+    private static ReflectorFactory reflectorFactory = new DefaultReflectorFactory();
+
+    private static final Map<String, String> TABLE_METHOD_OF_ENUM_TYPES = new ConcurrentHashMap<>();
+
     private final Class<E> type;
-    
-    private final Method method;
+
+    private Invoker invoker;
 
     public MybatisEnumTypeHandler(Class<E> type) {
         if (type == null) {
             throw new IllegalArgumentException("Type argument cannot be null");
         }
         this.type = type;
-        if (IEnum.class.isAssignableFrom(type)) {
-            try {
-                this.method = type.getMethod("getValue");
-            } catch (NoSuchMethodException e) {
-                throw new IllegalArgumentException(String.format("NoSuchMethod getValue() in Class: %s.", type.getName()));
-            }
-        } else {
-            this.method = TABLE_METHOD_OF_ENUM_TYPES.computeIfAbsent(type, k -> {
+        MetaClass metaClass = MetaClass.forClass(type, reflectorFactory);
+        String name = "value";
+        if (!IEnum.class.isAssignableFrom(type)) {
+            name = TABLE_METHOD_OF_ENUM_TYPES.computeIfAbsent(type.getName(), k -> {
                 Field field = dealEnumType(this.type).orElseThrow(() -> new IllegalArgumentException(String.format("Could not find @EnumValue in Class: %s.", type.getName())));
-                return ReflectionKit.getMethod(this.type, field);
+                return field.getName();
             });
         }
+        this.invoker = metaClass.getGetInvoker(name);
     }
-    
+
     @SuppressWarnings("Duplicates")
     @Override
     public void setNonNullParameter(PreparedStatement ps, int i, Enum<?> parameter, JdbcType jdbcType)
         throws SQLException {
-        try {
-            this.method.setAccessible(true);
-            if (jdbcType == null) {
-                ps.setObject(i, this.method.invoke(parameter));
-            } else {
-                // see r3589
-                ps.setObject(i, this.method.invoke(parameter), jdbcType.TYPE_CODE);
-            }
-        } catch (IllegalAccessException e) {
-            LOGGER.error("unrecognized jdbcType, failed to set StringValue for type=" + parameter);
-        } catch (InvocationTargetException e) {
-            throw ExceptionUtils.mpe("Error: NoSuchMethod in %s.  Cause:", e, this.type.getName());
+        if (jdbcType == null) {
+            ps.setObject(i, this.getValue(parameter));
+        } else {
+            // see r3589
+            ps.setObject(i, this.getValue(parameter), jdbcType.TYPE_CODE);
         }
     }
 
@@ -96,7 +84,7 @@ public class MybatisEnumTypeHandler<E extends Enum<?>> extends BaseTypeHandler<E
         if (null == rs.getObject(columnName) && rs.wasNull()) {
             return null;
         }
-        return EnumUtils.valueOf(this.type, rs.getObject(columnName), this.method);
+        return this.valueOf(this.type, rs.getObject(columnName));
     }
 
     @Override
@@ -104,7 +92,7 @@ public class MybatisEnumTypeHandler<E extends Enum<?>> extends BaseTypeHandler<E
         if (null == rs.getObject(columnIndex) && rs.wasNull()) {
             return null;
         }
-        return EnumUtils.valueOf(this.type, rs.getObject(columnIndex), this.method);
+        return this.valueOf(this.type, rs.getObject(columnIndex));
     }
 
     @Override
@@ -112,10 +100,39 @@ public class MybatisEnumTypeHandler<E extends Enum<?>> extends BaseTypeHandler<E
         if (null == cs.getObject(columnIndex) && cs.wasNull()) {
             return null;
         }
-        return EnumUtils.valueOf(this.type, cs.getObject(columnIndex), this.method);
+        return this.valueOf(this.type, cs.getObject(columnIndex));
     }
 
     public static Optional<Field> dealEnumType(Class<?> clazz) {
         return clazz.isEnum() ? Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.isAnnotationPresent(EnumValue.class)).findFirst() : Optional.empty();
     }
+
+    private <E extends Enum<?>> E valueOf(Class<E> enumClass, Object value) {
+        E[] es = enumClass.getEnumConstants();
+        return Arrays.stream(es).filter((e) -> equalsValue(value, getValue(e))).findAny().orElse(null);
+    }
+
+    /**
+     * 值比较
+     *
+     * @param sourceValue 数据库字段值
+     * @param targetValue 当前枚举属性值
+     * @return 是否匹配
+     * @since 3.2.1
+     */
+    protected boolean equalsValue(Object sourceValue, Object targetValue) {
+        if (sourceValue instanceof Number && targetValue instanceof Number
+            && new BigDecimal(String.valueOf(sourceValue)).compareTo(new BigDecimal(String.valueOf(targetValue))) == 0) {
+            return true;
+        }
+        return Objects.equals(sourceValue, targetValue);
+    }
+
+    private Object getValue(Object object) {
+        try {
+            return invoker.invoke(object, new Object[0]);
+        } catch (ReflectiveOperationException e) {
+            throw ExceptionUtils.mpe(e);
+        }
+    }
 }

+ 1 - 1
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/additional/AlwaysUpdateSomeColumnById.java

@@ -58,7 +58,7 @@ public class AlwaysUpdateSomeColumnById extends AbstractMethod {
     @Override
     public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
         SqlMethod sqlMethod = SqlMethod.UPDATE_BY_ID;
-        final String additional = optlockVersion() + tableInfo.getLogicDeleteSql(true, false);
+        final String additional = optlockVersion() + tableInfo.getLogicDeleteSql(true, true);
         String sqlSet = this.filterTableFieldInfo(tableInfo.getFieldList(), getPredicate(),
             i -> i.getSqlSet(true, ENTITY_DOT), NEWLINE);
         sqlSet = SqlScriptUtils.convertSet(sqlSet);

+ 3 - 3
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/injector/methods/additional/LogicDeleteByIdWithFill.java

@@ -54,13 +54,13 @@ public class LogicDeleteByIdWithFill extends AbstractMethod {
                 .collect(toList());
             if (CollectionUtils.isNotEmpty(fieldInfos)) {
                 String sqlSet = "SET " + fieldInfos.stream().map(i -> i.getSqlSet(EMPTY)).collect(joining(EMPTY))
-                    + tableInfo.getLogicDeleteSql(false, true);
+                    + tableInfo.getLogicDeleteSql(false, false);
                 sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlSet, tableInfo.getKeyColumn(),
-                    tableInfo.getKeyProperty(), tableInfo.getLogicDeleteSql(true, false));
+                    tableInfo.getKeyProperty(), tableInfo.getLogicDeleteSql(true, true));
             } else {
                 sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
                     tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
-                    tableInfo.getLogicDeleteSql(true, false));
+                    tableInfo.getLogicDeleteSql(true, true));
             }
         } else {
             sqlMethod = SqlMethod.DELETE_BY_ID;

+ 9 - 6
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java

@@ -118,12 +118,13 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
         String sqlStatement = sqlStatement(SqlMethod.INSERT_ONE);
         int size = entityList.size();
         try (SqlSession batchSqlSession = sqlSessionBatch()) {
-            int i = 0;
+            int i = 1;
             for (T entity : entityList) {
                 batchSqlSession.insert(sqlStatement, entity);
-                if ((i++ >= 1 && i % batchSize == 0) || i == size) {
+                if ((i % batchSize == 0) || i == size) {
                     batchSqlSession.flushStatements();
                 }
+                i++;
             }
         }
         return true;
@@ -162,7 +163,7 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
         Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");
         int size = entityList.size();
         try (SqlSession batchSqlSession = sqlSessionBatch()) {
-            int i = 0;
+            int i = 1;
             for (T entity : entityList) {
                 Object idVal = ReflectionKit.getMethodValue(cls, entity, keyProperty);
                 if (StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal))) {
@@ -173,9 +174,10 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
                     batchSqlSession.update(sqlStatement(SqlMethod.UPDATE_BY_ID), param);
                 }
                 // 不知道以后会不会有人说更新失败了还要执行插入 😂😂😂
-                if ((i++ >= 1 && i % batchSize == 0) || i == size) {
+                if ((i % batchSize == 0) || i == size) {
                     batchSqlSession.flushStatements();
                 }
+                i++;
             }
         }
         return true;
@@ -220,14 +222,15 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
         SqlHelper.clearCache(currentModelClass());
         int size = entityList.size();
         try (SqlSession batchSqlSession = sqlSessionBatch()) {
-            int i = 0;
+            int i = 1;
             for (T anEntityList : entityList) {
                 MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
                 param.put(Constants.ENTITY, anEntityList);
                 batchSqlSession.update(sqlStatement, param);
-                if ((i++ >= 1 && i % batchSize == 0) || i == size) {
+                if ((i % batchSize == 0) || i == size) {
                     batchSqlSession.flushStatements();
                 }
+                i++;
             }
         }
         return true;

+ 2 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/SampleTest.java

@@ -19,8 +19,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.TableInfo;
 import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.test.base.entity.CommonData;
-import com.baomidou.mybatisplus.test.base.entity.CommonLogicData;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonData;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonLogicData;
 import org.apache.ibatis.reflection.DefaultReflectorFactory;
 import org.apache.ibatis.reflection.MetaClass;
 import org.junit.jupiter.api.Test;

+ 0 - 386
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/BaseDbTest.java

@@ -1,386 +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.base;
-
-import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.MybatisConfiguration;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.metadata.OrderItem;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.test.base.entity.CommonData;
-import com.baomidou.mybatisplus.test.base.entity.CommonLogicData;
-import com.baomidou.mybatisplus.test.base.entity.ResultMapEntity;
-import com.baomidou.mybatisplus.test.base.enums.TestEnum;
-import com.baomidou.mybatisplus.test.base.mapper.children.CommonDataChildrenMapper;
-import com.baomidou.mybatisplus.test.base.mapper.children.CommonLogicDataChildrenMapper;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonDataCopyMapper;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonDataMapper;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonLogicDataMapper;
-import com.baomidou.mybatisplus.test.base.mapper.commons.ResultMapEntityMapper;
-import org.apache.ibatis.mapping.MappedStatement;
-import org.apache.ibatis.session.Configuration;
-import org.apache.ibatis.session.SqlSessionFactory;
-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.annotation.DirtiesContext;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
-import javax.annotation.Resource;
-import java.util.*;
-
-import static java.util.function.Function.identity;
-import static java.util.stream.Collectors.toMap;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.*;
-
-/**
- * @author miemie
- * @since 2019-03-06
- */
-@DirtiesContext
-@TestMethodOrder(MethodOrderer.Alphanumeric.class)
-@ExtendWith(SpringExtension.class)
-public abstract class BaseDbTest {
-    protected final int success = 1;
-    protected final int fail = 0;
-
-    protected final List<String> list = Arrays.asList("1", "2", "3");
-    protected final Map<String, Object> map = list.parallelStream().collect(toMap(identity(), identity()));
-    @Resource(name = "commonDataMapper")
-    protected CommonDataMapper commonDataMapper;
-    @Resource(name = "commonDataChildrenMapper")
-    protected CommonDataChildrenMapper commonDataChildrenMapper;
-    @Resource(name = "commonLogicDataMapper")
-    protected CommonLogicDataMapper commonLogicDataMapper;
-    @Resource(name = "commonLogicDataChildrenMapper")
-    protected CommonLogicDataChildrenMapper commonLogicDataChildrenMapper;
-    @Resource
-    protected CommonDataCopyMapper commonDataCopyMapper;
-    @Resource
-    protected ResultMapEntityMapper resultMapEntityMapper;
-    @Autowired
-    private SqlSessionFactory sqlSessionFactory;
-
-    @Test
-    void a00() {
-        Configuration configuration = sqlSessionFactory.getConfiguration();
-        assertThat(configuration).isInstanceOf(MybatisConfiguration.class);
-        MappedStatement mappedStatement = configuration.getMappedStatement("com.baomidou.mybatisplus.test.mysql.mapper.MysqlDataMapper.getRandomOne");
-        assertThat(mappedStatement).isNotNull();
-    }
-
-    @Test
-    void a01_insertForeach() {
-        for (int i = 1; i < 20; i++) {
-            Long id = (long) i;
-            String str = String.format("第%s条数据", i);
-            commonDataMapper.insert(new CommonData().setTestInt(i).setTestStr(str).setId(id)
-                .setTestEnum(TestEnum.ONE));
-            commonLogicDataMapper.insert(new CommonLogicData().setTestInt(i).setTestStr(str).setId(id));
-            resultMapEntityMapper.insert(new ResultMapEntity().setId(id).setList(list).setMap(map).setMapp(map));
-            this.insertForeach(id, i, str);
-        }
-    }
-
-    protected abstract void insertForeach(Long id, int index, String str);
-
-    @Test
-    void a02_insertBatch() {
-        int size = 9;
-        List<CommonData> commonDataList = new ArrayList<>();
-        List<CommonLogicData> commonLogicDataList = new ArrayList<>();
-        for (int i = 0; i < size; i++) {
-            String str = i + "条";
-            commonDataList.add(new CommonData().setTestInt(i).setTestEnum(TestEnum.TWO).setTestStr(str));
-            commonLogicDataList.add(new CommonLogicData().setTestInt(i).setTestStr(str));
-        }
-        assertEquals(size, commonDataMapper.insertBatchSomeColumn(commonDataList));
-        assertEquals(size, commonLogicDataMapper.insertBatchSomeColumn(commonLogicDataList));
-        this.insertBatch(size);
-    }
-
-    protected abstract void insertBatch(int size);
-
-    @Test
-    void a03_deleteById() {
-        long id = 1L;
-        assertEquals(success, commonDataMapper.deleteById(id));
-        assertEquals(success, commonLogicDataMapper.deleteById(id));
-        this.deleteById(id);
-    }
-
-    protected abstract void deleteById(long id);
-
-    @Test
-    void a04_deleteByMap() {
-        long id = 2L;
-        Map<String, Object> map = new HashMap<>();
-        map.put("id", id);
-        map.put("test_int", 5);
-        assertEquals(fail, commonDataMapper.deleteByMap(map));
-        assertEquals(fail, commonLogicDataMapper.deleteByMap(map));
-        this.deleteByMap_fail(id);
-    }
-
-    protected abstract void deleteByMap_fail(long id);
-
-    @Test
-    void a05_delete() {
-        long id = 2L;
-        assertEquals(success, commonDataMapper.delete(Wrappers.<CommonData>lambdaQuery()
-            .eq(CommonData::getId, id)
-            .eq(CommonData::getTestInt, 2)));
-        assertEquals(success, commonLogicDataMapper.delete(Wrappers.<CommonLogicData>lambdaQuery()
-            .eq(CommonLogicData::getId, id)
-            .eq(CommonLogicData::getTestInt, 2)));
-        this.delete(id);
-    }
-
-    protected abstract void delete(long id);
-
-    @Test
-    void a06_deleteBatchIds() {
-        List<Long> ids = Arrays.asList(3L, 4L);
-        assertEquals(ids.size(), commonDataMapper.deleteBatchIds(ids));
-        assertEquals(ids.size(), commonLogicDataMapper.deleteBatchIds(ids));
-        this.deleteBatchIds(ids);
-    }
-
-    protected abstract void deleteBatchIds(List<Long> ids);
-
-    //    @Test
-//    void b5_deleteByIdWithFill() {
-//        long id = 5L;
-//        // 真删
-//        Assertions.assertEquals(1, commonDataMapper.deleteByIdWithFill(new CommonData().setId(id)));
-//        // 逻辑删除带填充
-//        Assertions.assertEquals(1, commonLogicDataMapper.deleteByIdWithFill(new CommonLogicData().setId(id)));
-//        // 真删
-//        Assertions.assertEquals(1, mysqlMapper.deleteByIdWithFill(new MysqlData().setId(id)));
-//    }
-
-    @Test
-    void a07_updateById() {
-        long id = 6L;
-        assertEquals(success, commonDataMapper.updateById(new CommonData().setId(id).setTestInt(555).setVersion(0)
-            .setTestEnum(TestEnum.TWO)));
-        assertEquals(success, commonLogicDataMapper.updateById(new CommonLogicData().setId(id).setTestInt(555)));
-        assertEquals(success, resultMapEntityMapper.updateById(new ResultMapEntity().setId(id).setList(list).setMap(map)));
-        this.updateById(id);
-    }
-
-    protected abstract void updateById(long id);
-
-    @Test
-    void a08_updateWithEntity() {
-        long id = 8L;
-        assertEquals(success, commonDataMapper.update(new CommonData().setTestInt(888).setVersion(0),
-            Wrappers.<CommonData>lambdaUpdate().eq(CommonData::getId, id).eq(CommonData::getTestInt, 8)));
-        assertEquals(success, commonLogicDataMapper.update(new CommonLogicData().setTestInt(888),
-            Wrappers.<CommonLogicData>lambdaUpdate().eq(CommonLogicData::getId, id)
-                .eq(CommonLogicData::getTestInt, 8)));
-        this.updateWithEntity(id);
-    }
-
-    protected abstract void updateWithEntity(long id);
-
-    @Test
-    void a09_updateWithoutEntity() {
-        long id = 9L;
-        // todo
-        this.updateWithoutEntity(id);
-    }
-
-    protected abstract void updateWithoutEntity(long id);
-
-    @Test
-    void a10_selectById() {
-        long id = 6L;
-        assertNotNull(commonDataMapper.selectById(id).getTestEnum());
-        // todo
-        assertTrue(commonDataMapper.getById(id).isPresent());
-        assertThat(commonDataCopyMapper.selectById(id).isPresent()).isTrue();
-        assertNotNull(commonLogicDataMapper.selectById(id));
-        ResultMapEntity resultMapEntity = resultMapEntityMapper.selectById(id);
-        assertNotNull(resultMapEntity);
-        assertTrue(CollectionUtils.isNotEmpty(resultMapEntity.getMap()));
-        assertTrue(CollectionUtils.isNotEmpty(resultMapEntity.getMapp()));
-        assertTrue(CollectionUtils.isNotEmpty(resultMapEntity.getList()));
-        this.selectById(id);
-    }
-
-    protected abstract void selectById(long id);
-
-    @Test
-    void a11_selectBatchIds() {
-        List<Long> ids = Arrays.asList(7L, 8L);
-
-        List<CommonData> commonData = commonDataMapper.selectBatchIds(ids);
-        assertTrue(CollectionUtils.isNotEmpty(commonData));
-        assertEquals(ids.size(), commonData.size());
-
-        List<CommonLogicData> commonLogicData = commonLogicDataMapper.selectBatchIds(ids);
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicData));
-        assertEquals(ids.size(), commonLogicData.size());
-
-        List<ResultMapEntity> resultMapEntities = resultMapEntityMapper.selectBatchIds(ids);
-        assertTrue(CollectionUtils.isNotEmpty(resultMapEntities));
-        assertEquals(ids.size(), resultMapEntities.size());
-
-        this.selectBatchIds(ids);
-    }
-
-    protected abstract void selectBatchIds(List<Long> ids);
-
-    @Test
-    void a12_selectByMap() {
-        long id = 9L;
-        Map<String, Object> map = new HashMap<>();
-        map.put("id", id);
-        map.put("test_int", 9);
-        assertTrue(CollectionUtils.isNotEmpty(commonDataMapper.selectByMap(map)));
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectByMap(map)));
-        this.selectByMap(id);
-    }
-
-    protected abstract void selectByMap(long id);
-
-    @Test
-    void a13_selectOne() {
-        long id = 10L;
-        assertNotNull(commonDataMapper.selectOne(Wrappers.<CommonData>lambdaQuery()
-            .eq(CommonData::getId, id).eq(CommonData::getTestInt, 10)));
-        assertNotNull(commonLogicDataMapper.selectOne(Wrappers.<CommonLogicData>lambdaQuery()
-            .eq(CommonLogicData::getId, id).eq(CommonLogicData::getTestInt, 10)));
-        this.selectOne(id);
-    }
-
-    protected abstract void selectOne(long id);
-
-    @Test
-    void a14_selectList() {
-        long id = 10L;
-        List<CommonData> commonData = commonDataMapper.selectList(Wrappers.<CommonData>lambdaQuery()
-            .eq(CommonData::getTestInt, 10));
-        assertThat(commonData).isNotEmpty();
-        assertThat(commonData.get(0)).isNotNull();
-
-        List<CommonLogicData> commonLogicData = commonLogicDataMapper.selectList(Wrappers.<CommonLogicData>lambdaQuery()
-            .eq(CommonLogicData::getId, id).eq(CommonLogicData::getTestInt, 10));
-        assertThat(commonLogicData).isNotEmpty();
-        assertThat(commonLogicData.get(0)).isNotNull();
-
-        List<ResultMapEntity> resultMapEntities = resultMapEntityMapper.selectList(Wrappers.<ResultMapEntity>lambdaQuery()
-            .eq(ResultMapEntity::getId, id));
-        assertThat(resultMapEntities).isNotEmpty();
-        assertThat(resultMapEntities.get(0)).isNotNull();
-        assertThat(resultMapEntities.get(0).getList()).isNotEmpty();
-        assertThat(resultMapEntities.get(0).getMap()).isNotEmpty();
-        assertThat(resultMapEntities.get(0).getMapp()).isNotEmpty();
-
-        this.selectList(id);
-    }
-
-    protected abstract void selectList(long id);
-
-    @Test
-    void a15_selectMaps() {
-        List<Map<String, Object>> commonMaps = commonDataMapper.selectMaps(Wrappers.query());
-        assertThat(commonMaps).isNotEmpty();
-        assertThat(commonMaps.get(0)).isNotEmpty();
-
-        List<Map<String, Object>> commonLogicMaps = commonLogicDataMapper.selectMaps(Wrappers.query());
-        assertThat(commonLogicMaps).isNotEmpty();
-        assertThat(commonLogicMaps.get(0)).isNotEmpty();
-
-        List<Map<String, Object>> resultMapEntityMaps = resultMapEntityMapper.selectMaps(Wrappers.query());
-        assertThat(resultMapEntityMaps).isNotEmpty();
-        assertThat(resultMapEntityMaps.get(0)).isNotEmpty();
-
-        this.selectMaps();
-    }
-
-    protected abstract void selectMaps();
-
-    @Test
-    void a16_selectPage() {
-        Page<CommonData> page = new Page<>(1, 5);
-        page.addOrder(OrderItem.descs("c_time", "u_time"));
-        IPage<CommonData> dataPage = commonDataMapper.selectPage(page, null);
-        assertSame(dataPage, page);
-        assertNotEquals(0, dataPage.getRecords().size());
-        assertTrue(CollectionUtils.isNotEmpty(dataPage.getRecords()));
-        System.out.println(JSON.toJSONString(dataPage));
-        System.out.println(JSON.toJSON(dataPage.convert(CommonData::getId)));
-
-
-        Page<CommonLogicData> logicPage = new Page<>(1, 5);
-        IPage<CommonLogicData> logicDataPage = commonLogicDataMapper.selectPage(logicPage, null);
-        assertSame(logicDataPage, logicPage);
-        assertNotEquals(0, logicDataPage.getRecords().size());
-        assertTrue(CollectionUtils.isNotEmpty(logicDataPage.getRecords()));
-        System.out.println(JSON.toJSONString(logicDataPage));
-
-
-        Page<CommonData> commonDataPage = new Page<>(1, 5);
-        commonDataPage.addOrder(OrderItem.descs("c_time", "u_time"));
-        IPage<CommonData> commonDataDataPage = commonDataMapper.myPage(commonDataPage);
-        assertSame(commonDataDataPage, commonDataPage);
-        assertNotEquals(0, commonDataDataPage.getRecords().size());
-        assertTrue(CollectionUtils.isNotEmpty(commonDataDataPage.getRecords()));
-        System.out.println(JSON.toJSONString(commonDataDataPage));
-        System.out.println(JSON.toJSON(commonDataDataPage.convert(CommonData::getId)));
-
-
-        Page<ResultMapEntity> resultMapEntityPage = new Page<>(1, 5);
-        IPage<ResultMapEntity> resultMapEntityDataPage = resultMapEntityMapper.selectPage(resultMapEntityPage, null);
-        assertSame(resultMapEntityDataPage, resultMapEntityPage);
-        assertNotEquals(0, resultMapEntityDataPage.getRecords().size());
-        assertTrue(CollectionUtils.isNotEmpty(resultMapEntityDataPage.getRecords()));
-        System.out.println(JSON.toJSONString(resultMapEntityDataPage));
-
-        this.selectPage();
-    }
-
-    protected abstract void selectPage();
-
-    @Test
-    void a17_fatherAndChildren() {
-        long id = 6;
-        assertThat(commonDataMapper.getById(id).isPresent()).isTrue();
-        assertThat(commonDataChildrenMapper.getByIdChildren(id).isPresent()).isTrue();
-        assertNotNull(commonLogicDataMapper.selectById(id));
-        assertNotNull(commonLogicDataChildrenMapper.selectById(id));
-        commonLogicDataMapper.getByWrapper(Wrappers.lambdaQuery());
-        commonLogicDataChildrenMapper.getByWrapper(Wrappers.lambdaQuery());
-    }
-
-    @Test
-    void a18_groupByOrderBy() {
-        LambdaQueryWrapper<CommonData> wrapper = Wrappers.<CommonData>lambdaQuery().groupBy(true, CommonData::getCreateDatetime);
-        LambdaQueryWrapper<CommonData> wrapper2 = Wrappers.<CommonData>lambdaQuery().orderByAsc(CommonData::getCreateDatetime);
-        System.out.println(wrapper.getSqlSegment());
-        System.out.println(wrapper2.getSqlSegment());
-//        List<CommonData> commonData = commonDataMapper.selectList(wrapper);
-//        assertThat(commonData).isNotEmpty();
-    }
-}

+ 24 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/CacheTest.java

@@ -31,6 +31,30 @@ class CacheTest {
         IPage<CacheModel> cacheModelIPage3 = cacheMapper.selectPage(new Page<>(2, 3), new QueryWrapper<>());
         Assertions.assertEquals(cacheModelIPage1.getTotal(), cacheModelIPage3.getTotal());
         Assertions.assertEquals(cacheModelIPage3.getRecords().size(), 2);
+        IPage<CacheModel> cacheModelIPage4 = cacheMapper.selectPage(new Page<>(2, 3, false), new QueryWrapper<>());
+        Assertions.assertEquals(cacheModelIPage4.getTotal(), 0L);
+        Assertions.assertEquals(cacheModelIPage4.getRecords().size(), 2);
+        IPage<CacheModel> cacheModelIPage5 = cacheMapper.selectPage(new Page<>(2, 3, true), new QueryWrapper<>());
+        Assertions.assertEquals(cacheModelIPage5.getTotal(), cacheModelIPage3.getTotal());
+        Assertions.assertEquals(cacheModelIPage5.getRecords().size(), 2);
+        IPage<CacheModel> cacheModelIPage6 = cacheMapper.selectPage(new Page<>(1, 3, true), new QueryWrapper<CacheModel>().ge("id", 2L));
+        Assertions.assertEquals(cacheModelIPage6.getTotal(), 4);
+        Assertions.assertEquals(cacheModelIPage6.getRecords().size(), 3);
+        IPage<CacheModel> cacheModelIPage7 = cacheMapper.selectPage(new Page<>(1, 3, false), new QueryWrapper<CacheModel>().ge("id", 2L));
+        Assertions.assertEquals(cacheModelIPage7.getTotal(), 0L);
+        Assertions.assertEquals(cacheModelIPage7.getRecords().size(), 3);
+        IPage<CacheModel> cacheModelIPage8 = cacheMapper.selectPage(new Page<>(1, 3, false), new QueryWrapper<CacheModel>().ge("id", 3L));
+        Assertions.assertEquals(cacheModelIPage8.getTotal(), 0L);
+        Assertions.assertEquals(cacheModelIPage8.getRecords().size(), 3);
+        cacheModelIPage8 = cacheMapper.selectPage(new Page<>(1, 3, false), new QueryWrapper<CacheModel>().ge("id", 3L));
+        Assertions.assertEquals(cacheModelIPage8.getTotal(), 0L);
+        Assertions.assertEquals(cacheModelIPage8.getRecords().size(), 3);
+        IPage<CacheModel> cacheModelIPage9 = cacheMapper.selectPage(new Page<>(1, 3, true), new QueryWrapper<CacheModel>().ge("id", 3L));
+        Assertions.assertEquals(cacheModelIPage9.getTotal(), 3L);
+        Assertions.assertEquals(cacheModelIPage9.getRecords().size(), 3);
+        cacheModelIPage9 = cacheMapper.selectPage(new Page<>(1, 3, true), new QueryWrapper<CacheModel>().ge("id", 3L));
+        Assertions.assertEquals(cacheModelIPage9.getTotal(), 3L);
+        Assertions.assertEquals(cacheModelIPage9.getRecords().size(), 3);
     }
 
 }

+ 12 - 8
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2KeyGeneratorTest.java

@@ -1,13 +1,7 @@
 package com.baomidou.mybatisplus.test.h2;
 
-import com.baomidou.mybatisplus.test.h2.keygenerator.mapper.ExtendKeyGeneratorMapper;
-import com.baomidou.mybatisplus.test.h2.keygenerator.mapper.KeyGeneratorMapper;
-import com.baomidou.mybatisplus.test.h2.keygenerator.mapper.LongKeyGeneratorMapper;
-import com.baomidou.mybatisplus.test.h2.keygenerator.mapper.StringKeyGeneratorMapper;
-import com.baomidou.mybatisplus.test.h2.keygenerator.model.ExtendKeyGeneratorModel;
-import com.baomidou.mybatisplus.test.h2.keygenerator.model.KeyGeneratorModel;
-import com.baomidou.mybatisplus.test.h2.keygenerator.model.LongKeyGeneratorModel;
-import com.baomidou.mybatisplus.test.h2.keygenerator.model.StringKeyGeneratorModel;
+import com.baomidou.mybatisplus.test.h2.keygenerator.mapper.*;
+import com.baomidou.mybatisplus.test.h2.keygenerator.model.*;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.MethodOrderer;
 import org.junit.jupiter.api.Test;
@@ -34,6 +28,9 @@ class H2KeyGeneratorTest {
     @Autowired
     private ExtendKeyGeneratorMapper extendKeyGeneratorMapper;
 
+    @Autowired
+    private IntegerKeyGeneratorMapper integerKeyGeneratorMapper;
+
     @Test
     void test() {
         KeyGeneratorModel keyGeneratorModel = new KeyGeneratorModel();
@@ -59,6 +56,13 @@ class H2KeyGeneratorTest {
         extendKeyGeneratorMapper.insert(extendKeyGeneratorModel);
         Assertions.assertNotNull(extendKeyGeneratorModel.getUid());
         Assertions.assertEquals(extendKeyGeneratorModel.getUid(), 4L);
+
+        //这个受限数据库,如果返回是long的话,那就救不了.
+        IntegerKeyGeneratorModel integerKeyGeneratorModel = new IntegerKeyGeneratorModel();
+        integerKeyGeneratorModel.setName("我举起了K神");
+        integerKeyGeneratorMapper.insert(integerKeyGeneratorModel);
+        Assertions.assertNotNull(integerKeyGeneratorModel.getUid());
+        Assertions.assertEquals(integerKeyGeneratorModel.getUid(), 5);
     }
 
 }

+ 6 - 8
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/mapper/PgDataMapper.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/keygenerator/mapper/IntegerKeyGeneratorMapper.java

@@ -13,13 +13,11 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.postgres.mapper;
+package com.baomidou.mybatisplus.test.h2.keygenerator.mapper;
 
-import com.baomidou.mybatisplus.test.postgres.entity.PgData;
-import com.baomidou.mybatisplus.test.base.mapper.MyBaseMapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.test.h2.keygenerator.model.IntegerKeyGeneratorModel;
 
-/**
- * @author miemie
- * @since 2018-08-06
- */
-public interface PgDataMapper extends MyBaseMapper<PgData> {}
+public interface IntegerKeyGeneratorMapper extends BaseMapper<IntegerKeyGeneratorModel> {
+
+}

+ 11 - 23
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/CachePage.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/keygenerator/model/IntegerKeyGeneratorModel.java

@@ -13,34 +13,22 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.core.metadata;
+package com.baomidou.mybatisplus.test.h2.keygenerator.model;
 
-import lombok.AllArgsConstructor;
+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;
-import lombok.NoArgsConstructor;
 
-import java.io.Serializable;
-import java.util.List;
-
-/**
- * 缓存分页数据(二级缓存)
- *
- * @author nieqiuqiu
- * @since 3.2.1
- */
 @Data
-@NoArgsConstructor
-@AllArgsConstructor
-public final class CachePage<T> implements Serializable {
+@TableName(value = "key_generator_model")
+@KeySequence(value = "key_generator_model_seq")
+public class IntegerKeyGeneratorModel {
 
-    /**
-     * 记录数
-     */
-    private List<T> records;
+    @TableId(type = IdType.INPUT, value = "id")
+    private Integer uid;
 
-    /**
-     * 总数
-     */
-    private long total;
+    private String name;
 
 }

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/mapper/MyBaseMapper.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/MyBaseMapper.java

@@ -13,7 +13,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.mapper;
+package com.baomidou.mybatisplus.test.mysql;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;

+ 90 - 283
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/MysqlTestDataMapperTest.java

@@ -15,26 +15,38 @@
  */
 package com.baomidou.mybatisplus.test.mysql;
 
-import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.test.base.BaseDbTest;
-import com.baomidou.mybatisplus.test.base.entity.CommonLogicData;
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonData;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonLogicData;
 import com.baomidou.mybatisplus.test.mysql.entity.MysqlData;
+import com.baomidou.mybatisplus.test.mysql.entity.ResultMapEntity;
+import com.baomidou.mybatisplus.test.mysql.enums.TestEnum;
 import com.baomidou.mybatisplus.test.mysql.mapper.MysqlDataMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.children.CommonDataChildrenMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.children.CommonLogicDataChildrenMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.commons.CommonDataCopyMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.commons.CommonDataMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.commons.CommonLogicDataMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.commons.ResultMapEntityMapper;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.session.SqlSessionFactory;
+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.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.toMap;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
  * Mybatis Plus mysql Junit Test
@@ -42,296 +54,91 @@ import static org.junit.jupiter.api.Assertions.*;
  * @author hubin
  * @since 2018-06-05
  */
+@DirtiesContext
+@TestMethodOrder(MethodOrderer.Alphanumeric.class)
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(locations = {"classpath:mysql/spring-test-mysql.xml"})
-class MysqlTestDataMapperTest extends BaseDbTest {
+class MysqlTestDataMapperTest {
+
+    protected final List<String> list = Arrays.asList("1", "2", "3");
+    protected final Map<String, Object> map = list.parallelStream().collect(toMap(identity(), identity()));
+    private final int success = 1;
+    private final int fail = 0;
+    @Resource(name = "commonDataMapper")
+    protected CommonDataMapper commonDataMapper;
+    @Resource(name = "commonDataChildrenMapper")
+    protected CommonDataChildrenMapper commonDataChildrenMapper;
+    @Resource(name = "commonLogicDataMapper")
+    protected CommonLogicDataMapper commonLogicDataMapper;
+    @Resource(name = "commonLogicDataChildrenMapper")
+    protected CommonLogicDataChildrenMapper commonLogicDataChildrenMapper;
+    @Resource
+    protected CommonDataCopyMapper commonDataCopyMapper;
+    @Resource
+    protected ResultMapEntityMapper resultMapEntityMapper;
+    @Autowired
+    private SqlSessionFactory sqlSessionFactory;
 
     @Resource
     private MysqlDataMapper mysqlMapper;
 
-    @Override
-    protected void insertForeach(Long id, int index, String str) {
-        mysqlMapper.insert(new MysqlData().setOrder(index).setGroup(index).setId(id).setTestStr(str).setYaHoStr(str));
+    @Test
+    void a00() {
+        Configuration configuration = sqlSessionFactory.getConfiguration();
+        assertThat(configuration).isInstanceOf(MybatisConfiguration.class);
+        MappedStatement mappedStatement = configuration.getMappedStatement("com.baomidou.mybatisplus.test.mysql.mapper.MysqlDataMapper.getRandomOne");
+        assertThat(mappedStatement).isNotNull();
+    }
+
+    @Test
+    void a01_insertForeach() {
+        for (int i = 1; i < 20; i++) {
+            Long id = (long) i;
+            String str = String.format("第%s条数据", i);
+            commonDataMapper.insert(new CommonData().setTestInt(i).setTestStr(str).setId(id)
+                .setTestEnum(TestEnum.ONE));
+            commonLogicDataMapper.insert(new CommonLogicData().setTestInt(i).setTestStr(str).setId(id));
+            resultMapEntityMapper.insert(new ResultMapEntity().setId(id).setList(list).setMap(map).setMapp(map));
+            mysqlMapper.insert(new MysqlData().setOrder(i).setGroup(i).setId(id).setTestStr(str).setYaHoStr(str));
+        }
     }
 
-    @Override
-    protected void insertBatch(int size) {
+    @Test
+    void a02_insertBatch() {
+        int size = 9;
+        List<CommonData> commonDataList = new ArrayList<>();
+        List<CommonLogicData> commonLogicDataList = new ArrayList<>();
         List<MysqlData> mysqlDataList = new ArrayList<>();
         for (int i = 0; i < size; i++) {
             String str = i + "条";
+            commonDataList.add(new CommonData().setTestInt(i).setTestEnum(TestEnum.TWO).setTestStr(str));
+            commonLogicDataList.add(new CommonLogicData().setTestInt(i).setTestStr(str));
             mysqlDataList.add(new MysqlData().setOrder(i).setGroup(i).setTestStr(str).setYaHoStr(str));
         }
+        assertEquals(size, commonDataMapper.insertBatchSomeColumn(commonDataList));
+        assertEquals(size, commonLogicDataMapper.insertBatchSomeColumn(commonLogicDataList));
         assertEquals(size, mysqlMapper.insertBatchSomeColumn(mysqlDataList));
     }
 
-    @Override
-    protected void deleteById(long id) {
+    @Test
+    void a03_deleteById() {
+        long id = 1L;
+        assertEquals(success, commonDataMapper.deleteById(id));
+        assertEquals(success, commonLogicDataMapper.deleteById(id));
         assertEquals(success, mysqlMapper.deleteById(id));
     }
 
-    @Override
-    protected void deleteByMap_fail(long id) {
-        Map<String, Object> map = new HashMap<>();
-        map.put("id", id);
-        map.put("`order`", 5);
-        assertEquals(fail, mysqlMapper.deleteByMap(map));
-    }
-
-    @Override
-    protected void delete(long id) {
-        assertEquals(success, mysqlMapper.delete(Wrappers.<MysqlData>lambdaQuery()
-            .eq(MysqlData::getId, id)
-            .eq(MysqlData::getOrder, 2)));
-    }
-
-    @Override
-    protected void deleteBatchIds(List<Long> ids) {
-        assertEquals(ids.size(), mysqlMapper.deleteBatchIds(ids));
-    }
-
-    @Override
-    protected void updateById(long id) {
-        assertEquals(success, mysqlMapper.updateById(new MysqlData().setId(id).setOrder(555)));
-    }
-
-    @Override
-    protected void updateWithEntity(long id) {
-        assertEquals(success, mysqlMapper.update(new MysqlData().setOrder(888),
-            Wrappers.<MysqlData>lambdaUpdate().eq(MysqlData::getId, id)
-                .eq(MysqlData::getOrder, 8)));
-    }
-
-    @Override
-    protected void updateWithoutEntity(long id) {
-        //todo
-    }
-
-    @Override
-    protected void selectById(long id) {
-        assertNotNull(mysqlMapper.selectById(id));
-    }
-
-    @Override
-    protected void selectBatchIds(List<Long> ids) {
-        List<MysqlData> mysqlData = mysqlMapper.selectBatchIds(ids);
-        assertTrue(CollectionUtils.isNotEmpty(mysqlData));
-        assertEquals(ids.size(), mysqlData.size());
-    }
-
-    @Override
-    protected void selectByMap(long id) {
+    @Test
+    void a04_deleteByMap() {
+        long id = 2L;
         Map<String, Object> map = new HashMap<>();
         map.put("id", id);
-        map.put("`order`", 9);
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectByMap(map)));
-    }
-
-    @Override
-    protected void selectOne(long id) {
-        assertNotNull(mysqlMapper.selectOne(Wrappers.<MysqlData>lambdaQuery()
-            .eq(MysqlData::getId, id).eq(MysqlData::getOrder, 10)));
-    }
-
-    @Override
-    protected void selectList(long id) {
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.<MysqlData>lambdaQuery()
-            .eq(MysqlData::getId, id).eq(MysqlData::getOrder, 10))));
-    }
-
-    @Override
-    protected void selectMaps() {
-        List<Map<String, Object>> mysqlMaps = mysqlMapper.selectMaps(Wrappers.query());
-        assertThat(mysqlMaps).isNotEmpty();
-        assertThat(mysqlMaps.get(0)).isNotEmpty();
-
-        Page<Map<String, Object>> mapPage = mysqlMapper.getMaps(new Page(1, 5));
-        assertThat(mapPage).isNotNull();
-        assertThat(mapPage.getRecords()).isNotEmpty();
-        assertThat(mapPage.getRecords().get(0)).isNotEmpty();
-    }
-
-    //    @Test
-//    void b5_deleteByIdWithFill() {
-//        long id = 5L;
-//        // 真删
-//        Assertions.assertEquals(1, commonMapper.deleteByIdWithFill(new CommonData().setId(id)));
-//        // 逻辑删除带填充
-//        Assertions.assertEquals(1, commonLogicDataMapper.deleteByIdWithFill(new CommonLogicData().setId(id)));
-//        // 真删
-//        Assertions.assertEquals(1, mysqlMapper.deleteByIdWithFill(new MysqlData().setId(id)));
-//    }
-//
-//    @Test
-//    void c2_optimisticUpdateById() {
-//        long id = 7L;
-//        Assertions.assertEquals(1, commonMapper.updateById(new CommonData().setId(id).setTestInt(778)
-//            .setVersion(0)));
-//    }
-//
-//    @Test
-//    void d1_getAllNoTenant() {
-//        commonMapper.getAllNoTenant();
-//    }
-//
-    @Test
-    void b01_selectListForNoLogic() {
-        MysqlData data = new MysqlData().setOrder(1);
-        // 1. 只有 entity
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.query(data))));
-        // 2. 有 entity 也有 where 条件
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.lambdaQuery(data).eq(MysqlData::getGroup, 1))));
-        // 3. 有 entity 也有 where 条件 也有 last 条件
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.lambdaQuery(data).eq(MysqlData::getGroup, 1).last("limit 1"))));
-        // 4. 有 entity 也有 last 条件
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.query(data)
-            .last("limit 1"))));
-        // 5. 只有 order by 或者 last
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.<MysqlData>query()
-            .lambda().orderByDesc(MysqlData::getOrder).last("limit 1"))));
-        // 6. 什么都没有情况
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.emptyWrapper())));
-        // 7. 只有 where 条件
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.lambdaQuery(new MysqlData()).eq(MysqlData::getGroup, 1))));
-        // 8. 有 where 条件 也有 last 条件
-        assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(Wrappers.lambdaQuery(new MysqlData()).eq(MysqlData::getGroup, 1).last("limit 1"))));
-    }
-
-    @Test
-    void b02_selectListForLogic() {
-        // 1. 只有 entity
-        CommonLogicData data = new CommonLogicData().setTestInt(11);
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(Wrappers.query(data))));
-        // 2. 有 entity 也有 where 条件
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(Wrappers.lambdaQuery(data).eq(CommonLogicData::getId, 11))));
-        // 3. 有 entity 也有 where 条件 也有 last 条件
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(Wrappers.lambdaQuery(data).eq(CommonLogicData::getId, 11).last("limit 1"))));
-        // 4. 有 entity 也有 last 条件
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(Wrappers.query(data)
-            .last("limit 1"))));
-        // 5. 只有 order by 或者 last
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(Wrappers.<CommonLogicData>query()
-            .lambda().orderByAsc(CommonLogicData::getTestInt).last("limit 1"))));
-        // 6. 什么都没有情况
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(Wrappers.emptyWrapper())));
-        // 7. 只有 where 条件
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(Wrappers.lambdaQuery(new CommonLogicData()).eq(CommonLogicData::getId, 11))));
-        // 8. 有 where 条件 也有 last 条件
-        assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(Wrappers.lambdaQuery(new CommonLogicData()).eq(CommonLogicData::getId, 11).last("limit 1"))));
-    }
-
-    @Test
-    void b03_getRandomOne() {
-        Map<String, Object> randomOne = mysqlMapper.getRandomOne(null, null);
-        assertThat(randomOne).isNotEmpty();
-    }
-
-    @Override
-    protected void selectPage() {
-        Page<MysqlData> mysqlPage = new Page<>(1, 5);
-        IPage<MysqlData> mysqlDataPage = mysqlMapper.selectPage(mysqlPage, null);
-        assertSame(mysqlDataPage, mysqlPage);
-        assertNotEquals(0, mysqlDataPage.getRecords().size());
-        assertTrue(CollectionUtils.isNotEmpty(mysqlDataPage.getRecords()));
-        System.out.println(JSON.toJSONString(mysqlDataPage));
+        map.put("test_int", 5);
+        assertEquals(fail, commonDataMapper.deleteByMap(map));
+        assertEquals(fail, commonLogicDataMapper.deleteByMap(map));
+        Map<String, Object> map2 = new HashMap<>();
+        map2.put("id", id);
+        map2.put("`order`", 5);
+        assertEquals(fail, mysqlMapper.deleteByMap(map2));
     }
-//
-//    @Test
-//    void d8_testApply() {
-//        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonMapper.selectList(new QueryWrapper<CommonData>()
-//            .apply("test_int = 12"))));
-//        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonLogicDataMapper.selectList(new QueryWrapper<CommonLogicData>()
-//            .apply("test_int = 12"))));
-//        Assertions.assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(new QueryWrapper<MysqlData>()
-//            .apply("`order` = 12"))));
-//    }
-//
-//    @Test
-//    void d9_testSetSelect() {
-//        commonMapper.selectList(new QueryWrapper<>(new CommonData()).select(TableFieldInfo::isCharSequence));
-//        commonMapper.selectList(new QueryWrapper<>(new CommonData().setTestStr("")));
-//        commonMapper.selectList(new QueryWrapper<>(new CommonData().setTestStr("")).orderByAsc("test_int"));
-//        commonMapper.selectList(new QueryWrapper<>(new CommonData().setTestStr("").setTestInt(12)).orderByAsc("test_int"));
-//
-//        mysqlMapper.selectList(Wrappers.query(new MysqlData().setTestStr("")));
-//
-//        mysqlMapper.selectList(Wrappers.lambdaQuery(new MysqlData().setTestStr("")).orderByAsc(MysqlData::getGroup));
-//        mysqlMapper.selectList(Wrappers.lambdaQuery(new MysqlData().setTestStr("").setGroup(1)).orderByAsc(MysqlData::getGroup));
-//    }
-//
-//    @Test
-//    void d10_testDel1eq1Then() {
-//        // 有空对象,有 order by
-//        mysqlMapper.selectList(Wrappers.lambdaQuery(new MysqlData()).select(i -> true).orderByAsc(MysqlData::getId));
-//        commonMapper.selectList(Wrappers.lambdaQuery(new CommonData()).orderByAsc(CommonData::getCreateDatetime));
-//        commonLogicDataMapper.selectList(Wrappers.lambdaQuery(new CommonLogicData()).orderByAsc(CommonLogicData::getCreateDatetime));
-//        // 对象有值,有 order by
-//        mysqlMapper.selectList(Wrappers.lambdaQuery(new MysqlData().setOrder(12)).select(i -> true).orderByAsc(MysqlData::getId));
-//        commonMapper.selectList(Wrappers.lambdaQuery(new CommonData().setTestInt(12)).orderByAsc(CommonData::getCreateDatetime));
-//        commonLogicDataMapper.selectList(Wrappers.lambdaQuery(new CommonLogicData().setTestInt(12)).orderByAsc(CommonLogicData::getCreateDatetime));
-//    }
-//
-//    @Test
-//    void d11_testWrapperCustomSql() {
-//        // 1. 只有 order by 或者 last
-//        mysqlMapper.getAll(Wrappers.<MysqlData>lambdaQuery().orderByDesc(MysqlData::getOrder).last("limit 1"));
-//        // 2. 什么都没有情况
-//        mysqlMapper.getAll(Wrappers.emptyWrapper());
-//        // 3. 只有 where 条件
-//        mysqlMapper.getAll(Wrappers.lambdaQuery(new MysqlData()).eq(MysqlData::getGroup, 1));
-//        // 4. 有 where 条件 也有 last 条件
-//        mysqlMapper.getAll(Wrappers.lambdaQuery(new MysqlData()).eq(MysqlData::getGroup, 1).last("limit 1"));
-//    }
-//
-//    @Test
-//    void e_1testNest() {
-//        ArrayList<Object> list = new ArrayList<>();
-//        list.add(1);
-//        LambdaQueryWrapper<CommonData> wrapper = Wrappers.<CommonData>lambdaQuery()
-//            .isNotNull(CommonData::getId).and(i -> i.eq(CommonData::getId, 1)
-//                .or().in(CommonData::getTestInt, list));
-//        System.out.println(wrapper.getSqlSegment());
-//        System.out.println(wrapper.getSqlSegment());
-//        System.out.println(wrapper.getSqlSegment());
-//        System.out.println(wrapper.getSqlSegment());
-//        System.out.println(wrapper.getSqlSegment());
-//        commonMapper.selectList(wrapper);
-//    }
-//
-//    @Test
-//    void e_2testLambdaColumnCache() {
-//        mysqlMapper.selectList(Wrappers.<MysqlData>lambdaQuery().select(MysqlData::getId, MysqlData::getYaHoStr))
-//            .forEach(System.out::println);
-//    }
-//
-//    @Test
-//    void e_3testUpdateNotEntity() {
-//        mysqlMapper.update(null, Wrappers.<MysqlData>lambdaUpdate().set(MysqlData::getOrder, 1));
-//        commonLogicDataMapper.update(null, Wrappers.<CommonLogicData>lambdaUpdate().set(CommonLogicData::getTestInt, 1));
-//    }
-//
-//    @Test
-//    void e_4testChainQuery() {
-//        new LambdaQueryChainWrapper<>(mysqlMapper).select(MysqlData::getId, MysqlData::getYaHoStr)
-//            .list().forEach(System.out::println);
-//
-//        new LambdaQueryChainWrapper<>(mysqlMapper).select(MysqlData::getId, MysqlData::getYaHoStr)
-//            .eq(MysqlData::getId, 19).one();
-//
-//        new LambdaQueryChainWrapper<>(mysqlMapper).count();
-//
-//        new LambdaQueryChainWrapper<>(mysqlMapper).select(MysqlData::getId, MysqlData::getYaHoStr)
-//            .page(new Page<>(1, 2));
-//    }
-//
-//    @Test
-//    void e_5testChainUpdate() {
-//        new LambdaUpdateChainWrapper<>(mysqlMapper).set(MysqlData::getYaHoStr, "123456").update();
-//
-//        new LambdaUpdateChainWrapper<>(mysqlMapper).eq(MysqlData::getYaHoStr, "111").remove();
-//    }
-//
-//    @Test
-//    void e_6getByWrapper() {
-//        commonMapper.getByWrapper(Wrappers.<CommonData>lambdaQuery().isNotNull(CommonData::getId));
-//        commonLogicDataMapper.getByWrapper(Wrappers.<CommonLogicData>lambdaQuery().isNotNull(CommonLogicData::getId));
-//    }
 }

+ 4 - 4
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/SelectCountDistinctTest.java

@@ -19,10 +19,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.test.base.entity.CommonData;
-import com.baomidou.mybatisplus.test.base.entity.CommonLogicData;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonDataMapper;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonLogicDataMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonData;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonLogicData;
+import com.baomidou.mybatisplus.test.mysql.mapper.commons.CommonDataMapper;
+import com.baomidou.mybatisplus.test.mysql.mapper.commons.CommonLogicDataMapper;
 import org.junit.jupiter.api.*;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.test.annotation.DirtiesContext;

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

@@ -51,7 +51,7 @@ import java.util.List;
  * @since 2017/4/1
  */
 @Configuration
-@MapperScan({"com.baomidou.mybatisplus.test.base.mapper.children", "com.baomidou.mybatisplus.test.base.mapper.commons", "com.baomidou.mybatisplus.test.mysql.mapper"})
+@MapperScan("com.baomidou.mybatisplus.test.mysql.mapper")
 public class MybatisPlusConfig {
 
     @Bean("mybatisSqlSession")
@@ -61,7 +61,7 @@ public class MybatisPlusConfig {
         /* 数据源 */
         sqlSessionFactory.setDataSource(dataSource);
         /* 枚举扫描 */
-        sqlSessionFactory.setTypeEnumsPackage("com.baomidou.mybatisplus.test.base.enums");
+        sqlSessionFactory.setTypeEnumsPackage("com.baomidou.mybatisplus.test.mysql.enums");
         /* xml扫描 */
         sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
             .getResources("classpath:/mapper/*.xml"));

+ 2 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/entity/CommonData.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/CommonData.java

@@ -13,13 +13,13 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.entity;
+package com.baomidou.mybatisplus.test.mysql.entity;
 
 import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.Version;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
-import com.baomidou.mybatisplus.test.base.enums.TestEnum;
+import com.baomidou.mybatisplus.test.mysql.enums.TestEnum;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/entity/CommonLogicData.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/CommonLogicData.java

@@ -13,7 +13,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.entity;
+package com.baomidou.mybatisplus.test.mysql.entity;
 
 import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;

+ 39 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/FillTenantEnumVersion.java

@@ -0,0 +1,39 @@
+package com.baomidou.mybatisplus.test.mysql.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.test.mysql.enums.TestEnum;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author miemie
+ * @since 2019-11-22
+ */
+@Data
+@Accessors(chain = true)
+@TableName("ftev")
+public class FillTenantEnumVersion {
+
+    private Long id;
+    private Integer tInt;
+    @TableField //无意义
+    private String tStr;
+    @TableField(value = "c_time", fill = FieldFill.INSERT)
+    private LocalDateTime createTime;
+    @TableField(value = "u_time", fill = FieldFill.UPDATE)
+    private LocalDateTime updTime;
+    private TestEnum testEnum;
+
+    @Version
+    private Integer version;
+//    /**
+//     * 多租户
+//     * 不用配置实体字段,但是数据库需要该字段
+//     */
+//    private Long tenantId;
+}

+ 4 - 4
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/entity/ResultMapEntity.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/entity/ResultMapEntity.java

@@ -13,13 +13,13 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.entity;
+package com.baomidou.mybatisplus.test.mysql.entity;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.test.base.type.JsonTypeHandler;
-import com.baomidou.mybatisplus.test.base.type.ListTypeHandler;
-import com.baomidou.mybatisplus.test.base.type.MapTypeHandler;
+import com.baomidou.mybatisplus.test.mysql.type.JsonTypeHandler;
+import com.baomidou.mybatisplus.test.mysql.type.ListTypeHandler;
+import com.baomidou.mybatisplus.test.mysql.type.MapTypeHandler;
 import lombok.Data;
 import lombok.experimental.Accessors;
 

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/enums/TestEnum.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/enums/TestEnum.java

@@ -13,7 +13,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.enums;
+package com.baomidou.mybatisplus.test.mysql.enums;
 
 import com.baomidou.mybatisplus.core.enums.IEnum;
 import lombok.Getter;

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/MysqlDataMapper.java

@@ -18,7 +18,7 @@ package com.baomidou.mybatisplus.test.mysql.mapper;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.test.base.mapper.MyBaseMapper;
+import com.baomidou.mybatisplus.test.mysql.MyBaseMapper;
 import com.baomidou.mybatisplus.test.mysql.entity.MysqlData;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/mapper/children/CommonDataChildrenMapper.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/children/CommonDataChildrenMapper.java

@@ -13,10 +13,10 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.mapper.children;
+package com.baomidou.mybatisplus.test.mysql.mapper.children;
 
-import com.baomidou.mybatisplus.test.base.entity.CommonData;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonDataMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonData;
+import com.baomidou.mybatisplus.test.mysql.mapper.commons.CommonDataMapper;
 import org.apache.ibatis.annotations.Select;
 
 import java.util.Optional;

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/mapper/children/CommonLogicDataChildrenMapper.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/children/CommonLogicDataChildrenMapper.java

@@ -13,12 +13,12 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.mapper.children;
+package com.baomidou.mybatisplus.test.mysql.mapper.children;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
-import com.baomidou.mybatisplus.test.base.entity.CommonLogicData;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonLogicDataMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonLogicData;
+import com.baomidou.mybatisplus.test.mysql.mapper.commons.CommonLogicDataMapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 

+ 2 - 2
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/mapper/commons/CommonDataCopyMapper.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/commons/CommonDataCopyMapper.java

@@ -13,9 +13,9 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.mapper.commons;
+package com.baomidou.mybatisplus.test.mysql.mapper.commons;
 
-import com.baomidou.mybatisplus.test.base.entity.CommonData;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonData;
 import org.apache.ibatis.annotations.Select;
 
 import java.util.Optional;

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/mapper/commons/CommonDataMapper.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/commons/CommonDataMapper.java

@@ -13,14 +13,14 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.mapper.commons;
+package com.baomidou.mybatisplus.test.mysql.mapper.commons;
 
 import com.baomidou.mybatisplus.annotation.SqlParser;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.test.base.entity.CommonData;
-import com.baomidou.mybatisplus.test.base.mapper.MyBaseMapper;
+import com.baomidou.mybatisplus.test.mysql.MyBaseMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonData;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/mapper/commons/CommonLogicDataMapper.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/commons/CommonLogicDataMapper.java

@@ -13,12 +13,12 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.mapper.commons;
+package com.baomidou.mybatisplus.test.mysql.mapper.commons;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
-import com.baomidou.mybatisplus.test.base.entity.CommonLogicData;
-import com.baomidou.mybatisplus.test.base.mapper.MyBaseMapper;
+import com.baomidou.mybatisplus.test.mysql.MyBaseMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.CommonLogicData;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 

+ 3 - 3
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/mapper/commons/ResultMapEntityMapper.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/mapper/commons/ResultMapEntityMapper.java

@@ -13,13 +13,13 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.mapper.commons;
+package com.baomidou.mybatisplus.test.mysql.mapper.commons;
 
 import com.baomidou.mybatisplus.annotation.SqlParser;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
-import com.baomidou.mybatisplus.test.base.entity.ResultMapEntity;
-import com.baomidou.mybatisplus.test.base.mapper.MyBaseMapper;
+import com.baomidou.mybatisplus.test.mysql.MyBaseMapper;
+import com.baomidou.mybatisplus.test.mysql.entity.ResultMapEntity;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.ResultMap;
 import org.apache.ibatis.annotations.Select;

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/type/JsonTypeHandler.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/type/JsonTypeHandler.java

@@ -13,7 +13,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.type;
+package com.baomidou.mybatisplus.test.mysql.type;
 
 import com.alibaba.fastjson.JSON;
 import org.apache.ibatis.type.BaseTypeHandler;

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/type/ListTypeHandler.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/type/ListTypeHandler.java

@@ -13,7 +13,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.type;
+package com.baomidou.mybatisplus.test.mysql.type;
 
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.fasterxml.jackson.core.JsonProcessingException;

+ 1 - 1
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/base/type/MapTypeHandler.java → mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/type/MapTypeHandler.java

@@ -13,7 +13,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.baomidou.mybatisplus.test.base.type;
+package com.baomidou.mybatisplus.test.mysql.type;
 
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.fasterxml.jackson.core.JsonProcessingException;

+ 0 - 60
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/PostgresMetaObjectHandler.java

@@ -1,60 +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.postgres;
-
-import java.time.LocalDateTime;
-
-import org.apache.ibatis.reflection.MetaObject;
-
-import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
-
-/**
- * 测试,自定义元对象字段填充控制器,实现公共字段自动写入
- *
- * @author hubin
- * @since 2017-06-25
- */
-public class PostgresMetaObjectHandler implements MetaObjectHandler {
-
-    /**
-     * 测试 user 表 name 字段为空自动填充
-     */
-    @Override
-    public void insertFill(MetaObject metaObject) {
-        System.out.println("*************************");
-        System.out.println("insert of postgres fill");
-        System.out.println("*************************");
-        // 测试下划线
-        Object createDatetime = this.getFieldValByName("createDatetime", metaObject);
-        System.out.println("createDatetime=" + createDatetime);
-        if (createDatetime == null) {
-            //测试实体没有的字段,配置在公共填充,不应该set到实体里面
-            this.setInsertFieldValByName("createDatetime1", LocalDateTime.now(), metaObject)
-                .setInsertFieldValByName("createDatetime", LocalDateTime.now(), metaObject);
-        }
-    }
-
-    @Override
-    public void updateFill(MetaObject metaObject) {
-        System.out.println("*************************");
-        System.out.println("update of postgres fill");
-        System.out.println("*************************");
-        //测试实体没有的字段,配置在公共填充,不应该set到实体里面
-        this.setUpdateFieldValByName("updateDatetime1", LocalDateTime.now(), metaObject)
-            .setUpdateFieldValByName("updateDatetime", LocalDateTime.now(), metaObject);
-    }
-}
-

+ 0 - 231
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/PostgresTestDataMapperTest.java

@@ -1,231 +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.postgres;
-
-import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.baomidou.mybatisplus.test.base.entity.CommonData;
-import com.baomidou.mybatisplus.test.base.entity.CommonLogicData;
-import com.baomidou.mybatisplus.test.postgres.entity.PgData;
-import com.baomidou.mybatisplus.test.base.enums.TestEnum;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonDataMapper;
-import com.baomidou.mybatisplus.test.base.mapper.commons.CommonLogicDataMapper;
-import com.baomidou.mybatisplus.test.postgres.mapper.PgDataMapper;
-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.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Mybatis Plus mysql Junit Test
- *
- * @author hubin
- * @since 2018-06-05
- */
-@TestMethodOrder(MethodOrderer.Alphanumeric.class)
-@ExtendWith(SpringExtension.class)
-@ContextConfiguration(locations = {"classpath:postgres/spring-test-postgres.xml"})
-class PostgresTestDataMapperTest {
-
-    @Resource
-    private CommonDataMapper commonMapper;
-    @Resource
-    private CommonLogicDataMapper commonLogicMapper;
-    @Resource
-    private PgDataMapper pgMapper;
-
-    @Test
-    void a_insertForeach() {
-        for (int i = 1; i < 20; i++) {
-            Long id = (long) i;
-            commonMapper.insert(new CommonData().setTestInt(i).setTestStr(String.format("第%s条数据", i)).setId(id)
-                .setTestEnum(TestEnum.ONE));
-            commonLogicMapper.insert(new CommonLogicData().setTestInt(i).setTestStr(String.format("第%s条数据", i)).setId(id));
-            pgMapper.insert(new PgData().setGroup(i).setId(id).setPgInt(i).setPgInt2(i));
-        }
-    }
-
-    @Test
-    void b1_deleteById() {
-        Assertions.assertEquals(1, commonMapper.deleteById(1L));
-        Assertions.assertEquals(1, commonLogicMapper.deleteById(1L));
-        Assertions.assertEquals(1, pgMapper.deleteById(1L));
-    }
-
-    @Test
-    void b2_deleteByMap() {
-        Map<String, Object> map = new HashMap<>();
-        map.put("id", 2L);
-        map.put("test_int", 5);
-        Assertions.assertEquals(0, commonMapper.deleteByMap(map));
-        Assertions.assertEquals(0, commonLogicMapper.deleteByMap(map));
-        Map<String, Object> map2 = new HashMap<>();
-        map2.put("id", 2L);
-        map2.put("\"group\"", 5);
-        map2.put("\"pgInt\"", 5);
-        Assertions.assertEquals(0, pgMapper.deleteByMap(map2));
-    }
-
-    @Test
-    void b3_delete() {
-        Assertions.assertEquals(1, commonMapper.delete(new QueryWrapper<CommonData>().lambda()
-            .eq(CommonData::getId, 2L)
-            .eq(CommonData::getTestInt, 2)));
-        Assertions.assertEquals(1, commonLogicMapper.delete(new QueryWrapper<CommonLogicData>().lambda()
-            .eq(CommonLogicData::getId, 2L)
-            .eq(CommonLogicData::getTestInt, 2)));
-        Assertions.assertEquals(1, pgMapper.delete(new QueryWrapper<PgData>().lambda()
-            .eq(PgData::getId, 2L)
-            .eq(PgData::getGroup, 2).eq(PgData::getPgInt, 2)));
-    }
-
-    @Test
-    void b4_deleteBatchIds() {
-        List<Long> ids = Arrays.asList(3L, 4L);
-        Assertions.assertEquals(2, commonMapper.deleteBatchIds(ids));
-        Assertions.assertEquals(2, commonLogicMapper.deleteBatchIds(ids));
-        Assertions.assertEquals(2, pgMapper.deleteBatchIds(ids));
-    }
-
-    @Test
-    void c1_updateById() {
-        Assertions.assertEquals(1, commonMapper.updateById(new CommonData().setId(5L).setTestInt(555)));
-        Assertions.assertEquals(1, commonLogicMapper.updateById(new CommonLogicData().setId(5L).setTestInt(555)));
-        Assertions.assertEquals(1, pgMapper.updateById(new PgData().setId(5L).setGroup(555).setPgInt(555)));
-    }
-
-    @Test
-    void c2_optimisticUpdateById() {
-        Assertions.assertEquals(1, commonMapper.updateById(new CommonData().setId(5L).setTestInt(556)
-            .setVersion(0)));
-    }
-
-    @Test
-    void c3_update() {
-        Assertions.assertEquals(1, commonMapper.update(
-            new CommonData().setTestInt(666),
-            new UpdateWrapper<CommonData>().lambda().eq(CommonData::getId, 6L)
-                .eq(CommonData::getTestInt, 6)));
-        Assertions.assertEquals(1, commonLogicMapper.update(
-            new CommonLogicData().setTestInt(666),
-            new UpdateWrapper<CommonLogicData>().lambda().eq(CommonLogicData::getId, 6L)
-                .eq(CommonLogicData::getTestInt, 6)));
-        Assertions.assertEquals(1, pgMapper.update(
-            new PgData().setGroup(666).setPgInt(555),
-            new UpdateWrapper<PgData>().lambda().eq(PgData::getId, 6L)
-                .eq(PgData::getGroup, 6).eq(PgData::getPgInt, 6)));
-    }
-
-    @Test
-    void d1_getAllNoTenant() {
-        commonMapper.getAllNoTenant();
-    }
-
-    @Test
-    void d2_selectById() {
-        long id = 6L;
-        Assertions.assertNotNull(commonMapper.selectById(id).getTestEnum());
-        Assertions.assertNotNull(commonLogicMapper.selectById(id));
-        Assertions.assertNotNull(pgMapper.selectById(id));
-    }
-
-    @Test
-    void d3_selectBatchIds() {
-        List<Long> ids = Arrays.asList(7L, 8L);
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonMapper.selectBatchIds(ids)));
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonLogicMapper.selectBatchIds(ids)));
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(pgMapper.selectBatchIds(ids)));
-    }
-
-    @Test
-    void d4_selectByMap() {
-        Map<String, Object> map = new HashMap<>();
-        map.put("id", 9L);
-        map.put("test_int", 9);
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonMapper.selectByMap(map)));
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonLogicMapper.selectByMap(map)));
-        Map<String, Object> map2 = new HashMap<>();
-        map2.put("id", 9L);
-        map2.put("\"group\"", 9);
-        map2.put("\"pgInt\"", 9);
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(pgMapper.selectByMap(map2)));
-    }
-
-    @Test
-    void d5_selectOne() {
-        Assertions.assertNotNull(commonMapper.selectOne(new QueryWrapper<CommonData>().lambda()
-            .eq(CommonData::getId, 10L).eq(CommonData::getTestInt, 10)));
-        Assertions.assertNotNull(commonLogicMapper.selectOne(new QueryWrapper<CommonLogicData>().lambda()
-            .eq(CommonLogicData::getId, 10L).eq(CommonLogicData::getTestInt, 10)));
-        Assertions.assertNotNull(pgMapper.selectOne(new QueryWrapper<PgData>().lambda()
-            .eq(PgData::getId, 10L).eq(PgData::getGroup, 10).eq(PgData::getPgInt, 10)));
-    }
-
-    @Test
-    void d6_selectList() {
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonMapper.selectList(new QueryWrapper<CommonData>()
-            .lambda().eq(CommonData::getTestInt, 10))));
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonLogicMapper.selectList(new QueryWrapper<CommonLogicData>()
-            .lambda().eq(CommonLogicData::getId, 10L).eq(CommonLogicData::getTestInt, 10))));
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(pgMapper.selectList(new QueryWrapper<PgData>()
-            .lambda().eq(PgData::getId, 10L).eq(PgData::getGroup, 10).eq(PgData::getPgInt, 10))));
-    }
-
-    @Test
-    void d7_selectPage() {
-        IPage<CommonData> page = new Page<>(1, 5);
-        IPage<CommonData> dataPage = commonMapper.selectPage(page, null);
-        Assertions.assertSame(dataPage, page);
-        Assertions.assertNotEquals(0, dataPage.getRecords().size());
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(dataPage.getRecords()));
-        System.out.println(JSON.toJSONString(dataPage));
-
-        IPage<CommonLogicData> logicPage = new Page<>(1, 5);
-        IPage<CommonLogicData> logicDataPage = commonLogicMapper.selectPage(logicPage, null);
-        Assertions.assertSame(logicDataPage, logicPage);
-        Assertions.assertNotEquals(0, logicDataPage.getRecords().size());
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(logicDataPage.getRecords()));
-        System.out.println(JSON.toJSONString(logicDataPage));
-
-        IPage<PgData> pgPage = new Page<>(1, 5);
-        page.setSize(5).setCurrent(1);
-        IPage<PgData> pgDataPage = pgMapper.selectPage(pgPage, null);
-        Assertions.assertSame(pgDataPage, pgPage);
-        Assertions.assertNotEquals(0, pgDataPage.getRecords().size());
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(pgDataPage.getRecords()));
-        System.out.println(JSON.toJSONString(pgDataPage));
-    }
-
-    @Test
-    void d8_testApply() {
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonMapper.selectList(new QueryWrapper<CommonData>()
-            .apply("test_int = 12"))));
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(commonLogicMapper.selectList(new QueryWrapper<CommonLogicData>()
-            .apply("test_int = 12"))));
-        Assertions.assertTrue(CollectionUtils.isNotEmpty(pgMapper.selectList(new QueryWrapper<PgData>()
-            .apply("\"group\" = 12").apply("\"pgInt\" = 12"))));
-    }
-}

+ 0 - 72
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/config/DBConfig.java

@@ -1,72 +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.postgres.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-import org.springframework.jdbc.datasource.SimpleDriverDataSource;
-import org.springframework.jdbc.datasource.init.DataSourceInitializer;
-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;
-
-/**
- * @author miemie
- * @since 2018/6/7
- */
-@Configuration
-@EnableTransactionManagement
-public class DBConfig {
-
-    @Bean("dataSource")
-    public DataSource dataSource() {
-        SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
-        dataSource.setDriverClass(org.postgresql.Driver.class);
-        dataSource.setUrl("jdbc:postgresql://localhost:5432/mybatis_plus");
-        dataSource.setUsername("postgres");
-        dataSource.setPassword("123123");
-        return dataSource;
-    }
-
-    @Bean
-    public DataSourceTransactionManager transactionManager(DataSource ds) {
-        return new DataSourceTransactionManager(ds);
-    }
-
-    @Bean
-    public DataSourceInitializer dataSourceInitializer(DataSource dataSource) throws IOException {
-        final DataSourceInitializer initializer = new DataSourceInitializer();
-        initializer.setDataSource(dataSource);
-        initializer.setDatabasePopulator(databasePopulator());
-        initializer.setEnabled(true);
-        return initializer;
-    }
-
-    private DatabasePopulator databasePopulator() throws IOException {
-        ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
-        resourceDatabasePopulator.setContinueOnError(false);
-        resourceDatabasePopulator.addScripts(
-            new PathMatchingResourcePatternResolver().getResources("classpath:/postgres/*.sql")
-        );
-        return resourceDatabasePopulator;
-    }
-}

+ 0 - 111
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/config/MybatisPlusConfig.java

@@ -1,111 +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.postgres.config;
-
-import com.baomidou.mybatisplus.core.MybatisConfiguration;
-import com.baomidou.mybatisplus.core.config.GlobalConfig;
-import com.baomidou.mybatisplus.core.parser.ISqlParser;
-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.spring.MybatisSqlSessionFactoryBean;
-import com.baomidou.mybatisplus.test.postgres.PostgresMetaObjectHandler;
-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;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import javax.sql.DataSource;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Mybatis Plus Config
- *
- * @author Caratacus
- * @since 2017/4/1
- */
-@Configuration
-@MapperScan({"com.baomidou.mybatisplus.test.base.mapper.commons", "com.baomidou.mybatisplus.test.base.mapper.pg"})
-public class MybatisPlusConfig {
-
-    @Bean("mybatisSqlSession")
-    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig,
-                                               PaginationInterceptor paginationInterceptor) throws Exception {
-        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
-        /* 数据源 */
-        sqlSessionFactory.setDataSource(dataSource);
-        /* 枚举扫描 */
-        sqlSessionFactory.setTypeEnumsPackage("com.baomidou.mybatisplus.test.base.enums");
-        /* entity扫描,mybatis的Alias功能 */
-        MybatisConfiguration configuration = new MybatisConfiguration();
-        configuration.setJdbcTypeForNull(JdbcType.NULL);
-        /* 驼峰转下划线 */
-        configuration.setMapUnderscoreToCamelCase(true);
-        /* 分页插件 */
-        configuration.addInterceptor(paginationInterceptor);
-        /* 乐观锁插件 */
-        configuration.addInterceptor(new OptimisticLockerInterceptor());
-        sqlSessionFactory.setConfiguration(configuration);
-        /* 自动填充插件 */
-        globalConfig.setMetaObjectHandler(new PostgresMetaObjectHandler());
-        sqlSessionFactory.setGlobalConfig(globalConfig);
-        return sqlSessionFactory.getObject();
-    }
-
-    @Bean
-    public GlobalConfig globalConfig() {
-        GlobalConfig conf = new GlobalConfig();
-        conf.setDbConfig(new GlobalConfig.DbConfig());
-        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 where) {
-                return new LongValue(1L);
-            }
-
-            @Override
-            public String getTenantIdColumn() {
-                return "tenant_id";
-            }
-
-            @Override
-            public boolean doTableFilter(String tableName) {
-                // 这里可以判断是否过滤表
-                return "common_logic_data".equals(tableName) || "pg_data".equals(tableName);
-            }
-        });
-        sqlParserList.add(tenantSqlParser);
-        paginationInterceptor.setSqlParserList(sqlParserList);
-        return paginationInterceptor;
-    }
-}

+ 0 - 36
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/postgres/entity/PgData.java

@@ -1,36 +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.postgres.entity;
-
-import com.baomidou.mybatisplus.annotation.TableField;
-import lombok.Data;
-import lombok.experimental.Accessors;
-
-/**
- * @author miemie
- * @since 2018-08-06
- */
-@Data
-@Accessors(chain = true)
-public class PgData {
-
-    private Long id;
-    @TableField("\"pgInt\"")
-    private Integer pgInt;
-    private Integer pgInt2;
-    @TableField("\"group\"")
-    private Integer group;
-}

+ 1 - 1
mybatis-plus/src/test/resources/logback.xml

@@ -7,7 +7,7 @@
         </encoder>
     </appender>
 
-    <logger name="com.baomidou.mybatisplus.test" level="warn" additivity="false">
+    <logger name="com.baomidou.mybatisplus.test" level="debug" additivity="false">
         <appender-ref ref="STDOUT"/>
     </logger>
 

+ 6 - 6
mybatis-plus/src/test/resources/mapper/ResultMapEntityMapper.xml

@@ -1,19 +1,19 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
-<mapper namespace="com.baomidou.mybatisplus.test.base.mapper.commons.ResultMapEntityMapper">
+<mapper namespace="com.baomidou.mybatisplus.test.mysql.mapper.commons.ResultMapEntityMapper">
 
-    <resultMap id="baseResult" type="com.baomidou.mybatisplus.test.base.entity.ResultMapEntity">
+    <resultMap id="baseResult" type="com.baomidou.mybatisplus.test.mysql.entity.ResultMapEntity">
         <id column="id" property="id"/>
         <result column="column1" property="column1"/>
         <result column="column2" property="column2"/>
         <result column="column3" property="column3"/>
     </resultMap>
 
-    <resultMap id="resultChildren1" type="com.baomidou.mybatisplus.test.base.entity.ResultMapEntity"
+    <resultMap id="resultChildren1" type="com.baomidou.mybatisplus.test.mysql.entity.ResultMapEntity"
                extends="baseResult">
         <result column="column4" property="column4"/>
-        <result column="list" property="list" typeHandler="com.baomidou.mybatisplus.test.base.type.ListTypeHandler"/>
-        <result column="map" property="map" typeHandler="com.baomidou.mybatisplus.test.base.type.MapTypeHandler"/>
-        <result column="map" property="mapp" typeHandler="com.baomidou.mybatisplus.test.base.type.JsonTypeHandler"/>
+        <result column="list" property="list" typeHandler="com.baomidou.mybatisplus.test.mysql.type.ListTypeHandler"/>
+        <result column="map" property="map" typeHandler="com.baomidou.mybatisplus.test.mysql.type.MapTypeHandler"/>
+        <result column="map" property="mapp" typeHandler="com.baomidou.mybatisplus.test.mysql.type.JsonTypeHandler"/>
     </resultMap>
 </mapper>

+ 0 - 9
mybatis-plus/src/test/resources/postgres/spring-test-postgres.xml

@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:context="http://www.springframework.org/schema/context"
-       xmlns="http://www.springframework.org/schema/beans"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
-
-    <context:component-scan base-package="com.baomidou.mybatisplus.test.postgres.config"/>
-</beans>

+ 0 - 30
mybatis-plus/src/test/resources/postgres/test_data.ddl.sql

@@ -1,30 +0,0 @@
-drop table if exists public.common_data;
-drop table if exists public.common_logic_data;
-drop table if exists public.pg_data;
-CREATE TABLE public.common_data (
-    id        BIGINT primary key,
-    test_int  integer,
-    test_str  varchar(50),
-    c_time    timestamp,
-    u_time    timestamp,
-    version   integer default 0,
-    test_enum integer,
-    tenant_id bigint
-);
-
-CREATE TABLE public.common_logic_data (
-    id       BIGINT primary key,
-    test_int integer,
-    test_str varchar(50),
-    c_time   timestamp,
-    u_time   timestamp,
-    deleted  smallint default 0,
-    version  integer  default 0
-);
-
-CREATE TABLE public.pg_data (
-    id      BIGINT primary key,
-    "pgInt" integer,
-    pg_int2 integer,
-    "group" integer
-);