[Zope-dev] transaction support for ordering transactions.
Anthony Baxter
anthony@interlink.com.au
Tue, 06 Jun 2000 14:34:28 +1000
As part of making SQLSession transaction-sane, I'd like to be able
to specify that something can register itself to be committed or
aborted earlier in the list of objects rather than just being put on
the end of the list. The reason for this:
I want SQLSession to just use a normal DB connection, and have the
commits &c to "just work". The new code now only does the SQL statements
in SQLSessionObj's _finish() method - unfortunately, by that time, the
database's '_finish()' method has sometimes already been called (if there's
a different database call before the Session object is created, then the
database adaptor will be registered first).
I thought about various ways of dealing with this, such as being able
to say 'register me _before_ that object', but ended up going simply with
a flag to say 'put me on the front of the list, rather than the back.'
This way, anything that needs to say 'no, put me before the standard
ones' can do so.
Thoughts? Alternatives?
Anthony
Patch against current-cvs follows:
--- lib/python/ZODB/Transaction.py 2000/05/30 19:03:27 1.22
+++ lib/python/ZODB/Transaction.py 2000/06/06 04:01:51
@@ -117,6 +117,9 @@
for c in self._connections.values(): c.close()
del self._connections
+ def _prepend(self, object):
+ self._objects = [object] + self._objects
+
def sub(self):
# Create a manually managed subtransaction for internal use
r=self.__class__()
@@ -315,9 +318,12 @@
del objects[:] # clear registered
if not subtransaction and self._id is not None: free_transaction()
- def register(self,object):
+ def register(self,object,early=0):
'Register the given object for transaction control.'
- self._append(object)
+ if early:
+ self._prepend(object)
+ else:
+ self._append(object)
def note(self, text):
if self.description:
--
Anthony Baxter <anthony@interlink.com.au>
It's never too late to have a happy childhood.