Skip to content

Commit

Permalink
Optimize Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-hl committed May 22, 2024
1 parent 87baeb2 commit 9452a57
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/apache/ibatis/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.ibatis.reflection.ExceptionUtil;
import org.apache.ibatis.util.MapUtil;
Expand All @@ -34,6 +36,7 @@ public class Plugin implements InvocationHandler {
private final Object target;
private final Interceptor interceptor;
private final Map<Class<?>, Set<Method>> signatureMap;
private final ConcurrentMap<Method, Boolean> methodMap = new ConcurrentHashMap<>();

private Plugin(Object target, Interceptor interceptor, Map<Class<?>, Set<Method>> signatureMap) {
this.target = target;
Expand All @@ -53,9 +56,12 @@ public static Object wrap(Object target, Interceptor interceptor) {

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
boolean intercepted = MapUtil.computeIfAbsent(methodMap, method, key -> {
Set<Method> methods = signatureMap.get(method.getDeclaringClass());
if (methods != null && methods.contains(method)) {
return methods != null && methods.contains(method);
});
try {
if (intercepted) {
return interceptor.intercept(new Invocation(target, method, args));
}
return method.invoke(target, args);
Expand Down

0 comments on commit 9452a57

Please sign in to comment.