[Checkins] SVN: ZODB/branches/jinty-doom/src/transaction/ Add the ability to ask a transaction if it has been doomed i.e. isDoomed().

Brian Sutherland jinty at web.de
Fri Sep 8 07:24:46 EDT 2006


Log message for revision 70051:
  Add the ability to ask a transaction if it has been doomed i.e. isDoomed().

Changed:
  U   ZODB/branches/jinty-doom/src/transaction/__init__.py
  U   ZODB/branches/jinty-doom/src/transaction/_manager.py
  U   ZODB/branches/jinty-doom/src/transaction/_transaction.py
  U   ZODB/branches/jinty-doom/src/transaction/interfaces.py
  U   ZODB/branches/jinty-doom/src/transaction/tests/doom.txt

-=-
Modified: ZODB/branches/jinty-doom/src/transaction/__init__.py
===================================================================
--- ZODB/branches/jinty-doom/src/transaction/__init__.py	2006-09-08 11:13:06 UTC (rev 70050)
+++ ZODB/branches/jinty-doom/src/transaction/__init__.py	2006-09-08 11:24:45 UTC (rev 70051)
@@ -25,4 +25,5 @@
 commit = manager.commit
 abort = manager.abort
 doom = manager.doom
+isDoomed = manager.isDoomed
 savepoint = manager.savepoint

Modified: ZODB/branches/jinty-doom/src/transaction/_manager.py
===================================================================
--- ZODB/branches/jinty-doom/src/transaction/_manager.py	2006-09-08 11:13:06 UTC (rev 70050)
+++ ZODB/branches/jinty-doom/src/transaction/_manager.py	2006-09-08 11:24:45 UTC (rev 70051)
@@ -85,6 +85,9 @@
     def unregisterSynch(self, synch):
         self._synchs.remove(synch)
 
+    def isDoomed(self):
+        return self.get().isDoomed()
+
     def doom(self):
         return self.get().doom()
 

Modified: ZODB/branches/jinty-doom/src/transaction/_transaction.py
===================================================================
--- ZODB/branches/jinty-doom/src/transaction/_transaction.py	2006-09-08 11:13:06 UTC (rev 70050)
+++ ZODB/branches/jinty-doom/src/transaction/_transaction.py	2006-09-08 11:24:45 UTC (rev 70051)
@@ -260,6 +260,9 @@
         # List of (hook, args, kws) tuples added by addAfterCommitHook().
         self._after_commit = []
 
+    def isDoomed(self):
+        return self.status is Status.DOOMED
+
     def doom(self):
         if self.status is not Status.DOOMED:
             if self.status is not Status.ACTIVE:

Modified: ZODB/branches/jinty-doom/src/transaction/interfaces.py
===================================================================
--- ZODB/branches/jinty-doom/src/transaction/interfaces.py	2006-09-08 11:13:06 UTC (rev 70050)
+++ ZODB/branches/jinty-doom/src/transaction/interfaces.py	2006-09-08 11:24:45 UTC (rev 70051)
@@ -49,6 +49,10 @@
         """Doom the current transaction.
         """
 
+    def isDoomed():
+        """Returns True if the current transaction is doomed, otherwise False.
+        """
+
     def savepoint(optimistic=False):
         """Create a savepoint from the current transaction.
 

Modified: ZODB/branches/jinty-doom/src/transaction/tests/doom.txt
===================================================================
--- ZODB/branches/jinty-doom/src/transaction/tests/doom.txt	2006-09-08 11:13:06 UTC (rev 70050)
+++ ZODB/branches/jinty-doom/src/transaction/tests/doom.txt	2006-09-08 11:24:45 UTC (rev 70051)
@@ -50,9 +50,20 @@
     >>> dm = DataManager()
     >>> txn.join(dm)
 
+We can ask a transaction if it is doomed to avoid expensive operations. An
+example of a use case is an object-relational mapper where a pre-commit hook
+sends all outstanding SQL to a relational database for objects changed during
+the transaction. This expensive operation is not necessary if the transaction
+has been doomed. A non-doomed transaction should return False:
+
+    >>> txn.isDoomed()
+    False
+
 We can doom a transaction by calling .doom() on it:
 
     >>> txn.doom()
+    >>> txn.isDoomed()
+    True
 
 We can doom it again if we like:
 
@@ -95,7 +106,11 @@
 module. We can also begin a new transaction directly after dooming the old one:
 
     >>> txn = transaction.begin()
+    >>> transaction.isDoomed()
+    False
     >>> transaction.doom()
+    >>> transaction.isDoomed()
+    True
     >>> txn = transaction.begin()
 
 After committing a transaction we get an assertion error if we try to doom the



More information about the Checkins mailing list