BATCH-667:Added a section to Chapter 3 about the 'saveSate' property.
This commit is contained in:
@@ -2199,6 +2199,52 @@
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Preventing state persistence</title>
|
||||
|
||||
<para>By default, all of the <classname>ItemReader</classname> and
|
||||
<classname>ItemWriter</classname> implementations store their current
|
||||
state in the <classname>ExecutionContext</classname> before it is
|
||||
committed. However, this may not always be the desired behavior. For
|
||||
example, many developers choose to make their database readers
|
||||
'rerunnable' by using a process indicator. An extra column is added to the
|
||||
input data to indicate whether or not it has been processed. When a
|
||||
particular record is being read (or written out) the processed flag is
|
||||
flipped from false to true. The SQL statement can then contain an extra
|
||||
statement in the where clause, such as: "where PROCESSED_IND = false",
|
||||
thereby insuring that only unprocessed records will be returned in the
|
||||
case of a restart. In this scenario, it is prefereable to not store any
|
||||
state, such as the current row number, since it will be irrelevant upon
|
||||
restart. For this reason, all readers and writers include the 'saveState'
|
||||
property:</para>
|
||||
|
||||
<programlisting>
|
||||
<bean id="playerSummarizationSource"
|
||||
class="org.springframework.batch.item.database.JdbcCursorItemReader">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="mapper">
|
||||
<bean class="org.springframework.batch.sample.mapping.PlayerSummaryMapper" />
|
||||
</property>
|
||||
<property name="saveState" value="false" />
|
||||
<property name="sql">
|
||||
<value>
|
||||
SELECT games.player_id, games.year_no, SUM(COMPLETES),
|
||||
SUM(ATTEMPTS), SUM(PASSING_YARDS), SUM(PASSING_TD),
|
||||
SUM(INTERCEPTIONS), SUM(RUSHES), SUM(RUSH_YARDS),
|
||||
SUM(RECEPTIONS), SUM(RECEPTIONS_YARDS), SUM(TOTAL_TD)
|
||||
from games, players where players.player_id =
|
||||
games.player_id group by games.player_id, games.year_no
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</programlisting>
|
||||
|
||||
<para>The <classname>ItemReader</classname> configured above will not make
|
||||
any entries in the <classname>ExecutionContext</classname> for any
|
||||
executions it participates in.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title id="infrastructure.1.1">Creating Custom ItemReaders and
|
||||
ItemWriters</title>
|
||||
|
||||
Reference in New Issue
Block a user