final Executor executor = configuration.newExecutor(tx, execType);
通过Configuration创建一个executor
executor = (Executor) interceptorChain.pluginAll(executor);
动态代理executor (target)
=pluginAll(Object target) target是一个executor
for (Interceptor interceptor : interceptors/** 这个数组是插件的数组,所有插件都装到了这个数组*/) {
target = interceptor.plugin(target);一直生成,生成了一个又放进去生成,直到生成完毕,
}
@Intercepts(@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}))
生成的代理类有一个signatureMap以type = Executor.class为key,其他method,args为value
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
Plugin.wrap(target, this)生成一个代理类
Plugin impl InvocationHandler
Plugin实现了InvocationHandler
=wrap()
生成代理类
if (interfaces.length > 0) { return Proxy.newProxyInstance( type.getClassLoader(), interfaces, new Plugin(target, interceptor, signatureMap)); } return target;
=执行代理类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
Set
if (methods != null && methods.contains(method)) {
return interceptor.intercept(new Invocation(target, method, args));
}
return method.invoke(target, args);
} catch (Exception e) {
throw ExceptionUtil.unwrapThrowable(e);
}
}
return interceptor/** pageHelper*/.intercept(new Invocation(target, method, args));
走pagehelper的逻辑,
private Executor executor;
它里面有一个Executor,通过构造函数传进去。
List
executor如果是有插件的话,这个executor已经是代理类了
有包含了一个plugin(Pagehelper)
List
执行这一句,这里已经被它增强过了,走的是pagehelper的逻辑
也就是在生成executor的时候会生成插件代理
https://my.oschina.net/zudajun/blog/738973