|
15 | 15 | */ |
16 | 16 | package org.mybatis.spring.batch; |
17 | 17 |
|
18 | | -import static org.springframework.util.Assert.notNull; |
19 | | -import static org.springframework.util.ClassUtils.getShortName; |
20 | | - |
21 | | -import java.util.HashMap; |
22 | | -import java.util.Map; |
23 | | -import java.util.concurrent.CopyOnWriteArrayList; |
24 | | - |
25 | 18 | import org.apache.ibatis.session.ExecutorType; |
26 | 19 | import org.apache.ibatis.session.SqlSession; |
27 | 20 | import org.apache.ibatis.session.SqlSessionFactory; |
28 | 21 | import org.mybatis.spring.SqlSessionTemplate; |
29 | 22 | import org.springframework.batch.item.database.AbstractPagingItemReader; |
30 | 23 |
|
| 24 | +import java.util.HashMap; |
| 25 | +import java.util.Map; |
| 26 | +import java.util.concurrent.CopyOnWriteArrayList; |
| 27 | + |
| 28 | +import static org.springframework.util.Assert.notNull; |
| 29 | +import static org.springframework.util.ClassUtils.getShortName; |
| 30 | + |
31 | 31 | /** |
32 | 32 | * {@code org.springframework.batch.item.ItemReader} for reading database |
33 | 33 | * records using MyBatis in a paging fashion. |
@@ -89,12 +89,14 @@ public void setParameterValues(Map<String, Object> parameterValues) { |
89 | 89 | public void afterPropertiesSet() throws Exception { |
90 | 90 | super.afterPropertiesSet(); |
91 | 91 | notNull(sqlSessionFactory, "A SqlSessionFactory is required."); |
92 | | - sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory, ExecutorType.BATCH); |
93 | 92 | notNull(queryId, "A queryId is required."); |
94 | 93 | } |
95 | 94 |
|
96 | 95 | @Override |
97 | 96 | protected void doReadPage() { |
| 97 | + if (sqlSessionTemplate == null) { |
| 98 | + sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory, ExecutorType.BATCH); |
| 99 | + } |
98 | 100 | Map<String, Object> parameters = new HashMap<>(); |
99 | 101 | if (parameterValues != null) { |
100 | 102 | parameters.putAll(parameterValues); |
|
0 commit comments