|
28 | 28 | <body> |
29 | 29 | <section name="Spring Batch"> |
30 | 30 | <p> |
31 | | - As of version 1.1.0 MyBatis-Spring provides two beans for building Spring Batch applications: the <code>MyBatisPagingItemReader</code> |
32 | | - and the <code>MyBatisBatchItemWriter</code>. Both beans and this documentation are ports of their corresponding iBATIS 2.x versions |
33 | | - that are provided by default by in the Spring Batch bundle. |
| 31 | + As of version 1.1.0 MyBatis-Spring provides three beans for building Spring Batch applications: the <code>MyBatisPagingItemReader</code>, |
| 32 | + <code>MyBatisCursorItemReader</code> and the <code>MyBatisBatchItemWriter</code>. |
34 | 33 | </p> |
35 | 34 |
|
36 | 35 | <p> |
|
40 | 39 |
|
41 | 40 | <subsection name="MyBatisPagingItemReader"> |
42 | 41 | <p> |
43 | | - This bean is an <code>IteamReader</code> that reads records from a database using MyBatis in a paging fashion. |
| 42 | + This bean is an <code>IteamReader</code> that reads records from a database in a paging fashion. |
44 | 43 | </p> |
45 | 44 |
|
46 | 45 | <p> |
|
117 | 116 |
|
118 | 117 | </subsection> |
119 | 118 |
|
| 119 | + <subsection name="MyBatisCursorItemReader"> |
| 120 | + <p> |
| 121 | + This bean is an <code>IteamReader</code> that reads records from a database using a cursor. |
| 122 | + </p> |
| 123 | + |
| 124 | + <p> |
| 125 | + <span class="label important">NOTE</span> To use this bean you need at least MyBatis 3.4.0 or a newer version. |
| 126 | + </p> |
| 127 | + |
| 128 | + <p> |
| 129 | + It executes the query specified as the <code>setQueryId</code> property to retrieve requested data |
| 130 | + by using the method <code>selectCursor()</code>. |
| 131 | + Each time a <code>read()</code> method is called it will return the next element of the cursor until no more |
| 132 | + elements are left. |
| 133 | + </p> |
| 134 | + |
| 135 | + <p> |
| 136 | + The reader will use a separate connection so the select statement does no participate in any transactions created |
| 137 | + as part of the step processing. |
| 138 | + </p> |
| 139 | + |
| 140 | + <p>When using the cursor you can just execute a regular query:</p> |
| 141 | + <source><![CDATA[<select id="getEmployee" resultMap="employeeBatchResult"> |
| 142 | + SELECT id, name, job FROM employees ORDER BY id ASC |
| 143 | +</select>]]></source> |
| 144 | + |
| 145 | + <p>Follows below a sample configuration snippet:</p> |
| 146 | + |
| 147 | + <source><![CDATA[<bean id="reader" class="org.mybatis.spring.batch.MyBatisCursorItemReader"> |
| 148 | + <property name="sqlSessionFactory" ref="sqlSessionFactory" /> |
| 149 | + <property name="queryId" value="getEmployee" /> |
| 150 | +</bean>]]></source> |
| 151 | + |
| 152 | + </subsection> |
| 153 | + |
120 | 154 | <subsection name="MyBatisBatchItemWriter"> |
121 | 155 |
|
122 | 156 | <p> |
|
0 commit comments