Java Reference
In-Depth Information
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
public class AccountExecutiveDaoImpl extends JdbcTemplate implements
AccountExecutiveDao {
private String BY_CUSTOMER = "select a.* from accountExecutive a inner join customer c " +
"on a.id = c.accountExecutiveId where c.id = ?";
public AccountExecutive getAccountExecutiveByCustomer(Customer customer) {
return (AccountExecutive) queryForObject(BY_CUSTOMER,
new Object [] {
customer.getId()},
new RowMapper() {
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
AccountExecutive result = new AccountExecutive();
result.setFirstName(rs.getString("firstName"));
result.setLastName(rs.getString("lastName"));
result.setId(rs.getLong("id"));
return result;
}
});
}
}
As you did in the CustomerDaoImpl in Listing 8-19, the AccountExecutiveDaoImpl queries the database
using Spring's JdbcTemplate. Using Spring's RowMapper facilities, you are able to map the results of the
query to the new AccountExecutive object and return it to your ItemProcessor.
With your code written, you can wire up this job and see how it runs. The configuration for this
job—including the two DAOs, the two ItemProcessors, one reader, one writer, the step, and the job—can
all be found in Listing 8-21.
Listing 8-21. Configuring a Step with a CompositeItemProcessor
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=" http://www.springframework.org/schema/batch"
xmlns:beans=" http://www.springframework.org/schema/beans"
xmlns:util=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<beans:import resource="../launch-context.xml"/>
<beans:bean id="customerFile" class="org.springframework.core.io.FileSystemResource"
scope="step">
 
Search WWH ::




Custom Search