嗨,我正在阅读myBatis的源代码,我的问题是我不理解SqlSessionmanager.this.localSqlSession.get()
行。 SqlSessionmanager.this
是什么意思?
我的尝试:如果我没有记错的话,在创建嵌套类时,请说A.B nestedObjectB = new A.B();
实际上是为它创建一个对象A.B
和一个匿名对象A
。所以我猜SqlSessionmanager.this
类似于这里的对象A
?
(在SqlSessionmanager.java
中)
private class SqlSessionInterceptor implements invocationHandler {
public SqlSessionInterceptor() {
// Prevent Synthetic access
}
@Override
public Object invoke(Object proxy,Method method,Object[] args) throws Throwable {
final SqlSession sqlSession = SqlSessionmanager.this.localSqlSession.get(); // *
if (sqlSession != null) {
try {
return method.invoke(sqlSession,args);
} catch (Throwable t) {
throw ExceptionUtil.unwrapthrowable(t);
}
} else {
try (SqlSession autoSqlSession = openSession()) {
try {
final Object result = method.invoke(autoSqlSession,args);
autoSqlSession.commit();
return result;
} catch (Throwable t) {
autoSqlSession.rollback();
throw ExceptionUtil.unwrapthrowable(t);
}
}
}
}
}