[Zope3-checkins] CVS: Zope3/src/zope/app/services - configure.zcml:1.55 connection.py:1.18

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Aug 19 04:10:29 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv15967/services

Modified Files:
	configure.zcml connection.py 
Log Message:
Heads up, this is the beginning of Servicegeddon. We noticed that named 
components are a pain in the butt and that we can simpluify our code a lot
by making these named components local utilities. 

So I started with the SQL Connection service and database adapters and 
simplified the code greatly. Database Adaptors are now just simple 
utilities.

I also took the oppurtunity and updated all database adapters. 

This change is not backward compatible and you will have to toss your ZODB.
Although all tests pass, I expect there to be some hickups, so feel free to 
fix or report these. 

Next I will fix up the front screen a bit and try to factor some other 
pieces. I also still miss some functionality in the Utilities, which I plan
to add.




=== Zope3/src/zope/app/services/configure.zcml 1.54 => 1.55 ===
--- Zope3/src/zope/app/services/configure.zcml:1.54	Fri Aug 15 20:44:08 2003
+++ Zope3/src/zope/app/services/configure.zcml	Tue Aug 19 03:09:53 2003
@@ -325,41 +325,23 @@
     <implements
         interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
         />
-    </content>
+  </content>
 
-<!-- Page Folder --> <include file="pagefolder.zcml" />
+<!-- Page Folder --> 
+  <include file="pagefolder.zcml" />
 
 <!-- Connection Service -->
 
   <content class="zope.app.services.connection.ConnectionService">
     <factory
-       id="ConnectionService"
-       permission="zope.ManageServices"
-       />
+       id="zope.services.ConnectionService"
+       permission="zope.ManageServices" />
+
     <require
         permission="zope.View"
-        interface="zope.app.interfaces.rdb.IConnectionService"
-        attributes="queryRegistrations queryRegistrationsFor
-                    listRegistrationNames" />
-    </content>
+        interface="zope.app.interfaces.rdb.IConnectionService" />
 
-  <content class="zope.app.services.connection.ConnectionRegistration">
-    <require
-        permission="zope.ManageServices"
-        interface=
-        "zope.app.interfaces.services.connection.IConnectionRegistration"
-        set_attributes="name componentPath"
-        set_schema="zope.app.interfaces.services.view.IPageRegistration"
-        />
-    <require
-        permission="zope.ManageServices"
-        interface="zope.app.interfaces.container.IAddNotifiable"
-        />
-    <require
-        permission="zope.ManageServices"
-        interface="zope.app.interfaces.container.IDeleteNotifiable"
-        />
-    </content>
+  </content>
 
 <!-- Principal annotations (user data) service -->
 
@@ -506,11 +488,6 @@
 
 <fssync:adapter
     class=".cache.CacheRegistration"
-    factory=".registration.ComponentRegistrationAdapter"
-    />
-
-<fssync:adapter
-    class=".connection.ConnectionRegistration"
     factory=".registration.ComponentRegistrationAdapter"
     />
 


=== Zope3/src/zope/app/services/connection.py 1.17 => 1.18 ===
--- Zope3/src/zope/app/services/connection.py:1.17	Thu Jul  3 18:46:15 2003
+++ Zope3/src/zope/app/services/connection.py	Tue Aug 19 03:09:53 2003
@@ -15,30 +15,28 @@
 
 $Id$
 """
-
 from persistence import Persistent
+from zope.app import zapi
 from zope.app.component.nextservice import queryNextService
 from zope.app.interfaces.rdb import IZopeDatabaseAdapter
-from zope.app.interfaces.services.connection import IConnectionRegistration
 from zope.app.interfaces.services.connection import ILocalConnectionService
+from zope.app.interfaces.services.registration import ActiveStatus
 from zope.app.interfaces.services.service import ISimpleService
-from zope.app.services.servicenames import SQLDatabaseConnections
-from zope.app.services.registration import NameComponentRegistry
-from zope.app.services.registration import NamedComponentRegistration
-from zope.app import zapi
+from zope.app.services.servicenames import SQLDatabaseConnections, Utilities
 from zope.interface import implements
 
-class ConnectionService(Persistent, NameComponentRegistry):
-
-    __doc__ = ILocalConnectionService.__doc__
+class ConnectionService(Persistent):
+    """This is a local relational database connection service."""
 
     implements(ILocalConnectionService, ISimpleService)
 
     def getConnection(self, name):
         'See IConnectionService'
-        dbadapter = self.queryActiveComponent(name)
-        if dbadapter is not None:
-            return dbadapter()
+        utilities = zapi.getService(self, Utilities)
+        matching = utilities.getRegisteredMatching(IZopeDatabaseAdapter)
+        matching = filter(lambda m: m[1] == name, matching)
+        if matching and matching[0][2].active() is not None:
+            return matching[0][2].active().getComponent()
         service = queryNextService(self, SQLDatabaseConnections)
         if service is not None:
             return service.getConnection(name)
@@ -57,37 +55,17 @@
 
     def getAvailableConnections(self):
         'See IConnectionService'
-        connections = {}
-        for name in self.listRegistrationNames():
-            registry = self.queryRegistrations(name)
-            if registry.active() is not None:
-                connections[name] = 0
+        connections = []
+        utilities = zapi.getService(self, Utilities)
+        matching = utilities.getRegisteredMatching(IZopeDatabaseAdapter)
+        for match in matching:
+            if match[2].active() is not None:
+                connections.append(match[1])
         service = queryNextService(self, SQLDatabaseConnections)
         if service is not None:
-            # Note that this works because we're only interested in the names
-            # of connections. If we wanted other data about connections, we'd
-            # have to be careful not to override this service's connections
-            # with higher-up connections.
             for name in service.getAvailableConnections():
-                connections[name] = 0
-        return connections.keys()
+                if name not in connections:
+                    connections.append(name)
+        return connections
 
     getAvailableConnections = zapi.ContextMethod(getAvailableConnections)
-
-
-class ConnectionRegistration(NamedComponentRegistration):
-
-    __doc__ = IConnectionRegistration.__doc__
-
-    implements(IConnectionRegistration)
-
-    serviceType = SQLDatabaseConnections
-
-    label = "Connection"
-
-    def getInterface(self):
-        return IZopeDatabaseAdapter
-
-
-# XXX Pickle backward compatability
-ConnectionConfiguration = ConnectionRegistration




More information about the Zope3-Checkins mailing list