[Zodb-checkins] SVN: ZODB/branches/pycon-multidb/src/ZODB/ Start adding interfaces, and a bit of implementation.

Tim Peters tim.one at comcast.net
Sat Mar 19 15:50:37 EST 2005


Log message for revision 29580:
  Start adding interfaces, and a bit of implementation.
  

Changed:
  U   ZODB/branches/pycon-multidb/src/ZODB/Connection.py
  U   ZODB/branches/pycon-multidb/src/ZODB/DB.py
  U   ZODB/branches/pycon-multidb/src/ZODB/interfaces.py

-=-
Modified: ZODB/branches/pycon-multidb/src/ZODB/Connection.py
===================================================================
--- ZODB/branches/pycon-multidb/src/ZODB/Connection.py	2005-03-19 20:21:10 UTC (rev 29579)
+++ ZODB/branches/pycon-multidb/src/ZODB/Connection.py	2005-03-19 20:50:37 UTC (rev 29580)
@@ -220,7 +220,7 @@
         # from a single transaction should be applied atomically, so
         # the lock must be held when reading _invalidated.
 
-        # It sucks that we have to hold the lock to read _invalidated. 
+        # It sucks that we have to hold the lock to read _invalidated.
         # Normally, _invalidated is written by calling dict.update, which
         # will execute atomically by virtue of the GIL.  But some storage
         # might generate oids where hash or compare invokes Python code.  In
@@ -253,6 +253,13 @@
         # to pass to _importDuringCommit().
         self._import = None
 
+        self.connections = None
+
+    def get_connection(self, database_name):
+        """Return a Connection for the named database."""
+        # XXX implement this
+        return
+
     def getTransaction(self):
         """Get the current transaction for this connection.
 

Modified: ZODB/branches/pycon-multidb/src/ZODB/DB.py
===================================================================
--- ZODB/branches/pycon-multidb/src/ZODB/DB.py	2005-03-19 20:21:10 UTC (rev 29579)
+++ ZODB/branches/pycon-multidb/src/ZODB/DB.py	2005-03-19 20:50:37 UTC (rev 29580)
@@ -27,6 +27,9 @@
 from ZODB.utils import WeakSet
 from ZODB.utils import DEPRECATED_ARGUMENT, deprecated36
 
+from zope.interface import implements
+from ZODB.interfaces import IDatabase
+
 import transaction
 
 logger = logging.getLogger('ZODB.DB')
@@ -178,6 +181,7 @@
         setCacheDeactivateAfter,
         getVersionCacheDeactivateAfter, setVersionCacheDeactivateAfter
     """
+    implements(IDatabase)
 
     klass = Connection  # Class to use for connections
     _activity_monitor = None
@@ -188,6 +192,8 @@
                  cache_deactivate_after=DEPRECATED_ARGUMENT,
                  version_pool_size=3,
                  version_cache_size=100,
+                 database_name='unnamed',
+                 databases=None,
                  version_cache_deactivate_after=DEPRECATED_ARGUMENT,
                  ):
         """Create an object database.
@@ -248,6 +254,16 @@
             storage.tpc_vote(t)
             storage.tpc_finish(t)
 
+        # Multi-database setup.
+        if databases is None:
+            databases = {}
+        self.databases = databases
+        self.database_name = database_name
+        if database_name in databases:
+            raise ValueError("database_name %r already in databases" %
+                             database_name)
+        databases[database_name] = self
+
         # Pass through methods:
         for m in ['history', 'supportsUndo', 'supportsVersions', 'undoLog',
                   'versionEmpty', 'versions']:

Modified: ZODB/branches/pycon-multidb/src/ZODB/interfaces.py
===================================================================
--- ZODB/branches/pycon-multidb/src/ZODB/interfaces.py	2005-03-19 20:21:10 UTC (rev 29579)
+++ ZODB/branches/pycon-multidb/src/ZODB/interfaces.py	2005-03-19 20:50:37 UTC (rev 29580)
@@ -16,14 +16,15 @@
 $Id$
 """
 
-import zope.interface
+from zope.interface import Interface, Attribute
 
-class IConnection(zope.interface.Interface):
+class IConnection(Interface):
     """ZODB connection.
 
     TODO: This interface is incomplete.
     """
 
+
     def add(ob):
         """Add a new object 'obj' to the database and assign it an oid.
 
@@ -39,3 +40,77 @@
         must implement the IPersistent interface and must not
         already be associated with a Connection.
         """
+
+    # Multi-database support.
+
+    connections = Attribute("""\
+        A mapping from database name to a Connection to that database.
+
+        In multi-database use, the Connections of all members of a database
+        collection share the same .connections object.
+
+        In single-database use, of course this mapping contains a single
+        entry.
+        """)
+
+    # TODO:  should this accept all the arguments one may pass to DB.open()?
+    def get_connection(database_name):
+        """Return a Connection for the named database.
+
+        This is intended to be called from an open Connection associated with
+        a multi-database.  In that case, database_name must be the name of a
+        database within the database collection (probably the name of a
+        different database than is associated with the calling Connection
+        instance, but it's fine to use the name of the calling Connection
+        object's database).  A Connection for the named database is
+        returned.  If no connection to that database is already open, a new
+        Connection is opened.  So long as the multi-database remains open,
+        passing the same name to get_connection() multiple times returns the
+        same Connection object each time.
+        """
+
+class IDatabase(Interface):
+    """ZODB DB.
+
+    TODO: This interface is incomplete.
+    """
+
+    def __init__(storage,
+                 pool_size=7,
+                 cache_size=400,
+                 version_pool_size=3,
+                 version_cache_size=100,
+                 database_name='unnamed',
+                 databases=None,
+                 ):
+        """Create an object database.
+
+        storage: the storage used by the database, e.g. FileStorage
+        pool_size: expected maximum number of open connections
+        cache_size: target size of Connection object cache, in number of
+            objects
+        version_pool_size: expected maximum number of connections (per
+            version)
+        version_cache_size: target size of Connection object cache for
+             version connections, in number of objects
+        database_name: when using a multi-database, the name of this DB
+            within the database group.  It's a (detected) error if databases
+            is specified too and database_name is already a key in it.
+            This becomes the value of the DB's database_name attribute.
+        databases: when using a multi-database, a mapping to use as the
+            binding of this DB's .databases attribute.  It's intended
+            that the second and following DB's added to a multi-database
+            pass the .databases attribute set on the first DB added to the
+            collection.
+        """
+
+    databases = Attribute("""\
+        A mapping from database name to DB (database) object.
+
+        In multi-database use, all DB members of a database collection share
+        the same .databases object.
+
+        In single-database use, of course this mapping contains a single
+        entry.
+        """)
+



More information about the Zodb-checkins mailing list