[Zope3-checkins] CVS: Zope3/src/transaction -
_transaction.py:1.1.2.23
Jeremy Hylton
jeremy at zope.com
Tue Mar 23 15:49:03 EST 2004
Update of /cvs-repository/Zope3/src/transaction
In directory cvs.zope.org:/tmp/cvs-serv4616/transaction
Modified Files:
Tag: jeremy-txn-branch
_transaction.py
Log Message:
Add explicit adapters for ZODB.DB.ResourceManagers.
=== Zope3/src/transaction/_transaction.py 1.1.2.22 => 1.1.2.23 ===
--- Zope3/src/transaction/_transaction.py:1.1.2.22 Mon Mar 22 17:29:34 2004
+++ Zope3/src/transaction/_transaction.py Tue Mar 23 15:49:02 2004
@@ -151,10 +151,11 @@
# 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.
- obj = DBResourceManagerAdapter(obj)
+ if myhasattr(obj, "commit_sub"):
+ self.join(NoObjectAdapterSub(obj))
+ else:
+ self.join(NoObjectAdapter(obj))
+ return
adapter = self._adapters.get(obj._p_jar)
if adapter is None:
if myhasattr(obj._p_jar, "commit_sub"):
@@ -280,7 +281,7 @@
# XXX I think _sub and _nonsub are disjoint, and that
# XXX _resources is empty. If so, we can simplify this code.
assert len(d) == len(self._sub) + len(self._nonsub)
- assert not self._resources
+ assert not self._resources, (self._resources, self._sub, self._nonsub)
for rm in self._resources:
d[id(rm)] = rm
L = d.values()
@@ -342,19 +343,9 @@
# XXX We need a better name for the adapters.
-class MultiObjectResourceAdapter(object):
- """Adapt the old-style register() call to the new-style join().
-
- With join(), a resource mananger like a Connection registers with
- the transaction manager. With register(), an individual object
- is passed to register().
- """
+class BasicResourceAdapter(object):
- def __init__(self, obj):
- self.manager = obj._p_jar
- self.objects = [obj]
- self.ncommitted = 0
- self.voted = False
+ # subclass must define an __init__ that binds self.manager
def __repr__(self):
return "<%s for %s at %s>" % (self.__class__.__name__,
@@ -366,22 +357,35 @@
def tpc_begin(self, txn, sub=False):
self.manager.tpc_begin(txn, sub)
+ def tpc_finish(self, txn):
+ self.manager.tpc_finish(txn)
+
+ def tpc_abort(self, txn):
+ self.manager.tpc_abort(txn)
+
+
+class MultiObjectResourceAdapter(BasicResourceAdapter):
+ """Adapt the old-style register() call to the new-style join().
+
+ With join(), a resource mananger like a Connection registers with
+ the transaction manager. With register(), an individual object
+ is passed to register().
+ """
+
+ def __init__(self, obj):
+ self.manager = obj._p_jar
+ self.objects = [obj]
+ self.ncommitted = 0
+
def tpc_vote(self, txn):
for o in self.objects:
self.manager.commit(o, txn)
self.ncommitted += 1
self.manager.tpc_vote(txn)
- self.voted = True
def cleanup(self, txn):
self._abort(self.objects[self.ncommitted:], txn)
- def tpc_finish(self, txn):
- self.manager.tpc_finish(txn)
-
- def tpc_abort(self, txn):
- self.manager.tpc_abort(txn)
-
def abort(self, txn):
self._abort(self.objects, txn)
@@ -409,11 +413,29 @@
def abort_sub(self, txn):
self.manager.abort_sub(txn)
-class DBResourceManagerAdapter:
- """Make a ZODB.DB.ResourceManager instance look like an object."""
+class NoObjectAdapter(BasicResourceAdapter):
+ """Adapter a resource manager that doesn't have any objects."""
- def __init__(self, jar):
- self._p_jar = jar
+ def __init__(self, manager):
+ self.manager = manager
+
+ def abort(self, txn):
+ # Under the old register() interface, a Connection would
+ # register itself and special-case calls like abort() to
+ # handle the Connection being passed back.
+ self.manager.abort(self.manager, txn)
+
+ def tpc_vote(self, txn):
+ self.manager.commit(self.manager, txn)
+ self.manager.tpc_vote(txn)
+
+class NoObjectAdapterSub(NoObjectAdapter):
+
+ def commit_sub(self, txn):
+ self.manager.commit_sub(txn)
+
+ def abort_sub(self, txn):
+ self.manager.abort_sub(txn)
def rm_cmp(rm1, rm2):
return cmp(rm1.sortKey(), rm2.sortKey())
More information about the Zope3-Checkins
mailing list