Zope 2: Hooking into the transaction machinery
Every now and then I find myself looking for documentation about Zope 2 and how to
hook into its transaction machinery. In fact this is fairly easy.
All you have to to is using Shared.DC.ZRDB.TM.TM as mixin and implementing some methods. Let's have a look at an example:
...
from Shared.DC.ZRDB.TM import TM
class Foo(SimpleItem, TM):
"""a foo class"""
....
def _begin(self):
# called at begin of transaction
...
def _finish(self):
# called on commit
...
def _abort(self):
# called on rollback
...
Pretty easy. Please note that _finish is called in the second phase of Zope's two phase commit. If _finish throws an exception this is a serious error and your data might get inconsitent.
Christian Zagrodnick
Last modified 10.02.2004 08:15