Beispiel #1
0
 def rollback_transaction(self):
     """
     RollBack a transaction. 
     If we are part of nested transaction - rollback everything up to top parent transaction.
     """
     if not self.open_transactions:
         raise InvalidTransactionAccess("You are trying to close a transaction that was not started.")
     for transaction_idx in range(self.open_transactions):
         transaction = self.sessions_stack[-(1 + transaction_idx)]
         transaction.rollback()
Beispiel #2
0
 def close_transaction(self):
     """
     Close a transaction. Make sure to commit beforehand so all changes are written to database. Then
     depending on if we are top level or not either close or expunge session.
     """
     if not self.open_transactions:
         raise InvalidTransactionAccess("You are trying to close a transaction that was not started.")
     self.open_transactions -= 1
     top_transaction_session = self.sessions_stack.pop()
     top_transaction_session.commit()
     if self.open_transactions == 0:
         top_transaction_session.close()
     else:
         top_transaction_session.expunge_all()
     del top_transaction_session