[Zope-Checkins] CVS: Products/DCOracle2 - SP.py:1.12

Matthew T. Kromer matt@zope.com
Sat, 21 Dec 2002 15:29:07 -0500


Update of /cvs-repository/Products/DCOracle2
In directory cvs.zope.org:/tmp/cvs-serv13481

Modified Files:
	SP.py 
Log Message:
SP fix to use a modified TM class which doesnt store registration info
in non-volatile vars


=== Products/DCOracle2/SP.py 1.11 => 1.12 ===
--- Products/DCOracle2/SP.py:1.11	Wed May 15 17:14:23 2002
+++ Products/DCOracle2/SP.py	Sat Dec 21 15:29:06 2002
@@ -90,7 +90,7 @@
 import sys
 from Globals import HTMLFile
 from OFS.SimpleItem import SimpleItem
-from Shared.DC.ZRDB.TM import TM
+from Shared.DC.ZRDB.TM import Surrogate
 from string import split
 from AccessControl import getSecurityManager
 import DCOracle2
@@ -102,7 +102,62 @@
 else:
     dbstring = myname
 
-class Procedure(SimpleItem, TM):
+class VTM:
+    """Mix-in class that provides transaction management support
+
+    A sub class should call self._register() whenever it performs
+    any transaction-dependent operations (e.g. sql statements).
+
+    The sub class will need to override _finish, to finalize work,
+    _abort, to roll-back work, and perhaps _begin, if any work is needed
+    at the start of a transaction.
+
+    *** This code copied out from Shared/DC/ZRDB/TM to make _registered
+    *** and _finalize volatile variable names
+    """
+
+    _registered=None
+
+    def _begin(self): pass
+
+    def _register(self):
+        if not self._registered:
+            try:
+                get_transaction().register(Surrogate(self))
+                self._begin()
+                self._v_registered = 1
+                self._v_finalize = 0
+            except:
+                import sys
+                print sys.exc_info()
+
+    def tpc_begin(self, *ignored): pass
+    commit=tpc_begin
+
+    def _finish(self):
+        self.db.commit()
+
+    def _abort(self):
+        self.db.rollback()
+
+    def tpc_vote(self, *ignored):
+        self._v_finalize = 1
+
+    def tpc_finish(self, *ignored):
+
+        if self._v_finalize:
+            try: self._finish()
+            finally: self._v_registered=0
+
+    def abort(self, *ignored):
+        try: self._abort()
+        finally: self._v_registered=0
+
+    tpc_abort = abort
+
+
+
+class Procedure(SimpleItem, VTM):
 
     manage_options=(
         {'label': 'Edit', 'action':'manage_procview'},