[Zodb-checkins] SVN: ZODB/trunk/ Add optional new databases=
argument to the open()
Tim Peters
tim.one at comcast.net
Mon Oct 24 12:14:23 EDT 2005
Log message for revision 39574:
Add optional new databases= argument to the open()
method of ZODBDatabase factories. This gives apps
(like Zopes 2.9 and 3.2) a relatively clean way to
set up their multidatabases. An earlier checkin
adding an optional new database_name key to
<zodb> sections.
Changed:
U ZODB/trunk/NEWS.txt
U ZODB/trunk/src/ZODB/config.py
U ZODB/trunk/src/ZODB/tests/multidb.txt
-=-
Modified: ZODB/trunk/NEWS.txt
===================================================================
--- ZODB/trunk/NEWS.txt 2005-10-24 13:19:16 UTC (rev 39573)
+++ ZODB/trunk/NEWS.txt 2005-10-24 16:14:22 UTC (rev 39574)
@@ -1,11 +1,11 @@
-What's new in ZODB3 3.6a5?
+What's new in ZODB3 3.6b2?
==========================
Release date: DD-MMM-2005
Following is combined news from internal releases (to support ongoing
Zope3 development). These are the dates of the internal releases:
-- 3.6a5 DD-MMM-2005
+- 3.6b1 DD-MMM-2005
- 3.6a4 07-Oct-2005
- 3.6a3 07-Sep-2005
- 3.6a2 06-Sep-2005
@@ -47,6 +47,20 @@
left the commit lock in the acquired state, causing any later attempt
to commit changes hang.
+Multidatabase
+-------------
+
+- (3.6b1) The ``database_name`` for a database in a multidatabase
+ collection can now be specified in a config file's ``<zodb>`` section,
+ as the value of the optional new ``database_name`` key. The
+ ``.databases`` attribute cannot be specified in a config file, but
+ can be passed as the optional new ``databases`` argument to the
+ ``open()`` method of a ZConfig factory for type ``ZODBDatabase``.
+ For backward compatibility, Zope 2.9 continues to allow using the
+ name in its ``<zodb_db name>`` config section as the database name
+ (note that ``<zodb_db>`` is defined by Zope, not by ZODB -- it's a
+ Zope-specific extension of ZODB's ``<zodb>`` section).
+
PersistentMapping
-----------------
Modified: ZODB/trunk/src/ZODB/config.py
===================================================================
--- ZODB/trunk/src/ZODB/config.py 2005-10-24 13:19:16 UTC (rev 39573)
+++ ZODB/trunk/src/ZODB/config.py 2005-10-24 16:14:22 UTC (rev 39574)
@@ -92,7 +92,7 @@
class ZODBDatabase(BaseConfig):
- def open(self):
+ def open(self, databases=None):
section = self.config
storage = section.storage.open()
try:
@@ -101,7 +101,8 @@
cache_size=section.cache_size,
version_pool_size=section.version_pool_size,
version_cache_size=section.version_cache_size,
- database_name=section.database_name)
+ database_name=section.database_name,
+ databases=databases)
except:
storage.close()
raise
Modified: ZODB/trunk/src/ZODB/tests/multidb.txt
===================================================================
--- ZODB/trunk/src/ZODB/tests/multidb.txt 2005-10-24 13:19:16 UTC (rev 39573)
+++ ZODB/trunk/src/ZODB/tests/multidb.txt 2005-10-24 16:14:22 UTC (rev 39574)
@@ -152,6 +152,9 @@
>>> for a_db in dbmap.values():
... a_db.close()
+Configuration from File
+-----------------------
+
The database name can also be specified in a config file, starting in
ZODB 3.6:
@@ -168,5 +171,38 @@
>>> db.databases.keys()
['this_is_the_name']
+However, the .databases attribute cannot be configured from file. It
+can be passed to the ZConfig factory. I'm not sure of the clearest way
+to test that here; this is ugly:
+
+ >>> from ZODB.config import getDbSchema
+ >>> import ZConfig
+ >>> from cStringIO import StringIO
+
+Derive a new `config2` string from the `config` string, specifying a
+different database_name:
+
+ >>> config2 = config.replace("this_is_the_name", "another_name")
+
+Now get a ZConfig factory from `config2`:
+
+ >>> f = StringIO(config2)
+ >>> zconfig, handle = ZConfig.loadConfigFile(getDbSchema(), f)
+ >>> factory = zconfig.database
+
+The desired `databases` mapping can be passed to this factory:
+
+ >>> db2 = factory.open(databases=db.databases)
+ >>> print db2.database_name # has the right name
+ another_name
+ >>> db.databases is db2.databases # shares .databases with `db`
+ True
+ >>> all = db2.databases.keys()
+ >>> all.sort()
+ >>> all # and db.database_name & db2.database_name are the keys
+ ['another_name', 'this_is_the_name']
+
+Cleanup.
+
>>> db.close()
-
+ >>> db2.close()
More information about the Zodb-checkins
mailing list