Function
zope.app.appsetup.appsetup.multi_database

Signature

multi_database(database_factories)

Documentation String

Set up a multi-database from an iterable of database factories

Return a sequence of databases, and a mapping of from database name to database.

>>> class DB:
...     def __init__(self, number):
...         self.number = number
...     def __repr__(self):
...         return "DB(%s)" % self.number
...     def getActivityMonitor(self):
...         return self._activity_monitor
...     def setActivityMonitor(self, am):
...         self._activity_monitor = am
>>> class Factory:
...     def __init__(self, name, number):
...         self.name = name
...         self.number = number
...     def open(self):
...         return DB(self.number)
>>> s, m = multi_database(
...           [Factory(None, 3), Factory('y', 2), Factory('x', 1)])
>>> list(s)
[DB(3), DB(2), DB(1)]
>>> [d.database_name for d in s]
['', 'y', 'x']
>>> [d.databases is m for d in s]
[True, True, True]
>>> items = m.items()
>>> items.sort()
>>> items
[('', DB(3)), ('x', DB(1)), ('y', DB(2))]

Each of the databases is registered as an IDatabase utility:

>>> from zope import component
>>> [(component.getUtility(ZODB.interfaces.IDatabase, name) is m[name])
...  for name in m]
[True, True, True]

And has an activity monitor:

>>> [isinstance(db.getActivityMonitor(),
...             ZODB.ActivityMonitor.ActivityMonitor)
...  for db in m.values()]
[True, True, True]