Since I am working on a relatively complex problem, I would like to use the Domain Driven Design approach to solving it. Problem in question is calculating monthly invoices for clients. The current solution is implemented as a very long Stored Procedure that is difficult to maintain.
I would like to use Object Oriented environment (possibly POCO and Entity Framework) but I am worried about performance. Current SP takes some 10 minutes to generate more than 300 000 records by using set operations. I think this would be very difficult to achieve with any ORM since it will load entity one by one and send updates in the same manner. (Previous version took 5 hours when accessing records one by one.)
How would you create a rich model for massive operations?
I avoid using massive operations as possible as I can when applying rich domain model.
Some batch could be replaced with events. For example, I need a daily order count report.
The batch solution:
A scheduling task which is triggered at the end of the day collects data from orders placed today.
Or use events
The PlaceOrderService publishes a OrderPlacedEvent when a new order is placed. And a eventHandler receives the event and inserts to T_ORDER_COUNT_ENTRY
|TODAY |ORDER_ID|
|2012-04-01|123 |
|2012-04-01|124 |
The we could use SQL count() to calculate the daily order count report.
Some other batch could run parallelly. For example, My orders should be canceled automatically if unpaid in 30 mins.
The original batch solution is fetch all orders satisfied one by one and invokes their cancel().
The current solution is fetch all orders satisfied one by one and sends a OrderIsOverdue message. Message handlers receive the message containing an orderId and retrieve the order then cancel.
I think this is useful when the cancel operation takes far more time than sends a message . More message handler could be added to improve the thoughput if the hardware resources can afford it.