Implementation
Each procedure is implemented as a simple, straightforward procedural script. It can use a thin abstraction layer for integrating with storage mechanisms, but it is also free to access the databases directly.
The only requirement procedures have to fulfill is transactional behavior. Each opera‐ tion should either succeed or fail but can never result in an invalid state. Even if execu‐ tion of a transaction script fails at the most inconvenient moment, the system should remain consistent—either by rolling back any changes it has made up until the failure or by executing compensating actions. The transactional behavior is reflected in the pattern’s name: transaction script.
Here is an example of a transaction script that converts batches of JSON files into XML files:
DB.StartTransaction();
var job = DB.LoadNextJob();
var json = LoadFile(job.Source);
var xml = ConvertJsonToXml(json); WriteFile(job.Destination, xml.ToString(); DB.MarkJobAsCompleted(job);
DB.Commit()