Explorar el Código

Merge branch '3.0' of gitee.com:baomidou/mybatis-plus into 3.0

miemie hace 3 años
padre
commit
4fa6a8ebdb

+ 1 - 1
CHANGELOG.md

@@ -1,6 +1,6 @@
 # CHANGELOG
 
-## [v3.4.3.1] 2021.08.21
+## [v3.4.3.2] 2021.08.21
 
 - 增加 goldilocks 数据库 csiidb 数据库 的支持
 - 增加对南大通用GBase 8s数据库的支持(GBASEDBT),区别于原有定义(GBASE)

+ 4 - 27
mybatis-plus-boot-starter/src/main/java/com/baomidou/mybatisplus/autoconfigure/IdentifierGeneratorAutoConfiguration.java

@@ -15,7 +15,6 @@
  */
 package com.baomidou.mybatisplus.autoconfigure;
 
-import com.baomidou.mybatisplus.core.config.GlobalConfig;
 import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
 import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -34,32 +33,10 @@ import org.springframework.context.annotation.Lazy;
 @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
 public class IdentifierGeneratorAutoConfiguration {
 
-    @Configuration(proxyBeanMethods = false)
+    @Bean
     @ConditionalOnClass(InetUtils.class)
-    public static class InetUtilsAutoConfig {
-
-        private final InetUtils inetUtils;
-
-        private final MybatisPlusProperties properties;
-
-        public InetUtilsAutoConfig(InetUtils inetUtils, MybatisPlusProperties properties) {
-            this.inetUtils = inetUtils;
-            this.properties = properties;
-        }
-
-        @Bean
-        @ConditionalOnMissingBean
-        public IdentifierGenerator identifierGenerator() {
-            GlobalConfig globalConfig = properties.getGlobalConfig();
-            Long workerId = globalConfig.getWorkerId();
-            Long datacenterId = globalConfig.getDatacenterId();
-            if (workerId != null && datacenterId != null) {
-                return new DefaultIdentifierGenerator(workerId, datacenterId);
-            } else {
-                return new DefaultIdentifierGenerator(inetUtils.findFirstNonLoopbackAddress());
-            }
-        }
-
+    @ConditionalOnMissingBean
+    public IdentifierGenerator identifierGenerator(InetUtils inetUtils) {
+        return new DefaultIdentifierGenerator(inetUtils.findFirstNonLoopbackAddress());
     }
-
 }

+ 3 - 7
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisSqlSessionFactoryBuilder.java

@@ -81,18 +81,14 @@ public class MybatisSqlSessionFactoryBuilder extends SqlSessionFactoryBuilder {
     @Override
     public SqlSessionFactory build(Configuration configuration) {
         GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration);
+
         final IdentifierGenerator identifierGenerator;
-        if (globalConfig.getIdentifierGenerator() == null) {
-            if (null != globalConfig.getWorkerId() && null != globalConfig.getDatacenterId()) {
-                identifierGenerator = new DefaultIdentifierGenerator(globalConfig.getWorkerId(), globalConfig.getDatacenterId());
-            } else {
-                identifierGenerator = new DefaultIdentifierGenerator();
-            }
+        if (null == globalConfig.getIdentifierGenerator()) {
+            identifierGenerator = new DefaultIdentifierGenerator();
             globalConfig.setIdentifierGenerator(identifierGenerator);
         } else {
             identifierGenerator = globalConfig.getIdentifierGenerator();
         }
-        //TODO 这里只是为了兼容下,并没多大重要,方法标记过时了.
         IdWorker.setIdentifierGenerator(identifierGenerator);
 
         if (globalConfig.isEnableSqlRunner()) {

+ 0 - 17
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/config/GlobalConfig.java

@@ -43,27 +43,10 @@ import java.util.concurrent.ConcurrentSkipListSet;
 @Accessors(chain = true)
 @SuppressWarnings("serial")
 public class GlobalConfig implements Serializable {
-
     /**
      * 是否开启 LOGO
      */
     private boolean banner = true;
-    /**
-     * 机器 ID 部分
-     *
-     * @see #setIdentifierGenerator(IdentifierGenerator)
-     * @deprecated 3.3.0
-     */
-    @Deprecated
-    private Long workerId;
-    /**
-     * 数据标识 ID 部分
-     *
-     * @see #setIdentifierGenerator(IdentifierGenerator)
-     * @deprecated 3.3.0
-     */
-    @Deprecated
-    private Long datacenterId;
     /**
      * 是否初始化 SqlRunner
      */

+ 1 - 7
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/incrementer/DefaultIdentifierGenerator.java

@@ -27,16 +27,10 @@ import java.net.InetAddress;
  * @since 3.3.0
  */
 public class DefaultIdentifierGenerator implements IdentifierGenerator {
-
     private final Sequence sequence;
 
-    /**
-     * @see #DefaultIdentifierGenerator(InetAddress)
-     * @deprecated 3.4.3
-     */
-    @Deprecated
     public DefaultIdentifierGenerator() {
-        this.sequence = new Sequence();
+        this.sequence = new Sequence(null);
     }
 
     public DefaultIdentifierGenerator(InetAddress inetAddress) {

+ 8 - 5
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java

@@ -172,7 +172,6 @@ public class TableInfo implements Constants {
     /**
      * 排序列表
      */
-    @Getter
     @Setter
     private List<TableFieldInfo> orderByFields;
 
@@ -485,10 +484,7 @@ public class TableInfo implements Constants {
                 this.withUpdateFill = true;
             }
             if (i.isOrderBy()) {
-                if (null == this.orderByFields) {
-                    this.orderByFields = new LinkedList<>();
-                }
-                this.orderByFields.add(i);
+                this.getOrderByFields().add(i);
             }
             if (i.isVersion()) {
                 this.withVersion = true;
@@ -505,6 +501,13 @@ public class TableInfo implements Constants {
         return Collections.unmodifiableList(fieldList);
     }
 
+    public List<TableFieldInfo> getOrderByFields() {
+        if (null == this.orderByFields) {
+            this.orderByFields = new LinkedList<>();
+        }
+        return this.orderByFields;
+    }
+
     @Deprecated
     public boolean isLogicDelete() {
         return withLogicDelete;

+ 0 - 134
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/parser/AbstractJsqlParser.java

@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.core.parser;
-
-import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
-import net.sf.jsqlparser.JSQLParserException;
-import net.sf.jsqlparser.parser.CCJSqlParserUtil;
-import net.sf.jsqlparser.statement.Statement;
-import net.sf.jsqlparser.statement.Statements;
-import net.sf.jsqlparser.statement.delete.Delete;
-import net.sf.jsqlparser.statement.insert.Insert;
-import net.sf.jsqlparser.statement.select.Select;
-import net.sf.jsqlparser.statement.select.SelectBody;
-import net.sf.jsqlparser.statement.update.Update;
-import org.apache.ibatis.logging.Log;
-import org.apache.ibatis.logging.LogFactory;
-import org.apache.ibatis.reflection.MetaObject;
-
-/**
- * 抽象 SQL 解析类
- *
- * @author hubin
- * @since 2017-06-20
- */
-public abstract class AbstractJsqlParser implements ISqlParser {
-
-    /**
-     * 日志
-     */
-    protected final Log logger = LogFactory.getLog(this.getClass());
-
-    /**
-     * 解析 SQL 方法
-     *
-     * @param metaObject 元对象
-     * @param sql        SQL 语句
-     * @return SQL 信息
-     */
-
-    @Override
-    public SqlInfo parser(MetaObject metaObject, String sql) {
-        if (this.allowProcess(metaObject)) {
-            try {
-                if (logger.isDebugEnabled()) {
-                    logger.debug("Original SQL: " + sql);
-                }
-                // fixed github pull/295
-                StringBuilder sqlStringBuilder = new StringBuilder();
-                Statements statements = CCJSqlParserUtil.parseStatements(sql);
-                int i = 0;
-                for (Statement statement : statements.getStatements()) {
-                    if (null != statement) {
-                        if (i++ > 0) {
-                            sqlStringBuilder.append(';');
-                        }
-                        sqlStringBuilder.append(this.processParser(statement).getSql());
-                    }
-                }
-                if (sqlStringBuilder.length() > 0) {
-                    return SqlInfo.newInstance().setSql(sqlStringBuilder.toString());
-                }
-            } catch (JSQLParserException e) {
-                throw ExceptionUtils.mpe("Failed to process, please exclude the tableName or statementId.\n Error SQL: %s", e, sql);
-            }
-        }
-        return null;
-    }
-
-    /**
-     * 执行 SQL 解析
-     *
-     * @param statement JsqlParser Statement
-     * @return
-     */
-    public SqlInfo processParser(Statement statement) {
-        if (statement instanceof Insert) {
-            this.processInsert((Insert) statement);
-        } else if (statement instanceof Select) {
-            this.processSelectBody(((Select) statement).getSelectBody());
-        } else if (statement instanceof Update) {
-            this.processUpdate((Update) statement);
-        } else if (statement instanceof Delete) {
-            this.processDelete((Delete) statement);
-        }
-        if (logger.isDebugEnabled()) {
-            logger.debug("parser sql: " + statement.toString());
-        }
-        return SqlInfo.newInstance().setSql(statement.toString());
-    }
-
-    /**
-     * 新增
-     */
-    public abstract void processInsert(Insert insert);
-
-    /**
-     * 删除
-     */
-    public abstract void processDelete(Delete delete);
-
-    /**
-     * 更新
-     */
-    public abstract void processUpdate(Update update);
-
-    /**
-     * 查询
-     */
-    public abstract void processSelectBody(SelectBody selectBody);
-
-    /**
-     * 判断是否允许执行
-     * <p>例如:逻辑删除只解析 delete , update 操作</p>
-     *
-     * @param metaObject 元对象
-     * @return true
-     */
-    public boolean allowProcess(MetaObject metaObject) {
-        return true;
-    }
-}

+ 0 - 30
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/parser/ISqlParserFilter.java

@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.baomidou.mybatisplus.core.parser;
-
-import org.apache.ibatis.reflection.MetaObject;
-
-/**
- * SQL 解析过滤器
- *
- * @author hubin
- * @since 2017-09-02
- */
-public interface ISqlParserFilter {
-
-    boolean doFilter(MetaObject metaObject);
-
-}

+ 0 - 9
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/Sequence.java

@@ -76,15 +76,6 @@ public class Sequence {
      */
     private InetAddress inetAddress;
 
-    /**
-     * @deprecated 3.4.3
-     */
-    @Deprecated
-    public Sequence() {
-        this.datacenterId = getDatacenterId(maxDatacenterId);
-        this.workerId = getMaxWorkerId(datacenterId, maxWorkerId);
-    }
-
     public Sequence(InetAddress inetAddress) {
         this.inetAddress = inetAddress;
         this.datacenterId = getDatacenterId(maxDatacenterId);

+ 3 - 16
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/DynamicTableNameInnerInterceptor.java

@@ -36,7 +36,6 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 /**
  * 动态表名
@@ -50,13 +49,9 @@ import java.util.Map;
 @AllArgsConstructor
 @SuppressWarnings({"rawtypes"})
 public class DynamicTableNameInnerInterceptor implements InnerInterceptor {
-
     /**
-     * 该方法废弃,避免多表使用统一策略多次注入,切换使用 TableNameHandler 自行判断表面处理逻辑
-     * 该注入方法后续版本会移除
+     * 表名处理器,是否处理表名的情况都在该处理器中自行判断
      */
-    @Deprecated
-    private Map<String, TableNameHandler> tableNameHandlerMap;
     private TableNameHandler tableNameHandler;
 
     @Override
@@ -79,6 +74,7 @@ public class DynamicTableNameInnerInterceptor implements InnerInterceptor {
     }
 
     protected String changeTable(String sql) {
+        ExceptionUtils.throwMpe(null == tableNameHandler, "Please implement TableNameHandler processing logic");
         TableNameParser parser = new TableNameParser(sql);
         List<TableNameParser.SqlToken> names = new ArrayList<>();
         parser.accept(names::add);
@@ -88,16 +84,7 @@ public class DynamicTableNameInnerInterceptor implements InnerInterceptor {
             int start = name.getStart();
             if (start != last) {
                 builder.append(sql, last, start);
-                String value = name.getValue();
-                if (null == tableNameHandler) {
-                    tableNameHandler = tableNameHandlerMap.get(value);
-                }
-                ExceptionUtils.throwMpe(null == tableNameHandler,"Please implement TableNameHandler processing logic");
-                if (null != tableNameHandler) {
-                    builder.append(tableNameHandler.dynamicTableName(sql, value));
-                } else {
-                    builder.append(value);
-                }
+                builder.append(tableNameHandler.dynamicTableName(sql, name.getValue()));
             }
             last = name.getEnd();
         }