如果保证更新俩个聚合对象的内部状态的最终一致性。
eg)jdonjive
假设状况如下,必须同时更新俩个不同的聚合对象
ForumMessageReply tmp;//create a Object
Forum1.addNewMessage(tmp);//
Forum2.addNewMessage(tmp);//当执行到这儿时,业务规则不通过。
你们是如何维护或恢复第一个聚合对象的状态呢?
如果有transaction ,那么问题就解决了。(条件是没有软更新,软更新也是需要靠JMS 去触发进行软更新,以保证最终一致性)
可我看了jdonjive的源码,多是软更新,并没有任何的防范措施。
或许在论坛不用这么复杂。但是DDD其中一个目的就是为了复用对象呀。我找了很久,但就是没人说说如何更新俩个聚合对象,如何保证内部状态的最终一致性。
请解惑。谢谢。
我想到的是。通过已下方案解决
1)base on JMS solution.
UserTransaction trans=getTransaction
trans.begin();
try
{
ForumMessageReply tmp;//create a Object
// submit to jms,current state still not update,when JMS commit will triger
// object to update it,and notice Repository to store that state.
Forum1.addNewMessage(tmp);
// submit to jms,current state still not update,when JMS commit will triger
// object owner to update it,and notice Repository to store that state.
Forum2.addNewMessage(tmp);
trans.commit();
//JMS will notice Object to update that reference.
}
catch(Exception e)
{
trans.rollback();
//when rollback,JMS not commit, so not event to update object state.
}
2)Base on transaction support 的 reference , List, Map .....
trans.begin();
Forum1.addNewMessage(tmp); //add object to List(Transaction Support).
Forum2.addNewMessage(tmp); //add object to List(Transaction Support).
trans.commit();