How to ensure ACID properties are maintained in a transaction?