Skip to content

Commit fdab870

Browse files
committed
Added SqlSessionManagerTest. Fixed getMapper() implementation to not use the proxied mapper.
1 parent d6ef7ec commit fdab870

File tree

2 files changed

+506
-7
lines changed

2 files changed

+506
-7
lines changed

src/main/java/org/apache/ibatis/session/SqlSessionManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.apache.ibatis.session;
22

3+
import org.apache.ibatis.reflection.ExceptionUtil;
4+
35
import java.io.Reader;
46
import java.lang.reflect.InvocationHandler;
57
import java.lang.reflect.Method;
@@ -15,10 +17,6 @@ public class SqlSessionManager implements SqlSessionFactory, SqlSession {
1517

1618
private ThreadLocal<SqlSession> localSqlSession = new ThreadLocal<SqlSession>();
1719

18-
private SqlSessionManager(Reader reader, Properties properties) {
19-
this(new SqlSessionFactoryBuilder().build(reader, null, properties));
20-
}
21-
2220
public static SqlSessionManager newInstance(Reader reader) {
2321
return new SqlSessionManager(new SqlSessionFactoryBuilder().build(reader, null, null));
2422
}
@@ -31,7 +29,11 @@ public static SqlSessionManager newInstance(Reader reader, Properties properties
3129
return new SqlSessionManager(new SqlSessionFactoryBuilder().build(reader, null, properties));
3230
}
3331

34-
public SqlSessionManager(SqlSessionFactory sqlSessionFactory) {
32+
public static SqlSessionManager newInstance(SqlSessionFactory sqlSessionFactory) {
33+
return new SqlSessionManager(sqlSessionFactory);
34+
}
35+
36+
private SqlSessionManager(SqlSessionFactory sqlSessionFactory) {
3537
this.sqlSessionFactory = sqlSessionFactory;
3638
this.sqlSessionProxy = (SqlSession) Proxy.newProxyInstance(
3739
SqlSessionFactory.class.getClassLoader(),
@@ -164,7 +166,7 @@ public int delete(String statement, Object parameter) {
164166
}
165167

166168
public <T> T getMapper(Class<T> type) {
167-
return sqlSessionProxy.getMapper(type);
169+
return getConfiguration().getMapper(type, this);
168170
}
169171

170172
public Connection getConnection() {
@@ -226,7 +228,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
226228
return result;
227229
} catch (Throwable t) {
228230
autoSqlSession.rollback();
229-
throw t;
231+
throw ExceptionUtil.unwrapThrowable(t);
230232
} finally {
231233
autoSqlSession.close();
232234
}

0 commit comments

Comments
 (0)