ClassifierCompositeItemWriter with AsyncItemWriter?

277 Views Asked by At

I am currently using AsyncItemWriter to write the processed student details input into my database table. I recently got the requirement to write into several database tables based on criteria (if the student is in their last year, also write in a separate table with additional data).

Currently I have two, separately working AsyncItemWriter Beans defined. Tried using a CompositeItemWriter, which actually works and uses both delegates to write into the appropriate tables. Now, I want to call the second writer only if the above mentioned condition is met.

I tried using a ClassifierCompositeItemWriter with a custom Classifier implementation for my Student class, which should return the CompositeItemWriter when the student in last year criteria is met, else calls the single AsyncItemWriter to store the student data. Unfortunately when the ClassifierCompositeItemWriter's write() method gets called, the items inside the write list are of type FutureTask and on classify() call the writer fails with ClassCastException, as it couldn't cast the FutureTask into my Student model.

Unfortunately I currently don't have code at hand, but tried to be as thorough as possible.

1

There are 1 best solutions below

0
On

I tried using a ClassifierCompositeItemWriter with a custom Classifier implementation for my Student class, which should return the CompositeItemWriter when the student in last year criteria is met, else calls the single AsyncItemWriter to store the student data

This starts to become complex for no real benefit. I would keep it simple and use a custom writer with an "if" inside the implementation corresponding to if the student is in their last year, also write in a separate table with additional data.