The transaction.py module also defines the Transaction class as well as a TransactionError exception.
Here we can see that the Transaction class provides the ITransaction interface and also depends on the TransactionError exception. This exception is raised by the Transaction._close() method if there are no transactions on the transaction stack or if the only transaction on the stack is not the current transaction being closed.
There are also three events that are initiated by the Transaction class; TransactionBegin, TransactionCommit, and TransactionRollback.
Here is an example using the transactional decorator.
#Gaphor transaction decorator.
from gaphor.transaction import transactional
class MyDB:
@transactional
def update(self, data):
"""Update my hypothetical DB with data."""
print "Updating..."
if __name__=="__main__":
db_obj=MyDB()
db_obj.update(123)
No comments :
Post a Comment