[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/DB.py Refactored to release references to the storage on close.

Jim Fulton jim at zope.com
Thu Jul 15 07:14:34 EDT 2010


Log message for revision 114766:
  Refactored to release references to the storage on close.
  

Changed:
  U   ZODB/trunk/src/ZODB/DB.py

-=-
Modified: ZODB/trunk/src/ZODB/DB.py
===================================================================
--- ZODB/trunk/src/ZODB/DB.py	2010-07-15 10:07:47 UTC (rev 114765)
+++ ZODB/trunk/src/ZODB/DB.py	2010-07-15 11:14:34 UTC (rev 114766)
@@ -483,30 +483,10 @@
         databases[database_name] = self
         self.xrefs = xrefs
 
-        self._setupUndoMethods()
-        self.history = storage.history
-
         self._saved_oids = []
         self._max_saved_oids = max_saved_oids
         self.large_record_size = large_record_size
 
-    def _setupUndoMethods(self):
-        storage = self.storage
-        try:
-            self.supportsUndo = storage.supportsUndo
-        except AttributeError:
-            self.supportsUndo = lambda : False
-
-        if self.supportsUndo():
-            self.undoLog = storage.undoLog
-            if hasattr(storage, 'undoInfo'):
-                self.undoInfo = storage.undoInfo
-        else:
-            self.undoLog = self.undoInfo = lambda *a,**k: ()
-            def undo(*a, **k):
-                raise NotImplementedError
-            self.undo = undo
-
     @property
     def _storage(self):      # Backward compatibility
         return self.storage
@@ -654,7 +634,17 @@
         is closed, so they stop behaving usefully.  Perhaps close()
         should also close all the Connections.
         """
+        noop = lambda *a: None
+        self.close = noop
+
+        @self._connectionMap
+        def _(c):
+            c.transaction_manager.abort()
+            c.afterCompletion = c.newTransaction = c.close = noop
+            c._storage = c._normal_storage = None
+
         self.storage.close()
+        del self.storage
 
     def getCacheSize(self):
         return self._cache_size
@@ -908,6 +898,26 @@
         finally:
             self._r()
 
+    def history(self, *args, **kw):
+        return self.storage.history(*args, **kw)
+
+    def supportsUndo(self):
+        try:
+            f = self.storage.supportsUndo
+        except AttributeError:
+            return False
+        return f()
+
+    def undoLog(self, *args, **kw):
+        if not self.supportsUndo():
+            return ()
+        return self.storage.undoLog(*args, **kw)
+
+    def undoInfo(self, *args, **kw):
+        if not self.supportsUndo():
+            return ()
+        return self.storage.undoInfo(*args, **kw)
+
     def undoMultiple(self, ids, txn=None):
         """Undo multiple transactions identified by ids.
 
@@ -925,6 +935,8 @@
           - `txn`: transaction context to use for undo().
             By default, uses the current transaction.
         """
+        if not self.supportsUndo():
+            raise NotImplementedError
         if txn is None:
             txn = transaction.get()
         if isinstance(ids, basestring):



More information about the Zodb-checkins mailing list