Ver código fonte

优化初始化过程,添加逻辑删除注解次数检测

miemie 6 anos atrás
pai
commit
109322bcbf

+ 0 - 4
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableFieldInfo.java

@@ -184,10 +184,6 @@ public class TableFieldInfo {
      * @param field    字段属性对象
      */
     private boolean initLogicDelete(GlobalConfig.DbConfig dbConfig, Field field) {
-        if (null == dbConfig.getLogicDeleteValue()) {
-            // 未设置逻辑删除值不进行
-            return false;
-        }
         /* 获取注解属性,逻辑处理字段 */
         TableLogic tableLogic = field.getAnnotation(TableLogic.class);
         if (null != tableLogic) {

+ 0 - 21
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java

@@ -18,7 +18,6 @@ package com.baomidou.mybatisplus.core.metadata;
 import com.baomidou.mybatisplus.annotation.DbType;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.KeySequence;
-import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
@@ -83,7 +82,6 @@ public class TableInfo {
     /**
      * 表字段信息列表
      */
-    @Setter(AccessLevel.NONE)
     private List<TableFieldInfo> fieldList;
     /**
      * 命名空间
@@ -128,30 +126,11 @@ public class TableInfo {
         return currentNamespace + StringPool.DOT + sqlMethod;
     }
 
-    public void setFieldList(GlobalConfig globalConfig, List<TableFieldInfo> fieldList) {
-        this.fieldList = fieldList;
-        /*
-         * 启动逻辑删除注入、判断该表是否启动
-         */
-        if (null != globalConfig.getDbConfig().getLogicDeleteValue()) {
-            for (TableFieldInfo tfi : fieldList) {
-                if (tfi.isLogicDelete()) {
-                    this.setLogicDelete(true);
-                    break;
-                }
-            }
-        }
-    }
-
     public void setConfigMark(Configuration configuration) {
         Assert.notNull(configuration, "Error: You need Initialize MybatisConfiguration !");
         this.configMark = configuration.toString();
     }
 
-    public boolean isLogicDelete() {
-        return logicDelete;
-    }
-
     /**
      * 获取主键的 select sql 片段
      *

+ 5 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/TableInfoHelper.java

@@ -260,8 +260,12 @@ public class TableInfoHelper {
             fieldList.add(new TableFieldInfo(dbConfig, tableInfo, field));
         }
 
+        /* 检查逻辑删除字段只能有最多一个 */
+        Assert.isTrue(fieldList.stream().filter(TableFieldInfo::isLogicDelete).count() < 2L,
+            String.format("annotation of @TableLogic can't more than one in class : %s.", clazz.getName()));
+
         /* 字段列表 */
-        tableInfo.setFieldList(globalConfig, fieldList);
+        tableInfo.setFieldList(fieldList);
 
         /* 未发现主键注解,提示警告信息 */
         if (StringUtils.isEmpty(tableInfo.getKeyColumn())) {