I would like to use Spring batch for a batch application. I already have a domain model designed following DDD. My question is how batch processing (in my case, using Spring batch) fits with DDD?
For example, I have an aggregate root A and one of its children is the entity B. A has a list of one or more Bs. The batch application receives a file when each line corresponds to an operation (add, delete…) on the list of Bs. In my aggregate root A, I have one method for each operation (e.g. addB, delB…). Using Spring batch, which ItemWriter should I use? I don’t think a JdbcBatchItemWriter is appropriated since I should deal with the data only through the domain. Are there best practices concerning the use of DDD with batch processing?
Thanks
I don’t pretend to know what exactly the best practice for this is, but this is how I’d do it, considering your design goals. Instead of A and B, say we have a File object, your aggregate, which contains many lines:
Have your Reader/Processors return LineOperations, encapsulating your line (which you just read) and whether you are doing an add/remove/other:
Implementations of the AddOperation and whatever else you may require are left to the imagination.
Next, we’ll be passing the the LineOperations to your writer. Your writer performs the operation on the Aggregate File, and then uses the FileRepository to write the aggregate.
Hope this helps.