[Zope3-checkins] CVS: Zope3/src/zope/app/services - connection.py:1.9

Guido van Rossum guido@python.org
Wed, 23 Apr 2003 17:03:38 -0400


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

Modified Files:
	connection.py 
Log Message:
Add necessary hooks to maintain configuration usage.


=== Zope3/src/zope/app/services/connection.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/services/connection.py:1.8	Tue Apr 22 14:02:55 2003
+++ Zope3/src/zope/app/services/connection.py	Wed Apr 23 17:03:37 2003
@@ -17,12 +17,16 @@
 
 from persistence import Persistent
 from zope.proxy.context import ContextMethod
-from zope.app.component.nextservice import queryNextService
-from zope.app.interfaces.services.connection import ILocalConnectionService
-from zope.app.services.configuration import NameComponentConfigurable
+from zope.component import getAdapter
+
 from zope.app.interfaces.rdb import IZopeDatabaseAdapter
+from zope.app.interfaces.services.configuration import IUseConfiguration
+from zope.app.interfaces.services.connection import ILocalConnectionService
 from zope.app.interfaces.services.service import ISimpleService
 
+from zope.app.component.nextservice import queryNextService
+from zope.app.services.configuration import NameComponentConfigurable
+from zope.app.traversing import getPath
 
 class ConnectionService(Persistent, NameComponentConfigurable):
 
@@ -89,3 +93,24 @@
     def getInterface(self):
         return IZopeDatabaseAdapter
 
+    def afterAddHook(self, configuration, container):
+        """Hook method will call after an object is added to container.
+
+        Defined in IAddNotifiable.
+        """
+        super(ConnectionConfiguration, self).afterAddHook(configuration,
+                                                          container)
+        utility = configuration.getComponent()
+        adapter = getAdapter(utility, IUseConfiguration)
+        adapter.addUsage(getPath(configuration))
+
+    def beforeDeleteHook(self, configuration, container):
+        """Hook method will call before object is removed from container.
+
+        Defined in IDeleteNotifiable.
+        """
+        utility = configuration.getComponent()
+        adapter = getAdapter(utility, IUseConfiguration)
+        adapter.removeUsage(getPath(configuration))
+        super(ConnectionConfiguration, self).beforeDeleteHook(configuration,
+                                                              container)