22 lines
2.4 KiB
HTML
22 lines
2.4 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>ItemWriter</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="ch06.xhtml" title="Chapter 6. ItemReaders and ItemWriters"/><link rel="next" href="ch06s03.xhtml" title="ItemProcessor"/></head><body><header/><section class="section" title="ItemWriter" epub:type="subchapter" id="itemWriter"><div class="titlepage"><div><div><h2 class="title" style="clear: both">ItemWriter</h2></div></div></div><p><code class="classname">ItemWriter</code> is similar in functionality to an
|
||
<code class="classname">ItemReader</code>, but with inverse operations. Resources
|
||
still need to be located, opened and closed but they differ in that an
|
||
<code class="classname">ItemWriter</code> writes out, rather than reading in. In
|
||
the case of databases or queues these may be inserts, updates, or sends.
|
||
The format of the serialization of the output is specific to each batch
|
||
job.</p><p>As with <code class="classname">ItemReader</code>,
|
||
<code class="classname">ItemWriter</code> is a fairly generic interface:</p><pre class="programlisting">public interface ItemWriter<T> {
|
||
|
||
void write(List<? extends T> items) throws Exception;
|
||
|
||
}</pre><p>As with <code class="methodname">read</code> on
|
||
<code class="classname">ItemReader</code>, <code class="methodname">write</code> provides
|
||
the basic contract of <code class="classname">ItemWriter</code>; it will attempt
|
||
to write out the list of items passed in as long as it is open. Because it
|
||
is generally expected that items will be 'batched' together into a chunk
|
||
and then output, the interface accepts a list of items, rather than an
|
||
item by itself. After writing out the list, any flushing that may be
|
||
necessary can be performed before returning from the write method. For
|
||
example, if writing to a Hibernate DAO, multiple calls to write can be
|
||
made, one for each item. The writer can then call close on the hibernate
|
||
Session before returning.</p></section><footer/></body></html> |