[Checkins] SVN: zope.sqlalchemy/ Move global session registry to branch for now

Laurence Rowe l at lrowe.co.uk
Thu Jun 18 08:43:19 EDT 2009


Log message for revision 101126:
  Move global session registry to branch for now

Changed:
  A   zope.sqlalchemy/branches/global-session-registry/
  U   zope.sqlalchemy/trunk/CHANGES.txt
  U   zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt
  U   zope.sqlalchemy/trunk/src/zope/sqlalchemy/__init__.py

-=-
Modified: zope.sqlalchemy/trunk/CHANGES.txt
===================================================================
--- zope.sqlalchemy/trunk/CHANGES.txt	2009-06-18 12:14:15 UTC (rev 101125)
+++ zope.sqlalchemy/trunk/CHANGES.txt	2009-06-18 12:43:18 UTC (rev 101126)
@@ -5,8 +5,7 @@
 ----------------
 
 * Pull in pysqlite explicitly as a test dependency.
-* Add a global session factory registry so that applications can get the
-  Session from zope.sqlalchemy.
+
 * Setup sqlalchemy mappers in test setup and clear them in tear down. This
   makes the tests more robust and clears up the global state after. It
   caused the tests to fail when other tests in the same run called

Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt	2009-06-18 12:14:15 UTC (rev 101125)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt	2009-06-18 12:43:18 UTC (rev 101126)
@@ -10,8 +10,8 @@
 
 The aim of this package is to unify the plethora of existing packages
 integrating SQLAlchemy with Zope's transaction management. As such it seeks
-only to provide a data manager and hook to get the session. It makes no attempt
-to define a `zopeish` way to configure engines.
+only to provide a data manager and makes no attempt to define a `zopeish` way
+to configure engines.
 
 You need to understand SQLAlchemy for this package and this README to make 
 any sense. See http://sqlalchemy.org/docs/.
@@ -166,102 +166,6 @@
     u'bob'
     >>> transaction.abort()
 
-Session Registry
-================
-
-One difficulty in writing re-usable code is where to get the Session object
-from. zope.sqlalchemy provides a registry for plugging in different session
-factories.
-
-IMPORTANT: This should be setup only at application configure/setup time. All
-other run-time lookup should be built into the session factories themselves.
-
-Setup:
-
-    >>> import zope.sqlalchemy
-    >>> from zope.sqlalchemy import Session, install_sessions, clear_sessions, named_session
-    >>> def fake_session_factory(name):
-    ...     def f():
-    ...         return name
-    ...     return f
-
-Single Session
---------------
-
-To simply configure the default session we only need to assign it:
-
-    >>> zope.sqlalchemy.set_session(fake_session_factory('default'))
-    >>> zope.sqlalchemy.Session()
-    'default'
-    >>> Session()
-    'default'
-
-    >>> clear_sessions()
-
-Named Sessions
---------------
-
-We can also register multiple sessions by installing them:
-
-    >>> sessions = {'session1': fake_session_factory('session1'),
-    ...             'session2': fake_session_factory('session2')}
-    >>> install_sessions(sessions)
-
-And then get them:
-
-    >>> named_session('session1')
-    'session1'
-
-However, we have not registered a default session, so the default session errors:
-
-    >>> zope.sqlalchemy.Session()
-    Traceback (most recent call last):
-        ...
-    KeyError: ''
-    >>> Session()
-    Traceback (most recent call last):
-        ...
-    KeyError: ''
-
-We can modify our registered dict to have a default:
-
-    >>> sessions[''] = fake_session_factory('default')
-    >>> zope.sqlalchemy.Session()
-    'default'
-    >>> Session()
-    'default'
-    
-Cleanup
--------
-    
-We can clean up with clear_sessions:
-
-    >>> clear_sessions()
-    >>> zope.sqlalchemy.Session()
-    Traceback (most recent call last):
-        ...
-    KeyError: ''
-    >>> Session()
-    Traceback (most recent call last):
-        ...
-    KeyError: ''
-    >>> named_session('session1')
-    Traceback (most recent call last):
-        ...
-    KeyError: 'session1'
-    
-Even if we import it after setting it up:
-
-    >>> zope.sqlalchemy.set_session(fake_session_factory('default'))
-    >>> from zope.sqlalchemy import Session as SetupSession
-    >>> SetupSession()
-    'default'
-    >>> clear_sessions()
-    >>> SetupSession()
-    Traceback (most recent call last):
-        ...
-    KeyError: ''
-
 Development version
 ===================
 

Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/__init__.py
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/__init__.py	2009-06-18 12:14:15 UTC (rev 101125)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/__init__.py	2009-06-18 12:43:18 UTC (rev 101126)
@@ -16,23 +16,3 @@
 
 from datamanager import ZopeTransactionExtension, mark_changed
 invalidate = mark_changed
-
-_SESSIONS = {}
-
-def Session():
-    """Find the default session factory, execute and return the session"""
-    return _SESSIONS['']()
-
-def set_session(session_factory, name=''):
-    _SESSIONS[name] = session_factory
-
-def named_session(name):
-    return _SESSIONS[name]()
-
-def clear_sessions():
-    global _SESSIONS
-    _SESSIONS = {}
-
-def install_sessions(sessions):
-    global _SESSIONS
-    _SESSIONS = sessions



More information about the Checkins mailing list