瀏覽代碼

还原代码,开放执行器getCountCacheKey方法.

聂秋秋 5 年之前
父節點
當前提交
2f45af8551

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

@@ -175,7 +175,7 @@ public class MybatisCachingExecutor implements Executor {
             .build();
     }
 
-    private CacheKey getCountCacheKey(MappedStatement mappedStatement, BoundSql boundSql, Object parameterObject, RowBounds rowBounds) {
+    protected 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);

+ 14 - 4
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/LambdaUtils.java

@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda;
 import java.lang.ref.WeakReference;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 
 import static java.util.Locale.ENGLISH;
@@ -58,10 +59,13 @@ public final class LambdaUtils {
     public static <T> SerializedLambda resolve(SFunction<T, ?> func) {
         Class<?> clazz = func.getClass();
         String canonicalName = clazz.getCanonicalName();
-        return FUNC_CACHE.computeIfAbsent(canonicalName, (k) -> {
-            SerializedLambda lambda = SerializedLambda.resolve(func);
-            return new WeakReference<>(lambda);
-        }).get();
+        return Optional.ofNullable(FUNC_CACHE.get(canonicalName))
+            .map(WeakReference::get)
+            .orElseGet(() -> {
+                SerializedLambda lambda = SerializedLambda.resolve(func);
+                FUNC_CACHE.put(canonicalName, new WeakReference<>(lambda));
+                return lambda;
+            });
     }
 
     /**
@@ -119,5 +123,11 @@ public final class LambdaUtils {
             return info == null ? null : createColumnCacheMap(info);
         });
     }
+    
+    public static void main(String[] args) {
+        ConcurrentHashMap<String,String> map = new ConcurrentHashMap<>();
+        map.put("test","123456");
+        map.computeIfAbsent("123",(k)-> {return null;});
+    }
 
 }