Java Reference
In-Depth Information
}
As Listing 8-14 shows, the AccountExecutiveDaoImpl consists of a single method to look up the
AccountExecutive by the Customer's information. The ResultSet you receive back is mapped by the
RowMapper implementation you coded inline.
To put this Dao to use, you could do two things. The first would be to implement the ItemProcessor
interface and perform the logic of looking up the AccountExecutive there. However, this doesn't provide
any portability when it comes to reusing this code outside of your batch jobs. Instead, you'll implement
a service that you can wrap with the ItemProcessorAdapter as well as use in non-Spring Batch
applications. Listing 8-15 shows the code for the service you will use.
Listing 8-15. CustomerServiceImpl
package com.apress.springbatch.chapter8;
public class CustomerServiceImpl {
private AccountExecutiveDao acctExecDao;
public AccountExecutive getAccountExecutiveForCustomer(Customer customer) {
return acctExecDao.getAccountExecutiveByCustomer(customer);
}
public void setAcctExecDao(AccountExecutiveDao execDao) {
acctExecDao = execDao;
}
}
In order to use this service, you can configure the ItemProcessorAdapter to call the
getAccountExecutiveForCustomer method. By default, Spring Batch will use the item the ItemProcessor
receives when its process method is called as the parameter to the method on the service you call. In
this case, the ItemProcessor you configure will receive a Customer object as the parameter to the process
method. Spring Batch will take that Customer object and call your service with that object as the
parameter. To make this happen, you configure your ItemProcessor to use the ItemProcessorAdapter as
the class and satisfy two required dependencies:
targetObject : The object that contains the method to be called.
targetMethod : The name of the method to be called (as a String).
The configuration for this is shown in Listing 8-16.
Listing 8-16. ItemProcessor Configuration
<beans:bean id=”accountExecutiveDao”
class=”com.apress.springbatch.chapter8.AccountExecutiveDaoImpl”>
<beans:property name=”dataSource” ref=”dataSource”/>
</beans:bean>
<beans:bean id=”customerService” class=”com.apress.springbatch.chapter8.CustomerServiceImpl”>
<beans:property name=”acctExecDao” ref=”accountExecutiveDao”/>
 
Search WWH ::




Custom Search