Files
spring-batch/build/reference-epub-work/ch06s12.xhtml
Michael Minella 75ab909314 update
2017-03-23 10:18:33 -05:00

33 lines
3.1 KiB
HTML

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg"><head><title>Preventing State Persistence</title><link rel="stylesheet" type="text/css" href="docbook-epub.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="prev" href="ch06s11.xhtml" title="Validating Input"/><link rel="next" href="ch06s13.xhtml" title="Creating Custom ItemReaders and ItemWriters"/></head><body><header/><section class="section" title="Preventing State Persistence" epub:type="subchapter" id="process-indicator"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Preventing State Persistence</h2></div></div></div><p>By default, all of the <code class="classname">ItemReader</code> and
<code class="classname">ItemWriter</code> implementations store their current
state in the <code class="classname">ExecutionContext</code> 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 ensuring that only unprocessed records will be returned in the
case of a restart. In this scenario, it is preferable 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:</p><pre class="programlisting">&lt;bean id="playerSummarizationSource" class="org.spr...JdbcCursorItemReader"&gt;
&lt;property name="dataSource" ref="dataSource" /&gt;
&lt;property name="rowMapper"&gt;
&lt;bean class="org.springframework.batch.sample.PlayerSummaryMapper" /&gt;
&lt;/property&gt;
<span class="bold"><strong>&lt;property name="saveState" value="false" /&gt;</strong></span>
&lt;property name="sql"&gt;
&lt;value&gt;
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
&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre><p>The <code class="classname">ItemReader</code> configured above will not make
any entries in the <code class="classname">ExecutionContext</code> for any
executions in which it participates.</p></section><footer/></body></html>