[Zope-Checkins] SVN: Zope/trunk/lib/python/ Reverted changes in rev r24514 that broke mount points.

Jim Fulton jim at zope.com
Wed Jun 2 18:44:37 EDT 2004


Log message for revision 25206:
Reverted changes in rev r24514 that broke mount points.

Made a small fix to _setDB in Mount.py to pass 
through new args passed to it.

With these changes, Zope now runs again.




-=-
Modified: Zope/trunk/lib/python/DBTab/ClassFactories.py
===================================================================
--- Zope/trunk/lib/python/DBTab/ClassFactories.py	2004-06-02 21:34:36 UTC (rev 25205)
+++ Zope/trunk/lib/python/DBTab/ClassFactories.py	2004-06-02 22:44:36 UTC (rev 25206)
@@ -75,16 +75,12 @@
     """
     # If not the root connection, use the class factory from
     # the root database, otherwise use the Zope class factory.
-
-    # The default Zope configuration installs this function as the DB
-    # class's classFactory() method.
-    
     root_conn = getattr(jar, '_root_connection', None)
-    if root_conn is not jar:
-        root_db = getattr(root_conn, '_db', None)
-        if root_db is not None:
-            return root_db.classFactory(root_conn, module, name)
-    return zopeClassFactory(jar, module, name)
+    root_db = getattr(root_conn, '_db', None)
+    if root_db is not None:
+        return root_db.classFactory(root_conn, module, name)
+    else:
+        return zopeClassFactory(jar, module, name)
 
 class_factories['auto'] = autoClassFactory
 


Property changes on: Zope/trunk/lib/python/DBTab/ClassFactories.py
___________________________________________________________________
Name: cvs2svn:cvs-rev
   - 1.3
   + 1.2

Modified: Zope/trunk/lib/python/OFS/Application.py
===================================================================
--- Zope/trunk/lib/python/OFS/Application.py	2004-06-02 21:34:36 UTC (rev 25205)
+++ Zope/trunk/lib/python/OFS/Application.py	2004-06-02 22:44:36 UTC (rev 25206)
@@ -14,6 +14,7 @@
 
 $Id$
 """
+
 import Globals,Folder,os,sys,App.Product, App.ProductRegistry, misc_
 import time, traceback, os,  Products
 from DateTime import DateTime
@@ -323,10 +324,10 @@
 
     def install_tempfolder_and_sdc(self):
         app = self.getApp()
-        from Products.ZODBMountPoint.MountedObject \
-             import manage_addMounts, MountedObject
-        from Products.ZODBMountPoint.MountedObject \
-             import getConfiguration as getDBTabConfiguration
+        from Products.ZODBMountPoint.MountedObject import manage_addMounts,\
+             MountedObject
+        from Products.ZODBMountPoint.MountedObject import getConfiguration as \
+             getDBTabConfiguration
 
         dbtab_config = getDBTabConfiguration()
 


Property changes on: Zope/trunk/lib/python/OFS/Application.py
___________________________________________________________________
Name: cvs2svn:cvs-rev
   - 1.202
   + 1.201

Modified: Zope/trunk/lib/python/Products/ZODBMountPoint/Mount.py
===================================================================
--- Zope/trunk/lib/python/Products/ZODBMountPoint/Mount.py	2004-06-02 21:34:36 UTC (rev 25205)
+++ Zope/trunk/lib/python/Products/ZODBMountPoint/Mount.py	2004-06-02 22:44:36 UTC (rev 25206)
@@ -28,17 +28,14 @@
 from Acquisition import aq_base
 from ZODB.POSException import MountedStorageError
 
-from ZODB.DB import DB
-from ZODB.Connection import Connection
 
 LOG = getLogger('Zope.ZODBMountPoint')
 
 class MountPoint(Persistence.Persistent, Acquisition.Implicit):
-    """An object that accesses a different database when traversed.
+    '''The base class for a Zope object which, when traversed,
+    accesses a different database.
+    '''
 
-    This class is intended to be used as a base class.
-    """
-
     # Default values for non-persistent variables.
     _v_data = None   # An object in an open connection
     _v_connect_error = None
@@ -47,19 +44,23 @@
         self.id = id
 
     def _getDB(self):
-        """Hook for getting the DB object for this mount point."""
+        """Hook for getting the DB object for this mount point.
+        """
         raise NotImplementedError
 
     def _getDBName(self):
-        """Hook for getting the name of the database for this mount point."""
+        """Hook for getting the name of the database for this mount point.
+        """
         raise NotImplementedError
 
     def _getRootDBName(self):
-        """Hook for getting the name of the root database."""
+        """Hook for getting the name of the root database.
+        """
         raise NotImplementedError
 
     def _traverseToMountedRoot(self, root, mount_parent):
-        """Hook for getting the object to be mounted."""
+        """Hook for getting the object to be mounted.
+        """
         raise NotImplementedError
 
     def __repr__(self):
@@ -122,13 +123,20 @@
 
 
     def _test(self, parent):
-        """Tests the database connection."""
+        '''Tests the database connection.
+        '''
         self._getOrOpenObject(parent)
         return 1
 
 
     def _logConnectException(self):
-        """Records info about the exception that just occurred."""
+        '''Records info about the exception that just occurred.
+        '''
+        try:
+            from cStringIO import StringIO
+        except:
+            from StringIO import StringIO
+        import traceback
         exc = sys.exc_info()
         LOG.error('Failed to mount database. %s (%s)' % exc[:2], exc_info=exc)
         f=StringIO()
@@ -136,73 +144,85 @@
         self._v_connect_error = (exc[0], exc[1], f.getvalue())
         exc = None
 
-class MountConnection(Connection):
-    """Subclass of Connection that supports mounts."""
 
-    # XXX perhaps the code in this subclass should be folded into
-    # ZODB proper.
 
-    def __init__(self, **kwargs):
-        Connection.__init__(self, **kwargs)
-        # The _root_connection of the actual root points to self.  All
-        # other connections will have _root_connection over-ridden in
-        # _addMountedConnection().
-        self._root_connection = self
-        self._mounted_connections = {}
-        
+class ConnectionPatches:
+    # Changes to Connection.py that might fold into ZODB
+
+    _root_connection = None
+    _mounted_connections = None
+
     def _getRootConnection(self):
-        return self._root_connection
+        root_conn = self._root_connection
+        if root_conn is None:
+            return self
+        else:
+            return root_conn
 
     def _getMountedConnection(self, name):
-        return self._root_connection._mounted_connections.get(name)
+        conns = self._getRootConnection()._mounted_connections
+        if conns is None:
+            return None
+        else:
+            return conns.get(name)
 
     def _addMountedConnection(self, name, conn):
-        if conn._root_connection is not conn:
-            raise ValueError("Connection %s is already mounted" % repr(conn))
-        conns = self._root_connection._mounted_connections
-        if name in conns:
-            raise KeyError("A connection named %s already exists" % repr(name))
-        conn._root_connection = self._root_connection
+        if conn._root_connection is not None:
+            raise ValueError, 'Connection %s is already mounted' % repr(conn)
+        root_conn = self._getRootConnection()
+        conns = root_conn._mounted_connections
+        if conns is None:
+            conns = {}
+            root_conn._mounted_connections = conns
+        if conns.has_key(name):
+            raise KeyError, 'A connection named %s already exists' % repr(name)
+        conn._root_connection = root_conn
         conns[name] = conn
 
-    def _setDB(self, odb, **kwargs):
-        Connection._setDB(self, odb, **kwargs)
-        for conn in self._mounted_connections.values():
-            conn._setDB(odb, **kwargs)
+    def _setDB(self, odb, *args, **kw):
+        self._real_setDB(odb, *args, **kw)
+        conns = self._mounted_connections
+        if conns:
+            for conn in conns.values():
+                conn._setDB(conn._db, *args, **kw)
 
     def close(self):
-        if self._root_connection is not self:
+        if self._root_connection is not None:
             raise RuntimeError("Should not close mounted connections directly")
-
-        # The code here duplicates much of the code in
-        # DB._closeConnection and Connection.close.  A mounted
-        # connection can't operate independently, so we don't call
-        # DB._closeConnection(), which would return it to the
-        # connection pool; only the root connection should be
-        # returned.
-        
-        for conn in self._mounted_connections.values():
-            # DB._closeConnection calls the activity monitor
-            am = conn._db.getActivityMonitor()
-            am.closedConnection(conn)
-            # Connection.close does GC
-            conn._cache.incrgc()
-            conn._storage = conn._tmp = conn.new_oid = conn._opened = None
-            conn._debug_info = ()
-            # The mounted connection keeps a reference to
-            # its database, but nothing else.
-            
+        conns = self._mounted_connections
+        if conns:
+            for conn in conns.values():
+                # Notify the activity monitor
+                db = conn.db()
+                f = getattr(db, 'getActivityMonitor', None)
+                if f is not None:
+                    am = f()
+                    if am is not None:
+                        am.closedConnection(conn)
+                conn.cacheGC() # This is a good time to do some GC
+                # XXX maybe we ought to call the close callbacks.
+                conn._storage = conn._tmp = conn.new_oid = conn._opened = None
+                conn._debug_info = ()
+                # The mounted connection keeps a reference to
+                # its database, but nothing else.
+                # Note that mounted connections can not operate
+                # independently, so don't use _closeConnection() to
+                # return them to the pool.  Only the root connection
+                # should be returned.
         # Close this connection only after the mounted connections
         # have been closed.  Otherwise, this connection gets returned
         # to the pool too early and another thread might use this
         # connection before the mounted connections have all been
         # closed.
-        Connection.close(self)
+        self._real_close()
 
-# Replace the default database Connection
-def install():
-    DB.klass = MountConnection
-    
-# XXX This shouldn't be done as a side-effect of import, but it's not
-# clear where in the Zope initialization code it should be done.
-install()
+if 1:
+    # patch Connection.py.
+    from ZODB.Connection import Connection
+    Connection._real_setDB = Connection._setDB
+    Connection._real_close = Connection.close
+
+    for k, v in ConnectionPatches.__dict__.items():
+        if not k.startswith('__'):
+            setattr(Connection, k, v)
+


Property changes on: Zope/trunk/lib/python/Products/ZODBMountPoint/Mount.py
___________________________________________________________________
Name: cvs2svn:cvs-rev
   - 1.5
   + 1.3

Modified: Zope/trunk/lib/python/Products/ZODBMountPoint/tests/testMountPoint.py
===================================================================
--- Zope/trunk/lib/python/Products/ZODBMountPoint/tests/testMountPoint.py	2004-06-02 21:34:36 UTC (rev 25205)
+++ Zope/trunk/lib/python/Products/ZODBMountPoint/tests/testMountPoint.py	2004-06-02 22:44:36 UTC (rev 25206)
@@ -22,9 +22,7 @@
 from OFS.Application import Application
 from OFS.Folder import Folder
 import App.config
-from Products.ZODBMountPoint.MountedObject \
-     import manage_addMounts, getMountPoint
-from Products.ZODBMountPoint.Mount import MountConnection
+from Products.ZODBMountPoint.MountedObject import manage_addMounts, getMountPoint
 from DBTab.DBTab import DBTab
 
 try:
@@ -38,7 +36,7 @@
         self.mpoints = mpoints
         
     def getDB(self):
-        from ZODB.config import MappingStorage
+        from ZODB.config import DemoStorage
         from ZODB.Connection import Connection
         from Zope.Startup.datatypes import ZopeDatabase
         self.name = self.fname
@@ -52,9 +50,9 @@
         self.version_pool_size = 3
         self.version_cache_size = 100
         self.mount_points = self.mpoints
-        self.connection_class = MountConnection
+        self.connection_class = Connection
         self.class_factory = None
-        self.storage = MappingStorage(self)
+        self.storage = DemoStorage(self)
         self.container_class = None
         return ZopeDatabase(self)
 


Property changes on: Zope/trunk/lib/python/Products/ZODBMountPoint/tests/testMountPoint.py
___________________________________________________________________
Name: cvs2svn:cvs-rev
   - 1.4
   + 1.3




More information about the Zope-Checkins mailing list