Skip to content

Transactions_en

رامي مناف edited this page Jun 4, 2019 · 1 revision

Transactions

When you want to do more than one change on the database by executing several commands onto it you are doing a transaction on the database. But when you execute the commands on the database discreetly the database at a certain point will be in an unconscious state. Let's take an example. If a customer with a 600$ wanted to buy a computer that costs 600$ you will try to check if he has enough money and then you will discount 600$ from his account and add it to the seller account. But if there is an exception that has been thrown while executing these steps the database will be in an unconscious state e.g: the customer paid but the seller didn't receive anything. To prevent that Sofof offers the easy to use Transaction command that will execute all your commands by passing them in order to its constructor and it will execute all or none of them. In that way, if there is any exception been thrown the Transaction command will roll back all the process.

session.execute(new Transaction(customerDiscounting, sellerAdding));

Clone this wiki locally