I need to use two database function one in which i need to delete comment and after that second function called which decreases the score of user .
Problem :
If exception occurs in second function score will not be deducted but comment was deleted .
I m trying store action of first function in class object and if exception occurs in second , reverse action will be taken place to rewrite it in database . Is there any other approach possible to do this please suggest me .
thanks in advance
You need to have both database calls within the scope of the same transaction. Thus if you get an exception, all will be rolled back.
It depends on how you access the database but it could be something like this: