[Zodb-checkins] CVS: ZODB3/ZODB - Transaction.py:1.56.2.1

Fred L. Drake, Jr. fred at zope.com
Thu Jan 22 15:16:43 EST 2004


Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv4442

Modified Files:
      Tag: zope3-zodb3-devel-branch
	Transaction.py 
Log Message:
Checking in so Jim can edit.

Added join method to support zodb4 data managers.

Added adapter from zodb4 data managers to zodb3 data managers.

Added an XXX suggesting that we need to revisit transaction
management.


=== ZODB3/ZODB/Transaction.py 1.56 => 1.56.2.1 ===
--- ZODB3/ZODB/Transaction.py:1.56	Mon Dec 29 17:40:48 2003
+++ ZODB3/ZODB/Transaction.py	Thu Jan 22 15:16:42 2004
@@ -90,6 +90,9 @@
         else:
             return "Transaction thread=%s user=%s" % (self._id, `self.user`)
 
+    # XXX This whole freeme business is lame.
+    # As a separate task, we really need to revisit transaction management.
+
     def __del__(self):
         if self._objects:
             self.abort(freeme=0)
@@ -428,6 +431,11 @@
         'Register the given object for transaction control.'
         self._append(object)
 
+    def join(self, zodb4datamanager):
+        """Join a transaction.interfaces.IDataManager with the transaction
+        """
+        self._append(DataManagerAdapter(zodb4datamanager))
+
     def note(self, text):
         if self.description:
             self.description = "%s\n\n%s" % (self.description, text.strip())
@@ -454,6 +462,66 @@
 the system problem.  See your application log for
 information on the error that lead to this problem.
 """
+
+
+
+class DataManagerAdapter(object):
+    """Adapt zodb 4-style data managers to zodb3 style
+
+    Adapt transaction.interfaces.IDataManager to
+    ZODB.interfaces.IPureDatamanager
+    """
+
+    # Note that it is pretty important that this does not have a _p_jar
+    # attribute. This object will be registered with a zodb3 TM, which
+    # will then try to get a _p_jar from it, using it as the default.
+    # (Objects without a _p_jar are their own data managers.)
+
+    def __init__(self, datamanager):
+        self._datamanager = datamanager
+        self._rollback = None
+
+    def commit(self, ob, transaction):
+        assert ob is self
+
+    def abort(self, ob, transaction):
+        assert ob is self
+
+        # We need to discard any changes since the last save point, or all
+        # changes
+
+        if self._rollback is None:
+            # No previous savepoint, so just abort
+            self._datamanager.abort(transaction)
+        else:
+            self._rollback()
+
+    def abort_sub(self, transaction):
+        self._datamanager.abort(transaction)
+
+    def commit_sub(self, transaction):
+        pass # Nothing to do
+        
+    def tpc_begin(self, transaction, subtransaction):
+        self._sub = subtransaction
+
+    def tpc_abort(self, transaction):
+        if self._sub:
+            self.abort(self, transaction)
+        else:
+            self._datamanager.abort(transaction)
+
+    def tpc_finish(self, transaction):
+        if self.sub:
+            self._rollback = self._datamanager.savepoint().rollback
+        else:
+            self._datamanager.commit(transaction)
+
+    def tpc_vote(self, transaction):
+        if not self._sub:
+            self._datamanager.prepare(transaction)
+        
+
 
 ############################################################################
 # install get_transaction:




More information about the Zodb-checkins mailing list