[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ConnectionService - ConnectionConfiguration.py:1.1 IConnectionConfiguration.py:1.1 ConnectionService.py:1.6 IConnectionManager.py:1.2 configure.zcml:1.5

Viktorija Zaksiene ryzaja@codeworks.lt
Mon, 9 Dec 2002 10:27:12 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ConnectionService
In directory cvs.zope.org:/tmp/cvs-serv24078/lib/python/Zope/App/OFS/Services/ConnectionService

Modified Files:
	ConnectionService.py IConnectionManager.py configure.zcml 
Added Files:
	ConnectionConfiguration.py IConnectionConfiguration.py 
Log Message:
ConnectionService is no longer a container of database adapters; now the
latter are added directly into a package and bound to the connection service
via the common configuration mechanism.



=== Added File Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/ConnectionConfiguration.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""A configuration for a database adapter.

$Id: ConnectionConfiguration.py,v 1.1 2002/12/09 15:26:42 ryzaja Exp $
"""

from IConnectionConfiguration import IConnectionConfiguration
from Zope.App.OFS.Services.Configuration import ComponentConfiguration
from Zope.App.OFS.Services.Configuration import ConfigurationStatusProperty

class ConnectionConfiguration(ComponentConfiguration):

    __doc__ = IConnectionConfiguration.__doc__
    
    __implements__ = (IConnectionConfiguration,
                      ComponentConfiguration.__implements__)

    status = ConfigurationStatusProperty('SQLDatabaseConnections')

    def __init__(self, connection_name, *args, **kw):
        self.connectionName = connection_name
        super(ConnectionConfiguration, self).__init__(*args, **kw)


=== Added File Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/IConnectionConfiguration.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""A configuration for a database adapter.

$Id: IConnectionConfiguration.py,v 1.1 2002/12/09 15:26:42 ryzaja Exp $
"""

from Zope.Schema import TextLine
from Zope.App.OFS.Services.ConfigurationInterfaces \
     import IComponentConfiguration

class IConnectionConfiguration(IComponentConfiguration):
    """Database Connection Configuration

    Connection configurations are dependent on the database adapters that they
    configure. They register themselves as component dependents.    
    """

    connectionName = TextLine(title=u"Connection name",
                              required=True)



=== Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/ConnectionService.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/ConnectionService.py:1.5	Wed Dec  4 12:57:17 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/ConnectionService.py	Mon Dec  9 10:26:42 2002
@@ -14,47 +14,52 @@
 """
 $Id$
 """
-from types import TupleType
 
-from Zope.App.ComponentArchitecture.NextService import queryNextService
+from Persistence import Persistent
 from Zope.ContextWrapper import ContextMethod
+from Zope.Proxy.ContextWrapper import ContextWrapper
+from Zope.App.ComponentArchitecture.NextService import queryNextService
+from Zope.App.OFS.Annotation.IAttributeAnnotatable import IAttributeAnnotatable
+from Zope.App.OFS.Services.ConfigurationInterfaces import IConfigurable
+from Zope.App.OFS.Services.Configuration import ConfigurationRegistry
+from IConnectionManager import IConnectionManager
 
-from Zope.App.OFS.Container.IContainer import IHomogenousContainer, IContainer
-from Zope.App.OFS.Container.BTreeContainer import BTreeContainer
-
-from Zope.App.RDB.IConnectionService import IConnectionService
-from Zope.App.RDB.IZopeDatabaseAdapter import IZopeDatabaseAdapter
 
-class ILocalConnectionService(IConnectionService, IContainer,
-                              IHomogenousContainer):
-    """TTW manageable connection service"""
-    
+class ConnectionService(Persistent):
 
-class ConnectionService(BTreeContainer):
+    __doc__ = IConnectionManager.__doc__
 
-    __implements__ =  ILocalConnectionService
+    __implements__ = IConnectionManager, IAttributeAnnotatable
 
-    ############################################################
-    # Implementation methods for interface
-    # Zope.App.RDB.ConnectionService.ILocalConnectionService
+    def __init__(self):
+        super(ConnectionService, self).__init__()
+        self.__bindings = {}    # connectionName -> ConfigurationRegistry
 
-    ######################################
-    # from: Zope.App.RDB.IConnectionService.IConnectionService
 
     def getConnection(self, name):
         'See Zope.App.RDB.IConnectionService.IConnectionService'
-        return self.__getitem__(name)()
+        registry = self.queryConfigurations(name)
+        if registry:
+            configuration = registry.active()
+            if configuration is not None:
+                adapter = configuration.getComponent()
+                return adapter()
+        raise KeyError, name
+
+    getConnection = ContextMethod(getConnection)
 
     def queryConnection(self, name, default=None):
         'See Zope.App.RDB.IConnectionService.IConnectionService' 
-        adapter = self.get(name, default)
-        if adapter is not default:
-            return adapter()
-        return default
+        try:
+            return self.getConnection(name)
+        except KeyError:
+            return default
+    
+    queryConnection = ContextMethod(queryConnection)
 
     def getAvailableConnections(self):
         'See Zope.App.RDB.IConnectionService.IConnectionService'
-        connections = list(self.keys())
+        connections = list(self.__bindings.keys())
         service = queryNextService(self, "SQLDatabaseConnections")
         if service is not None:
             connections.append(service.getAvailableConnections())
@@ -62,16 +67,32 @@
 
     getAvailableConnections = ContextMethod(getAvailableConnections)
 
-    ######################################
-    # from: Zope.App.OFS.Container.IContainer.IHomogenousContainer
 
-    def isAddable(self, interfaces):
-        'See Zope.App.OFS.Container.IContainer.IHomogenousContainer'
-        if type(interfaces) != TupleType:
-            interfaces = (interfaces,)
-        if IZopeDatabaseAdapter in interfaces:
-            return 1
-        return 0
+    def queryConfigurationsFor(self, cfg, default=None):
+        'See Zope.App.OFS.Services.ConfigurationInterfaces.IConfigurable'
+        return self.queryConfigurations(cfg.connectionName)
+
+    queryConfigurationsFor = ContextMethod(queryConfigurationsFor)
+
+    def queryConfigurations(self, name, default=None):
+        registry = self.__bindings.get(name, default)
+        return ContextWrapper(registry, self)
+
+    queryConfigurations = ContextMethod(queryConfigurations)
+
+    def createConfigurationsFor(self, cfg):
+        'See Zope.App.OFS.Services.ConfigurationInterfaces.IConfigurable'
+        return self.createConfigurations(cfg.connectionName)
+
+    createConfigurationsFor = ContextMethod(createConfigurationsFor)
+
+    def createConfigurations(self, name):
+        try:
+            registry = self.__bindings[name]
+        except KeyError:
+            self.__bindings[name] = registry = ConfigurationRegistry()
+            self._p_changed = 1
+        return ContextWrapper(registry, self)
+    
+    createConfigurations = ContextMethod(createConfigurations)
 
-    #
-    ############################################################


=== Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/IConnectionManager.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/IConnectionManager.py:1.1	Mon Jun 24 12:18:50 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/IConnectionManager.py	Mon Dec  9 10:26:42 2002
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2002 Zope Corporation and Contributors.
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
 # 
 # This software is subject to the provisions of the Zope Public License,
@@ -14,10 +14,14 @@
 """
 $Id$
 """
-from Zope.App.OFS.Container.IContainer import IContainer
 from Zope.App.RDB.IConnectionService import IConnectionService
+from Zope.App.OFS.Services.ConfigurationInterfaces import IConfigurable
 
-class IConnectionManager(IContainer, IConnectionService):
-    """TTW object that manages RDBMS connections"""
+class IConnectionManager(IConnectionService, IConfigurable):
+    """A Connection Manager is a configurable connection service"""
 
-__doc__ = IConnectionManager.__doc__ + __doc__
+    def queryConfigurations(connection_name):
+        """Return an IConfigurationRegistry for a connection"""
+
+    def createConfigurations(connection_name):
+        """Create and return an IConfigurationRegistry a connection"""


=== Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/configure.zcml 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/configure.zcml:1.4	Sat Nov 30 13:36:38 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/ConnectionService/configure.zcml	Mon Dec  9 10:26:42 2002
@@ -5,11 +5,26 @@
     <factory id="ConnectionService" permission="Zope.ManageServices" />
       <require
           permission="Zope.View"
-          interface="Zope.App.RDB.IConnectionService." />
+          interface="Zope.App.RDB.IConnectionService."
+          attributes="queryConfigurations queryConfigurationsFor" />
       <require
           permission="Zope.ManageServices"
           interface="Zope.App.OFS.Container.IContainer." />
-      <implements interface="Zope.App.OFS.Annotation.IAttributeAnnotatable." />
+  </content>
+
+  <content class=".ConnectionConfiguration.">
+    <require
+        permission="Zope.ManageServices"
+        interface=".IConnectionConfiguration."
+        set_attributes="connectionName componentPath"
+        set_schema=
+            "Zope.App.OFS.Services.ConfigurationInterfaces.IConfiguration" />
+    <require
+        permission="Zope.ManageServices"
+        interface="Zope.App.OFS.Container.IAddNotifiable." />
+    <require
+        permission="Zope.ManageServices"
+        interface="Zope.App.OFS.Container.IDeleteNotifiable." />
   </content>
 
   <include package=".Views" />