Java Reference
In-Depth Information
<beans:bean id="citySetter"
class="com.apress.springbatch.chapter7.CitySetter" scope=”step”>
<beans:property name="city" value="#{jobParameters[city]}"/>
</beans:bean>
<beans:bean id="customerRowMapper"
class="com.apress.springbatch.chapter7.CustomerRowMapper"/>
Notice that in the SQL, there is a ? where your parameter will go. This is nothing more than a
standard PreparedStatement. Spring Batch will use your CitySetter to set the value of the city to be
processed. This is the same processing paradigm as the JdbcTemplate in Spring Core uses. Listing 7-41
shows your CitySetter implementation.
Listing 7-41. CitySetter
package com.apress.springbatch.chapter7;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.springframework.jdbc.core.PreparedStatementSetter;
public class CitySetter implements PreparedStatementSetter {
private String city;
public void setValues(PreparedStatement ps) throws SQLException {
ps.setString(1, city);
}
public void setCity(String city) {
this.city = city;
}
}
This job is executed using virtually the same command as the previous example. he only difference
is the addition of the city parameter: java -jar copyJob.jar jobs/copyJob.xml copyJob
outputFile=/output/jdbcOutput.txt city=”Carol Stream” .
With the ability to not only stream items from the database but also inject parameters into your
queries, this approach is useful in the real world. There are good and bad things about this approach. It
can be a good thing to stream records in certain cases; however, when processing a million rows, the
individual network overhead for each request can add up, which leads you to the other option, paging.
JDBC Paged Processing
When working with a paginated approach, Spring Batch returns the result set in chunks called pages.
Each page is a predefined number of records to be returned by the database. It is important to note that
when working with pages, the items your job will process will still be processed individually. There is no
difference in the processing of the records. What differs is the way they are retrieved from the database.
Instead of retrieving records one at a time, paging will essentially cache a page until they are needed to
be processed. In this section, you'll update your configuration to return a page of 10 records in a page.
 
Search WWH ::




Custom Search