Skip to content

Commit 66556f9

Browse files
kazuki43zooschauder
authored andcommitted
DATAJDBC-161 - Share a SqlSession between statements.
Original pull request: #29.
1 parent 1713534 commit 66556f9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.ibatis.session.SqlSession;
2222
import org.apache.ibatis.session.SqlSessionFactory;
23+
import org.mybatis.spring.SqlSessionTemplate;
2324
import org.springframework.data.jdbc.core.DataAccessStrategy;
2425
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
2526
import org.springframework.data.mapping.PropertyPath;
@@ -33,16 +34,22 @@
3334
* methods taking a {@link PropertyPath} the entityTyoe if the context is set to the class of the leaf type.
3435
*
3536
* @author Jens Schauder
37+
* @author Kazuki Shimizu
3638
*/
3739
public class MyBatisDataAccessStrategy implements DataAccessStrategy {
3840

3941
private static final String MAPPER_SUFFIX = "Mapper";
4042

41-
private final SqlSessionFactory sqlSessionFactory;
43+
private final SqlSession sqlSession;
4244

4345
public MyBatisDataAccessStrategy(SqlSessionFactory sqlSessionFactory) {
4446

45-
this.sqlSessionFactory = sqlSessionFactory;
47+
this(new SqlSessionTemplate(sqlSessionFactory));
48+
}
49+
50+
public MyBatisDataAccessStrategy(SqlSessionTemplate sqlSessionTemplate) {
51+
52+
this.sqlSession = sqlSessionTemplate;
4653
}
4754

4855
@Override
@@ -135,7 +142,7 @@ private String mapper(Class<?> domainType) {
135142
}
136143

137144
private SqlSession sqlSession() {
138-
return sqlSessionFactory.openSession();
145+
return this.sqlSession;
139146
}
140147

141148
private String toDashPath(PropertyPath propertyPath) {

0 commit comments

Comments
 (0)