Java Reference
In-Depth Information
appropriate orders and passes them to a MultiResourceItemWriter so that each picklist is contained
within its own file. For this final step, you need to write a small amount of code in the LineAggregator for
the writer because you need to loop over the OrderItem s in the order. Listing 11-17 shows the code for
the LineAggregator , PickListFormatter .
Listing 11-17. PickListFormatter
package com.apress.springbatch.chapter11.writer;
import org.springframework.batch.item.file.transform.LineAggregator;
import com.apress.springbatch.chapter11.domain.Order;
import com.apress.springbatch.chapter11.domain.OrderItem;
public class PickListFormatter implements LineAggregator<Order> {
public String aggregate(Order order) {
StringBuilder builder = new StringBuilder();
builder.append("Items to pick\n");
if(order.getItems() != null) {
for (OrderItem item : order.getItems()) {
builder.append(item.getItemNumber() + ":" + item.getQty() + "\n");
}
} else {
builder.append("No items to pick");
}
return builder.toString();
}
}
Because all you need to do is write a small header (“Items to pick”) and then list the item numbers
and the quantity to pick, this LineAggregator is very simple to code. The configuration for the final step
consists of adding the new step to the job and pointing the split tag to the step after both flows have
completed. Listing 11-18 shows the configuration of the final step and the completed job.
Listing 11-18. The Completed parallelJob Configuration
<beans:bean id="validatedOrderItemReader"
class="org.springframework.batch.item.database.HibernateCursorItemReader"
scope="step">
<beans:property name="sessionFactory" ref="sessionFactory"/>
<beans:property name="queryString"
value="from Order as o where o.creditValidated = true and not exists
(from OrderItem oi where oi.order = o and oi.inventoryValidated = false)"/>
<beans:property name="useStatelessSession" value="false"/>
</beans:bean>
Search WWH ::




Custom Search