1
1
package org .apache .ibatis .session ;
2
2
3
+ import org .apache .ibatis .reflection .ExceptionUtil ;
4
+
3
5
import java .io .Reader ;
4
6
import java .lang .reflect .InvocationHandler ;
5
7
import java .lang .reflect .Method ;
@@ -15,10 +17,6 @@ public class SqlSessionManager implements SqlSessionFactory, SqlSession {
15
17
16
18
private ThreadLocal <SqlSession > localSqlSession = new ThreadLocal <SqlSession >();
17
19
18
- private SqlSessionManager (Reader reader , Properties properties ) {
19
- this (new SqlSessionFactoryBuilder ().build (reader , null , properties ));
20
- }
21
-
22
20
public static SqlSessionManager newInstance (Reader reader ) {
23
21
return new SqlSessionManager (new SqlSessionFactoryBuilder ().build (reader , null , null ));
24
22
}
@@ -31,7 +29,11 @@ public static SqlSessionManager newInstance(Reader reader, Properties properties
31
29
return new SqlSessionManager (new SqlSessionFactoryBuilder ().build (reader , null , properties ));
32
30
}
33
31
34
- public SqlSessionManager (SqlSessionFactory sqlSessionFactory ) {
32
+ public static SqlSessionManager newInstance (SqlSessionFactory sqlSessionFactory ) {
33
+ return new SqlSessionManager (sqlSessionFactory );
34
+ }
35
+
36
+ private SqlSessionManager (SqlSessionFactory sqlSessionFactory ) {
35
37
this .sqlSessionFactory = sqlSessionFactory ;
36
38
this .sqlSessionProxy = (SqlSession ) Proxy .newProxyInstance (
37
39
SqlSessionFactory .class .getClassLoader (),
@@ -164,7 +166,7 @@ public int delete(String statement, Object parameter) {
164
166
}
165
167
166
168
public <T > T getMapper (Class <T > type ) {
167
- return sqlSessionProxy .getMapper (type );
169
+ return getConfiguration () .getMapper (type , this );
168
170
}
169
171
170
172
public Connection getConnection () {
@@ -226,7 +228,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
226
228
return result ;
227
229
} catch (Throwable t ) {
228
230
autoSqlSession .rollback ();
229
- throw t ;
231
+ throw ExceptionUtil . unwrapThrowable ( t ) ;
230
232
} finally {
231
233
autoSqlSession .close ();
232
234
}
0 commit comments