Hi I'm reading myBatis' source code and my problem is that I don't understand the line SqlSessionManager.this.localSqlSession.get()
. What's the meaning of SqlSessionManager.this
?
My trying: If I remember it correctly When create a nested class say A.B nestedObjectB = new A.B();
It actually create an object A.B
and an anonymous object A
for it. So I guess SqlSessionManager.this
is analogous to the object A
here?
(In 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);
}
}
}
}
}