Commit d0207efa authored by Tim Peters's avatar Tim Peters

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.
parent 7c6681f0
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 @@ BaseStorage
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
-----------------
......
......@@ -92,7 +92,7 @@ class BaseConfig:
class ZODBDatabase(BaseConfig):
def open(self):
def open(self, databases=None):
section = self.config
storage = section.storage.open()
try:
......@@ -101,7 +101,8 @@ class ZODBDatabase(BaseConfig):
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
......
......@@ -152,6 +152,9 @@ Clean up:
>>> 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 @@ ZODB 3.6:
>>> db.databases.keys()
['this_is_the_name']
>>> db.close()
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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment