[Zope-Checkins] CVS: Zope/lib/python/Zope/Startup - datatypes.py:1.7 zopeschema.xml:1.8
Chris McDonough
chrism@zope.com
Tue, 8 Jul 2003 01:25:51 -0400
Update of /cvs-repository/Zope/lib/python/Zope/Startup
In directory cvs.zope.org:/tmp/cvs-serv26876/lib/python/Zope/Startup
Modified Files:
datatypes.py zopeschema.xml
Log Message:
Add a 'connection-class' key to the database definition which you may use to override the stock ZODB Connection class for a given database via the config file.
=== Zope/lib/python/Zope/Startup/datatypes.py 1.6 => 1.7 ===
--- Zope/lib/python/Zope/Startup/datatypes.py:1.6 Sun Apr 27 16:47:03 2003
+++ Zope/lib/python/Zope/Startup/datatypes.py Tue Jul 8 01:25:16 2003
@@ -15,6 +15,8 @@
"""Datatypes for the Zope schema for use with ZConfig."""
import os
+from ZODB.config import ZODBDatabase
+from ZODB.config import FileStorage
# generic datatypes
@@ -78,6 +80,27 @@
"begin with a slash" % value)
return value
+# A datatype that converts a Python dotted-path-name to an object
+
+def importable_name(name):
+ try:
+ components = name.split('.')
+ start = components[0]
+ g = globals()
+ package = __import__(start, g, g)
+ modulenames = [start]
+ for component in components[1:]:
+ modulenames.append(component)
+ try:
+ package = getattr(package, component)
+ except AttributeError:
+ n = '.'.join(modulenames)
+ package = __import__(n, g, g, component)
+ return package
+ except ImportError:
+ raise ValueError, (
+ 'The object named by "%s" could not be imported' % name )
+
# Datatype for the root configuration object
# (adds the softwarehome and zopehome fields; default values for some
# computed paths)
@@ -119,17 +142,25 @@
return section
+class ZopeDatabase(ZODBDatabase):
+ """ A ZODB database datatype that can handle an extended set of
+ attributes """
+ def open(self):
+ DB = ZODBDatabase.open(self)
+ # set the connection class
+ DB.klass = self.config.connection_class
+ return DB
+
def getDefaultDatabaseFactory(context):
# default to a filestorage named 'Data.fs' in clienthome
- from ZODB.config import FileStorage
- from ZODB.config import ZODBDatabase
-
class dummy:
def __init__(self, name):
self.name = name
def getSectionName(self):
return self.name
+ from ZODB.Connection import Connection
+
path = os.path.join(context.clienthome, 'Data.fs')
fs_ns = dummy('default filestorage at %s' % path)
fs_ns.path = path
@@ -144,4 +175,6 @@
db_ns.version_pool_size=3
db_ns.version_cache_size = 100
db_ns.mount_points = ['/']
- return ZODBDatabase(db_ns)
+ db_ns.connection_class = Connection
+ return ZopeDatabase(db_ns)
+
=== Zope/lib/python/Zope/Startup/zopeschema.xml 1.7 => 1.8 ===
--- Zope/lib/python/Zope/Startup/zopeschema.xml:1.7 Tue Apr 8 13:56:11 2003
+++ Zope/lib/python/Zope/Startup/zopeschema.xml Tue Jul 8 01:25:16 2003
@@ -121,8 +121,9 @@
</sectiontype>
- <sectiontype name="zodb_db" datatype="ZODB.config.ZODBDatabase"
+ <sectiontype name="zodb_db" datatype=".ZopeDatabase"
implements="ZODB.database" extends="zodb">
+
<description>
We need to specialize the database configuration section for Zope
only by including a (required) mount-point argument, which
@@ -131,6 +132,15 @@
</description>
<multikey name="mount-point" required="yes" attribute="mount_points"
datatype=".mount_point"/>
+
+ <description>
+ We want to allow people to be able to change the connection
+ class a database uses on a per-database basis to support
+ different connection policies.
+ </description>
+ <key name="connection-class" datatype=".importable_name"
+ default="ZODB.Connection.Connection"/>
+
</sectiontype>
<!-- end of type definitions -->
@@ -273,7 +283,7 @@
</description>
</key>
- <multisection type="ZODB.database" name="+" attribute="databases">
+ <multisection type="zodb_db" name="+" attribute="databases">
<description>
Zope ZODB databases must have a name, and they are required to be
referenced via the "zodb_db" database type because it is