[Zope3-checkins] CVS: Zope3/src/transaction -
_transaction.py:1.1.2.22
Jeremy Hylton
jeremy at zope.com
Mon Mar 22 17:29:41 EST 2004
Update of /cvs-repository/Zope3/src/transaction
In directory cvs.zope.org:/tmp/cvs-serv20984
Modified Files:
Tag: jeremy-txn-branch
_transaction.py
Log Message:
Fixes for undo() &c.
The objects passed to register() when you call db.undo() &c need to be
adapted in a funny way.
=== Zope3/src/transaction/_transaction.py 1.1.2.21 => 1.1.2.22 ===
--- Zope3/src/transaction/_transaction.py:1.1.2.21 Mon Mar 22 17:00:03 2004
+++ Zope3/src/transaction/_transaction.py Mon Mar 22 17:29:34 2004
@@ -141,12 +141,20 @@
self._resources.append(resource)
def register(self, obj):
+ # The old way of registering transaction participants.
+ #
+ # register() is passed either a persisent object or a
+ # resource manager like the ones defined in ZODB.DB.
+ # If it is passed a persistent object, that object should
+ # be stored when the transaction commits. For other
+ # objects, the object implements the standard two-phase
+ # commit protocol.
+
if not myhasattr(obj, "_p_jar"):
# A resource manager like TransactionalUndo that doesn't
# manage individual objects. It doesn't need to be
# adapted.
- self.join(obj)
- return
+ obj = DBResourceManagerAdapter(obj)
adapter = self._adapters.get(obj._p_jar)
if adapter is None:
if myhasattr(obj._p_jar, "commit_sub"):
@@ -400,6 +408,12 @@
def abort_sub(self, txn):
self.manager.abort_sub(txn)
+
+class DBResourceManagerAdapter:
+ """Make a ZODB.DB.ResourceManager instance look like an object."""
+
+ def __init__(self, jar):
+ self._p_jar = jar
def rm_cmp(rm1, rm2):
return cmp(rm1.sortKey(), rm2.sortKey())
More information about the Zope3-Checkins
mailing list