Skip to content

Commit 6533a70

Browse files
committed
Merge branch '3.0' into github3.0
2 parents 9a800a9 + bfa636a commit 6533a70

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parser/cache/AbstractCaffeineJsqlParseCache.java

+28-5
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,49 @@ public AbstractCaffeineJsqlParseCache(Consumer<Caffeine<Object, Object>> consume
5353

5454
@Override
5555
public void putStatement(String sql, Statement value) {
56-
put(sql, value);
56+
this.put(sql, value);
5757
}
5858

5959
@Override
6060
public void putStatements(String sql, Statements value) {
61-
put(sql, value);
61+
this.put(sql, value);
6262
}
6363

6464
@Override
6565
public Statement getStatement(String sql) {
66-
byte[] bytes = cache.getIfPresent(sql);
67-
return null == bytes ? null : (Statement) deserialize(sql, bytes);
66+
return this.get(sql);
6867
}
6968

7069
@Override
7170
public Statements getStatements(String sql) {
71+
return this.get(sql);
72+
}
73+
74+
/**
75+
* 获取解析对象,异常清空缓存逻辑
76+
*
77+
* @param sql 执行 SQL
78+
* @return 返回泛型对象
79+
*/
80+
protected <T> T get(String sql) {
7281
byte[] bytes = cache.getIfPresent(sql);
73-
return null == bytes ? null : (Statements) deserialize(sql, bytes);
82+
if (null != bytes) {
83+
try {
84+
return (T) deserialize(sql, bytes);
85+
} catch (Exception e) {
86+
cache.invalidate(sql);
87+
logger.error("deserialize error", e);
88+
}
89+
}
90+
return null;
7491
}
7592

93+
/**
94+
* 存储解析对象
95+
*
96+
* @param sql 执行 SQL
97+
* @param value 解析对象
98+
*/
7699
protected void put(String sql, Object value) {
77100
if (async) {
78101
if (executor != null) {

mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parser/cache/FstSerialCaffeineJsqlParseCache.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ public byte[] serialize(Object obj) {
4444

4545
@Override
4646
public Object deserialize(String sql, byte[] bytes) {
47-
try {
48-
return FstFactory.getDefaultFactory().asObject(bytes);
49-
} catch (Exception e) {
50-
cache.invalidate(sql);
51-
logger.error("deserialize error", e);
52-
}
53-
return null;
47+
return FstFactory.getDefaultFactory().asObject(bytes);
5448
}
5549
}

mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/parser/cache/JdkSerialCaffeineJsqlParseCache.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@
1818
import com.baomidou.mybatisplus.core.toolkit.SerializationUtils;
1919
import com.github.benmanes.caffeine.cache.Cache;
2020
import com.github.benmanes.caffeine.cache.Caffeine;
21-
import lombok.Setter;
22-
import net.sf.jsqlparser.statement.Statement;
23-
import net.sf.jsqlparser.statement.Statements;
24-
import org.apache.ibatis.logging.Log;
25-
import org.apache.ibatis.logging.LogFactory;
26-
27-
import java.util.concurrent.CompletableFuture;
28-
import java.util.concurrent.Executor;
21+
2922
import java.util.function.Consumer;
3023

3124
/**
@@ -52,12 +45,6 @@ public byte[] serialize(Object obj) {
5245

5346
@Override
5447
public Object deserialize(String sql, byte[] bytes) {
55-
try {
56-
return SerializationUtils.deserialize(bytes);
57-
} catch (Exception e) {
58-
cache.invalidate(sql);
59-
logger.error("deserialize error", e);
60-
}
61-
return null;
48+
return SerializationUtils.deserialize(bytes);
6249
}
6350
}

0 commit comments

Comments
 (0)