- A code example (implies a 'transaction' keyword)
transaction
...some code that makes up the transaction
try:
transaction:
...This is a sub-transacation
except:
handle failure of sub transaction...
... more code for the first transaction...
- A new compound statement is needed
Transaction.Begin()
... some code ...
Transaction.End()
- problem - An exception might cause you not to execute
'End()'
- A possible solution...
Tansaction.Begin()
ok=0
try:
...some code...
ok=1
finally:
if ok:
Transaction.End()
else:
Transaction.Abort()
- Problems
- Exposes the transaction logic
- complicated and therefore error prone
- it obscures the application program
- A generic routine designated to handle the transaction
def mytransaction(v1,v2,v3):
... some code ...
- Function would propagate the exception back to the application
- Disadvantage - must break flow to execute this function
- Another Problem - Critical regions - must do locks
lock.aquire()
... some code ...
lock.release()
- Nested transactions - make things more complicated
- Two cantidate proposals - both involve an in statement
in expression:
... some code ...
in Transaction.Transaction():
... some code for transaction t1
try:
in Transaction.Transaction():
... some code for t2 ...
except:
... handle failure of t2
... more code for t1
- Proposal 1
- convert the suite to a callable object
- something that looks like a Smalltalk block is also
possible
- Proposal 2
- call a special object before and after executing the suite
- does not use code blocks
- handles transactions and critical regions
- does not handle threads and callbacks