浏览代码

代码调整.

nieqiurong 5 月之前
父节点
当前提交
199417d7c8

+ 13 - 15
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/OptimisticLockerInnerInterceptor.java

@@ -31,12 +31,12 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import lombok.Setter;
 import org.apache.ibatis.executor.Executor;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.mapping.SqlCommandType;
 
 import java.lang.reflect.Field;
-import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.time.Instant;
 import java.time.LocalDateTime;
@@ -71,26 +71,30 @@ import java.util.regex.Pattern;
  */
 @SuppressWarnings({"unchecked"})
 public class OptimisticLockerInnerInterceptor implements InnerInterceptor {
-    private RuntimeException exception;
 
-    public void setException(RuntimeException exception) {
-        this.exception = exception;
-    }
+    /**
+     * 自定义异常处理
+     */
+    @Setter
+    private RuntimeException exception;
 
     /**
      * entity类缓存
      */
     private static final Map<String, Class<?>> ENTITY_CLASS_CACHE = new ConcurrentHashMap<>();
+
     /**
      * 变量占位符正则
      */
     private static final Pattern PARAM_PAIRS_RE = Pattern.compile("#\\{ew\\.paramNameValuePairs\\.(" + Constants.WRAPPER_PARAM + "\\d+)\\}");
+
     /**
      * paramNameValuePairs存放的version值的key
      */
     private static final String UPDATED_VERSION_VAL_KEY = "#updatedVersionVal#";
+
     /**
-     * Support wrapper mode
+     * Support wrapper mode (update(LambdaUpdateWrapper) or update(UpdateWrapper))
      */
     private final boolean wrapperMode;
 
@@ -103,7 +107,7 @@ public class OptimisticLockerInnerInterceptor implements InnerInterceptor {
     }
 
     @Override
-    public void beforeUpdate(Executor executor, MappedStatement ms, Object parameter) throws SQLException {
+    public void beforeUpdate(Executor executor, MappedStatement ms, Object parameter) {
         if (SqlCommandType.UPDATE != ms.getSqlCommandType()) {
             return;
         }
@@ -130,9 +134,6 @@ public class OptimisticLockerInnerInterceptor implements InnerInterceptor {
                 Object originalVersionVal = versionField.get(et);
                 if (originalVersionVal == null) {
                     if (null != exception) {
-                        /**
-                         * 自定义异常处理
-                         */
                         throw exception;
                     }
                     return;
@@ -157,10 +158,7 @@ public class OptimisticLockerInnerInterceptor implements InnerInterceptor {
             } catch (IllegalAccessException e) {
                 throw ExceptionUtils.mpe(e);
             }
-        }
-
-        // update(LambdaUpdateWrapper) or update(UpdateWrapper)
-        else if (wrapperMode && map.entrySet().stream().anyMatch(t -> Objects.equals(t.getKey(), Constants.WRAPPER))) {
+        } else if (wrapperMode && map.containsKey(Constants.WRAPPER)) {
             setVersionByWrapper(map, msId);
         }
     }
@@ -221,7 +219,7 @@ public class OptimisticLockerInnerInterceptor implements InnerInterceptor {
             INIT,
             FIELD_FOUND,
             EQ_FOUND,
-            VERSION_VALUE_PRESENT;
+            VERSION_VALUE_PRESENT
 
         }
 

+ 1 - 2
mybatis-plus-jsqlparser-support/mybatis-plus-jsqlparser/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/TenantLineInnerInterceptor.java

@@ -40,7 +40,6 @@ import org.apache.ibatis.session.ResultHandler;
 import org.apache.ibatis.session.RowBounds;
 
 import java.sql.Connection;
-import java.sql.SQLException;
 import java.util.List;
 import java.util.Properties;
 
@@ -59,7 +58,7 @@ public class TenantLineInnerInterceptor extends BaseMultiTableInnerInterceptor i
     private TenantLineHandler tenantLineHandler;
 
     @Override
-    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
+    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
         if (InterceptorIgnoreHelper.willIgnoreTenantLine(ms.getId())) {
             return;
         }