[Zope3-checkins] CVS: Zope3/src/transaction -
_transaction.py:1.1.2.26
Jeremy Hylton
jeremy at zope.com
Mon Mar 29 11:39:07 EST 2004
Update of /cvs-repository/Zope3/src/transaction
In directory cvs.zope.org:/tmp/cvs-serv5039
Modified Files:
Tag: jeremy-txn-branch
_transaction.py
Log Message:
Revise the handling of manager-like objects passed to register().
If we don't pass an object to the MultiObjectResourceAdapter
constructor, then we can use this class for any kind of register call,
even for TransactionalUndo objects.
Simplify the adapter lookup logic in register() by using a temporary
"manager" variable that is either obj._p_jar or obj.
=== Zope3/src/transaction/_transaction.py 1.1.2.25 => 1.1.2.26 ===
--- Zope3/src/transaction/_transaction.py:1.1.2.25 Tue Mar 23 16:13:59 2004
+++ Zope3/src/transaction/_transaction.py Mon Mar 29 11:39:05 2004
@@ -154,20 +154,16 @@
# be stored when the transaction commits. For other
# objects, the object implements the standard two-phase
# commit protocol.
-
- if not myhasattr(obj, "_p_jar"):
- if myhasattr(obj, "commit_sub"):
- self.join(NoObjectAdapterSub(obj))
- else:
- self.join(NoObjectAdapter(obj))
- return
- adapter = self._adapters.get(obj._p_jar)
+
+ manager = getattr(obj, "_p_jar", obj)
+ adapter = self._adapters.get(manager)
if adapter is None:
- if myhasattr(obj._p_jar, "commit_sub"):
- adapter = MultiObjectResourceAdapterSub(obj)
+ if myhasattr(manager, "commit_sub"):
+ adapter = MultiObjectResourceAdapterSub(manager)
else:
- adapter = MultiObjectResourceAdapter(obj)
- self._adapters[obj._p_jar] = adapter
+ adapter = MultiObjectResourceAdapter(manager)
+ adapter.objects.append(obj)
+ self._adapters[manager] = adapter
self.join(adapter)
else:
# XXX comment out this expensive assert later
@@ -233,10 +229,12 @@
# to revert the changes in each of the resource managers.
# For top-level transactions, it must be freed from the
# txn manager.
- self._cleanup(L)
- if not subtransaction:
- self.status = Status.FAILED
- self._manager.free(self)
+ try:
+ self._cleanup(L)
+ finally:
+ if not subtransaction:
+ self.status = Status.FAILED
+ self._manager.free(self)
raise
def _cleanup(self, L):
@@ -250,13 +248,11 @@
rm.abort_sub(self)
except Exception, err:
print err
- raise
else:
try:
rm.tpc_abort(self)
except Exception, err:
print err
- raise
def _getResourceManagers(self, subtransaction):
L = []
@@ -377,9 +373,9 @@
is passed to register().
"""
- def __init__(self, obj):
- self.manager = obj._p_jar
- self.objects = [obj]
+ def __init__(self, jar):
+ self.manager = jar
+ self.objects = []
self.ncommitted = 0
def tpc_vote(self, txn):
@@ -418,29 +414,15 @@
def abort_sub(self, txn):
self.manager.abort_sub(txn)
-class NoObjectAdapter(BasicResourceAdapter):
- """Adapter a resource manager that doesn't have any objects."""
-
- 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 tpc_begin(self, txn, sub=False):
+ self.manager.tpc_begin(txn, sub)
+ self.sub = sub
- def abort_sub(self, txn):
- self.manager.abort_sub(txn)
+ def tpc_finish(self, txn):
+ self.manager.tpc_finish(txn)
+ if self.sub:
+ self.objects = []
+
def rm_cmp(rm1, rm2):
return cmp(rm1.sortKey(), rm2.sortKey())
@@ -476,7 +458,7 @@
def __init__(self, datamanager):
self._datamanager = datamanager
self._rollback = None
-
+
# XXX I'm not sure why commit() doesn't do anything
def commit(self, transaction):
More information about the Zope3-Checkins
mailing list