Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transactional Design Pattern

I have a need to create a "transactional" process using an external API that does not support COM+ or .NET transactions (Sharepoint to be exact)

What I need to do is to be able to perform a number of processes in a sequence, but any failure in that sequence means that I will have to manually undo all of the previous steps. In my case there are only 2 types of step, both af which are fairly easy to undo/roll back.

Does anyony have any suggestions for design patterns or structures that could be usefull for this ?

like image 822
Matt Avatar asked Aug 22 '08 12:08

Matt


People also ask

What is a transactional pattern?

A transactional pattern is a convergence concept between workflow patterns and advanced transactional models. It can be seen as a coordination pattern and as a structured transaction. Thus, it combines workflow flexibility and transactional processing reliability.

Which of the following design pattern is also known as transaction?

A Command Pattern says that "encapsulate a request under an object as a command and pass it to invoker object. Invoker object looks for the appropriate object which can handle this command and pass the command to the corresponding object and that object executes the command". It is also known as Action or Transaction.

What are transactions in microservices?

A transaction is distributed to multiple services that are called sequentially or parallelly to complete the entire transaction. With a microservices architecture, the most common pattern is database per microservice, so transactions also need to span across different databases.


2 Answers

If your changes are done to the SharePoint object model, you can use the fact that changes are not committed until you call the Update() method of the modified object, such as SPList.Update() or SPWeb.Update().

Otherwise, I would use the Command Design Pattern. Chapter 6 in Head First Design Patterns even has an example that implements the undo functionality.

like image 76
vitule Avatar answered Oct 07 '22 17:10

vitule


The GoF Command Pattern supports undoable operations.

I think the same pattern can be used for sequential operations (sequential commands).

like image 26
Thomas Owens Avatar answered Oct 07 '22 19:10

Thomas Owens