[Checkins] SVN: z3c.saconfig/trunk/ Integrate with zope.sqlalchemy's Session registry.

Brian Sutherland jinty at web.de
Mon Mar 30 18:12:39 EDT 2009


Log message for revision 98644:
  Integrate with zope.sqlalchemy's Session registry.

Changed:
  U   z3c.saconfig/trunk/buildout.cfg
  U   z3c.saconfig/trunk/src/z3c/saconfig/README.txt
  U   z3c.saconfig/trunk/src/z3c/saconfig/meta.zcml
  U   z3c.saconfig/trunk/src/z3c/saconfig/scopedsession.py
  U   z3c.saconfig/trunk/src/z3c/saconfig/zcml.py

-=-
Modified: z3c.saconfig/trunk/buildout.cfg
===================================================================
--- z3c.saconfig/trunk/buildout.cfg	2009-03-30 22:12:36 UTC (rev 98643)
+++ z3c.saconfig/trunk/buildout.cfg	2009-03-30 22:12:39 UTC (rev 98644)
@@ -1,6 +1,7 @@
 [buildout]
 parts = test scripts
 develop = .
+	  ../zope.sqlalchemy
 
 [test]
 recipe = zc.recipe.testrunner
@@ -9,4 +10,4 @@
 [scripts]
 recipe = zc.recipe.egg
 eggs = z3c.saconfig
-interpreter = py
\ No newline at end of file
+interpreter = py

Modified: z3c.saconfig/trunk/src/z3c/saconfig/README.txt
===================================================================
--- z3c.saconfig/trunk/src/z3c/saconfig/README.txt	2009-03-30 22:12:36 UTC (rev 98643)
+++ z3c.saconfig/trunk/src/z3c/saconfig/README.txt	2009-03-30 22:12:39 UTC (rev 98644)
@@ -20,6 +20,18 @@
 in a single site; if you want more than one database in your Zope 3
 instance, you will need to set up different sites.
 
+Integration into zope.sqlalchemy
+================================
+
+We can install z3c.salchemy into zope.sqlalchemy to tell zope.sqlalchemy to use
+our implementation of sessions:
+
+  >>> from z3c.saconfig import scopedsession
+  >>> scopedsession.install_sessions()
+
+This can also be done via the "installSessions" zcml directive. It is important
+that this be only done during application setup.
+
 GloballyScopedSession (one database per Zope 3 instance)
 ========================================================
 
@@ -121,7 +133,7 @@
 We can now use the ``Session`` class to create a session which will
 behave according to the utility we provided::
 
-  >>> from z3c.saconfig import Session
+  >>> from zope.sqlalchemy import Session
   >>> session = Session()
 
 Now things go the usual ``zope.sqlalchemy`` way, which is like
@@ -374,3 +386,25 @@
   >>> Session = named_scoped_session('dummy')
   >>> Session().bind is factory()
   True
+
+We can setup the zope.sqlalchemy sessions using the installSessions directive
+(making sure we clean up before testing this):
+ 
+  >>> from zope.sqlalchemy import Session, clear_sessions
+
+  >>> clear_sessions()
+  >>> session = Session()
+  Traceback (most recent call last):
+    ...
+  KeyError: ''
+
+  >>> xmlconfig.xmlconfig(StringIO("""
+  ... <configure xmlns="http://namespaces.zope.org/db">
+  ...   <installSessions/>
+  ... </configure>"""))
+
+  >>> session = Session()
+
+CleanUp:
+
+  >>> clear_sessions()

Modified: z3c.saconfig/trunk/src/z3c/saconfig/meta.zcml
===================================================================
--- z3c.saconfig/trunk/src/z3c/saconfig/meta.zcml	2009-03-30 22:12:36 UTC (rev 98643)
+++ z3c.saconfig/trunk/src/z3c/saconfig/meta.zcml	2009-03-30 22:12:39 UTC (rev 98644)
@@ -18,6 +18,12 @@
        handler=".zcml.session"
        />
 
+    <meta:directive
+       name="installSessions"
+       schema="zope.interface.Interface"
+       handler=".zcml.install_sessions"
+       />
+
   </meta:directives>
 
 </configure>

Modified: z3c.saconfig/trunk/src/z3c/saconfig/scopedsession.py
===================================================================
--- z3c.saconfig/trunk/src/z3c/saconfig/scopedsession.py	2009-03-30 22:12:36 UTC (rev 98643)
+++ z3c.saconfig/trunk/src/z3c/saconfig/scopedsession.py	2009-03-30 22:12:39 UTC (rev 98644)
@@ -32,3 +32,7 @@
         return _named_scoped_sessions.setdefault(name,
                             scoped_session(lambda:session_factory(name),
                                            lambda:scopefunc(name)))
+
+def install_sessions():
+    from zope.sqlalchemy import install_sessions
+    install_sessions(_named_scoped_sessions)

Modified: z3c.saconfig/trunk/src/z3c/saconfig/zcml.py
===================================================================
--- z3c.saconfig/trunk/src/z3c/saconfig/zcml.py	2009-03-30 22:12:36 UTC (rev 98643)
+++ z3c.saconfig/trunk/src/z3c/saconfig/zcml.py	2009-03-30 22:12:39 UTC (rev 98644)
@@ -5,6 +5,7 @@
 
 import utility
 import interfaces
+from z3c.saconfig import scopedsession
 
 class IEngineDirective(zope.interface.Interface):
     """Registers a database engine factory."""
@@ -92,4 +93,7 @@
         component=scoped_session,
         permission=zope.component.zcml.PublicPermission,
         name=name)
-    
+
+def install_sessions(_context):
+    _context.action(discriminator=('installSessions'),
+                    callable=scopedsession.install_sessions)



More information about the Checkins mailing list