Java Reference
In-Depth Information
private SeatDao dao;
@Override
public Object processItem(Object id) throws Exception {
Seat seat = dao.find(Long.parseLong((String) id));
if (seat != null) {
if (seat.getBooked() == true) {
return null;
}
seat.setBooked(true);
}
return seat;
}
}
Our processor retrieves IDs from the reader and finds the corresponding entry in the data-
base. To find the entity, we reuse our SeatDao class known from previous chapters. Be-
cause we have CDI working on the batch framework, we can just inject our EJB without
caring about transaction handling.
If the seat is found, we check if it's already booked. If yes, we can simply return a null
value to omit this item from further processing.
The last step is SeatWriter . This is shown in the following code snippet:
package com.packtpub.wflydevelopment.chapter12.batching;
import javax.batch.api.chunk.AbstractItemWriter;
import javax.batch.runtime.context.JobContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Named
public class SeatWriter extends AbstractItemWriter {
public static final String FILENAME_PARAM = "logFile";
Search WWH ::




Custom Search