Java Reference
In-Depth Information
@Override
public Customer mapRow(ResultSet rs, int arg1) throws SQLException {
Customer customer = new Customer();
customer.setAddress(rs.getString("address"));
customer.setCity(rs.getString("city"));
customer.setEmail(rs.getString("email"));
customer.setFirstName(rs.getString("firstName"));
customer.setId(rs.getLong("id"));
customer.setLastName(rs.getString("lastName"));
customer.setMiddleInitial(rs.getString("middleInitial"));
customer.setState(rs.getString("state"));
customer.setZip(rs.getString("zip"));
return customer;
}
}
Now that the Customer class can handle e-mails, you need to do one other piece of coding for the job
before you wire it up. As mentioned previously, this job needs an ItemProcessor to convert the Customer
objects into the required SimpleMailMessage s. Listing 9-56 shows the simple converter you use for this.
Listing 9-56. CustomerEmailConverter.java
package com.apress.springbatch.chapter9;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.mail.SimpleMailMessage;
public class CustomerEmailConverter implements
ItemProcessor<Customer, SimpleMailMessage> {
private static final String EMAIL_TEMPLATE =
"Welcome %s,\nYou were imported into the system using Spring Batch!";
@Override
public SimpleMailMessage process(Customer customer) throws Exception {
SimpleMailMessage mail = new SimpleMailMessage();
mail.setFrom(" prospringbatch@gmail.com");
mail.setTo(customer.getEmail());
mail.setSubject("Welcome!");
mail.setText(String.format(EMAIL_TEMPLATE,
new Object[] {customer.getFirstName(), customer.getLastName()}));
return mail;
}
}
 
Search WWH ::




Custom Search