no there can only be returned one item, but you have the full Java possibilities at hand:
- encapsulate two elements as properties of an "item" transferobject
- return a list which contains the two elements (eventually with an abstract parent which provides discriminator mechanism)
it might be more clever to implement the "split" inside the reader, depends on your requirements
i would go with the "split-transformation" into a list with an itemProcessor
read -> A -> processor -> list(A1,A2) -> writer (handles list)
this works because the processor can return any Java class you like it to return, as long as the writer(s) can work with it
some code examples:
Code:
public class ListItemProcessor implements ItemProcessor<Object, List<Object>> {
@Override
public List<Object> process(Object item) throws Exception {
// transform item to list of objects
return list;
}
}
Code:
public class ListItemWriter implements ItemWriter<List<Object>> {
@Override
public void write(List<? extends List<Object>> items) throws Exception {
for (List<Object> list : items) {
for (Object object : list) {
// if object of type A, do that
// if object of type B, do this
}
}
}
}