[Zodb-checkins] CVS: ZODB4/src/transaction - txn.py:1.4

Jeremy Hylton jeremy@zope.com
Thu, 6 Mar 2003 19:18:11 -0500


Update of /cvs-repository/ZODB4/src/transaction
In directory cvs.zope.org:/tmp/cvs-serv3549/transaction

Modified Files:
	txn.py 
Log Message:
Add IllegalStateError calls to prevent assertions from failing.
XXX Should the manager duplicate these checks?


=== ZODB4/src/transaction/txn.py 1.3 => 1.4 ===
--- ZODB4/src/transaction/txn.py:1.3	Wed Mar  5 17:12:38 2003
+++ ZODB4/src/transaction/txn.py	Thu Mar  6 19:18:10 2003
@@ -3,13 +3,20 @@
 
 __metaclass__ = type
 
-from transaction.interfaces import ITransaction, TransactionError
+from transaction.interfaces import *
 from threading import Lock
 
-class Set(dict):
+try:
+    from sets import Set
+except ImportError:
 
-    def add(self, k):
-        self[k] = 1
+    class Set(dict):
+
+        def add(self, k):
+            self[k] = 1
+
+        def remove(self, k):
+            del self[k]
 
 class Status:
 
@@ -50,24 +57,29 @@
     def commit(self):
         """Commit a transaction."""
         assert self._manager is not None
+        if self._status != Status.ACTIVE:
+            raise IllegalStateError("commit", self._status)
         self._manager.commit(self)
 
     def abort(self):
         """Rollback to initial state."""
         assert self._manager is not None
+        if self._status not in (Status.ACTIVE, Status.PREPARED, Status.FAILED):
+            raise IllegalStateError("abort", self._status)
         self._manager.abort(self)
 
     def savepoint(self):
         """Save current progress and return a savepoint."""
         assert self._manager is not None
+        if self._status != Status.ACTIVE:
+            raise IllegalStateError("create savepoint", self._status)
         return self._manager.savepoint(self)
 
     def join(self, resource):
         """resource is participating in the transaction."""
         assert self._manager is not None
         if self._status != Status.ACTIVE:
-            raise TransactionError("Can't join transaction. Status=%s" %
-                                   self._status)
+            raise IllegalStateError("join", self._status)
         self._resources.add(resource)
 
     def status(self):
@@ -78,7 +90,7 @@
         self._lock.acquire()
         try:
             if self._status == Status.SUSPENDED:
-                raise TransactionError("Already suspended")
+                raise IllegalStateError("suspend", self._status)
             self._manager.suspend(self)
             self._suspend = self._status
             self._status = Status.SUSPENDED