vendredi 27 mars 2015

How to manage business transactions



I have some bogus activity occurring in my code because of incomplete transactions and I'm not sure what to do about it.


For example, if I have:



User user = new User();
userService.save(user);
Email email = new Email(user, "Welcome!");
emailService.send(email);


and the server dies after saving the user but does not get to send the email then how can I revert the transaction?


Furthermore, to make things even more complex, let's say we sent the email first and then persisted the user afterwards and the email got sent, but the user didn't get persisted. Since that transaction couldn't possibly be reversed, there would have to be a way of managing all the "what-if" cases.


Does Java have a way of managing problems like these? I understand that this could be seen as an open-ended question, but the problem is that I don't actually know where to start learning about this problem.




Aucun commentaire:

Enregistrer un commentaire