[Zope3-checkins] CVS: Zope3/src/ZODB - Connection.py:1.151 POSException.py:1.24

Tim Peters tim.one at comcast.net
Fri Apr 16 15:07:35 EDT 2004


Update of /cvs-repository/Zope3/src/ZODB
In directory cvs.zope.org:/tmp/cvs-serv16416/src/ZODB

Modified Files:
	Connection.py POSException.py 
Log Message:
Introduced new exception ConnectionStateError, as a subclass of POSError,
raised when an operation on a Connection can't be performed because the
Connection is in "a wrong state".

Connection.close() now raises this exception if the connection is
currently joined to a transaction (most obviously, if the transaction
the connection is joined to has modified objects waiting for commit
or abort).

Also changed other appropriate instances of RuntimeError to raise
ConnectionStateError instead (e.g., trying to load an object from a
closed connection).


=== Zope3/src/ZODB/Connection.py 1.150 => 1.151 ===
--- Zope3/src/ZODB/Connection.py:1.150	Fri Apr 16 10:19:11 2004
+++ Zope3/src/ZODB/Connection.py	Fri Apr 16 15:07:00 2004
@@ -31,7 +31,8 @@
 from ZODB.ConflictResolution import ResolvedSerial
 from ZODB.ExportImport import ExportImport
 from ZODB.POSException \
-     import ConflictError, ReadConflictError, InvalidObjectReference
+     import ConflictError, ReadConflictError, InvalidObjectReference, \
+            ConnectionStateError
 from ZODB.TmpStore import TmpStore
 from ZODB.utils import oid_repr, z64, positive_id
 from ZODB.serialize import ObjectWriter, ConnectionObjectReader, myhasattr
@@ -316,11 +317,11 @@
             object does not exist as of the current transaction, but
             existed in the past.  It may even exist again in the
             future, if the transaction that removed it is undone.
-          - `RuntimeError`:  if the connection is closed.
+          - `ConnectionStateError`:  if the connection is closed.
         """
         if self._storage is None:
             # XXX Should this be a ZODB-specific exception?
-            raise RuntimeError("The database connection is closed")
+            raise ConnectionStateError("The database connection is closed")
 
         obj = self._cache.get(oid, None)
         if obj is not None:
@@ -365,11 +366,10 @@
           - `TypeError`: if obj is not a persistent object.
           - `InvalidObjectReference`: if obj is already associated
             with another connection.
-          - `RuntimeError`: if the connection is closed.
+          - `ConnectionStateError`: if the connection is closed.
         """
         if self._storage is None:
-            # XXX Should this be a ZODB-specific exception?
-            raise RuntimeError("The database connection is closed")
+            raise ConnectionStateError("The database connection is closed")
 
         marker = object()
         oid = getattr(obj, "_p_oid", marker)
@@ -532,6 +532,12 @@
         onCloseCallback() are invoked and the cache is scanned for
         old objects.
         """
+
+        if not self._needs_to_join:
+            # We're currently joined to a transaction.
+            raise ConnectionStateError("Cannot close a connection joined to "
+                                       "a transaction")
+
         if self._cache is not None:
             self._cache.incrgc() # This is a good time to do some GC
 
@@ -671,14 +677,12 @@
 
     def getVersion(self):
         if self._storage is None:
-            # XXX Should this be a ZODB-specific exception?
-            raise RuntimeError("The database connection is closed")
+            raise ConnectionStateError("The database connection is closed")
         return self._version
 
     def isReadOnly(self):
         if self._storage is None:
-            # XXX Should this be a ZODB-specific exception?
-            raise RuntimeError("The database connection is closed")
+            raise ConnectionStateError("The database connection is closed")
         return self._storage.isReadOnly()
 
     def invalidate(self, tid, oids):
@@ -776,7 +780,7 @@
             msg = ("Shouldn't load state for %s "
                    "when the connection is closed" % oid_repr(oid))
             self._log.error(msg)
-            raise RuntimeError(msg)
+            raise ConnectionStateError(msg)
 
         try:
             self._setstate(obj)


=== Zope3/src/ZODB/POSException.py 1.23 => 1.24 ===
--- Zope3/src/ZODB/POSException.py:1.23	Thu Feb 26 19:31:53 2004
+++ Zope3/src/ZODB/POSException.py	Fri Apr 16 15:07:00 2004
@@ -268,7 +268,7 @@
     """An export file doesn't have the right format."""
 
 class Unsupported(POSError):
-    """An feature that is unsupported bt the storage was used."""
+    """A feature was used that is not supported by the storage."""
 
 class InvalidObjectReference(POSError):
     """An object contains an invalid reference to another object.
@@ -280,4 +280,14 @@
     o A reference to an object in a different database connection.
 
     XXX The exception ought to have a member that is the invalid object.
+    """
+
+class ConnectionStateError(POSError):
+    """A Connection isn't in the required state for an operation.
+
+    o An operation such as a load is attempted on a closed connection.
+
+    o An attempt to close a connection is made while the connection is
+      still joined to a transaction (for example, a transaction is in
+      progress, with uncommitted modifications in the connection).
     """




More information about the Zope3-Checkins mailing list