summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-08-02 05:42:49 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-08-02 05:42:49 +0000
commitb8b51fe4379936fe142c875ea0f17da14a12c27d (patch)
tree987fc4033cad747f0decfa80e38708a13d812d4c /lib/sqlalchemy/ext
parent9f23ec7423e98305f43a0b7a7ef894da74325329 (diff)
downloadsqlalchemy-b8b51fe4379936fe142c875ea0f17da14a12c27d.tar.gz
- sessionmaker module is out, replaced with simple function in session.py
- scoping/class instrumenting behavior of sessionmaker moved into new scoping module which implements scoped_session() (subject to potential name change) - SessionContext / assignmapper are deprecated, replaced with scoped_session()
Diffstat (limited to 'lib/sqlalchemy/ext')
-rw-r--r--lib/sqlalchemy/ext/assignmapper.py1
-rw-r--r--lib/sqlalchemy/ext/sessioncontext.py67
2 files changed, 18 insertions, 50 deletions
diff --git a/lib/sqlalchemy/ext/assignmapper.py b/lib/sqlalchemy/ext/assignmapper.py
index cab5a9eae..730b5313b 100644
--- a/lib/sqlalchemy/ext/assignmapper.py
+++ b/lib/sqlalchemy/ext/assignmapper.py
@@ -26,6 +26,7 @@ def _monkeypatch_session_method(name, ctx, class_):
setattr(class_, name, do)
def assign_mapper(ctx, class_, *args, **kwargs):
+ util.warn_deprecated("assign_mapper is deprecated. Use scoped_session() instead.")
extension = kwargs.pop('extension', None)
if extension is not None:
extension = util.to_list(extension)
diff --git a/lib/sqlalchemy/ext/sessioncontext.py b/lib/sqlalchemy/ext/sessioncontext.py
index 8221bc495..5ac8acb40 100644
--- a/lib/sqlalchemy/ext/sessioncontext.py
+++ b/lib/sqlalchemy/ext/sessioncontext.py
@@ -1,35 +1,24 @@
-from sqlalchemy.util import ScopedRegistry, warn_deprecated
-from sqlalchemy.orm import create_session, object_session, MapperExtension, EXT_CONTINUE
+from sqlalchemy.orm.scoping import ScopedSession, _ScopedExt
+from sqlalchemy.util import warn_deprecated
+from sqlalchemy.orm import create_session
__all__ = ['SessionContext', 'SessionContextExt']
-class SessionContext(object):
- """A simple wrapper for ``ScopedRegistry`` that provides a
- `current` property which can be used to get, set, or remove the
- session in the current scope.
- By default this object provides thread-local scoping, which is the
- default scope provided by sqlalchemy.util.ScopedRegistry.
+class SessionContext(ScopedSession):
+ """Provides thread-local management of Sessions.
Usage::
- engine = create_engine(...)
- def session_factory():
- return Session(bind=engine)
- context = SessionContext(session_factory)
+ context = SessionContext(sessionmaker(autoflush=True))
- s = context.current # get thread-local session
- context.current = Session(bind=other_engine) # set current session
- del context.current # discard the thread-local session (a new one will
- # be created on the next call to context.current)
"""
def __init__(self, session_factory=None, scopefunc=None):
- warn_deprecated("SessionContext is deprecated. Use Session=sessionmaker(scope='thread').")
+ warn_deprecated("SessionContext is deprecated. Use scoped_session().")
if session_factory is None:
- session_factory = create_session
- self.registry = ScopedRegistry(session_factory, scopefunc)
- super(SessionContext, self).__init__()
+ session_factory=create_session
+ super(SessionContext, self).__init__(session_factory, scopefunc=scopefunc)
def get_current(self):
return self.registry()
@@ -51,33 +40,11 @@ class SessionContext(object):
return ext
mapper_extension = property(_get_mapper_extension,
- doc="""Get a mapper extension that implements `get_session` using this context.""")
-
-
-class SessionContextExt(MapperExtension):
- """A mapper extension that provides sessions to a mapper using ``SessionContext``."""
-
- def __init__(self, context):
- MapperExtension.__init__(self)
- self.context = context
-
- def get_session(self):
- return self.context.current
-
- def init_instance(self, mapper, class_, oldinit, instance, args, kwargs):
- session = kwargs.pop('_sa_session', self.context.current)
- session._save_impl(instance, entity_name=kwargs.pop('_sa_entity_name', None))
- return EXT_CONTINUE
-
- def init_failed(self, mapper, class_, instance, args, kwargs):
- object_session(instance).expunge(instance)
- return EXT_CONTINUE
-
- def dispose_class(self, mapper, class_):
- if hasattr(class_, '__init__') and hasattr(class_.__init__, '_oldinit'):
- if class_.__init__._oldinit is not None:
- class_.__init__ = class_.__init__._oldinit
- else:
- delattr(class_, '__init__')
-
-
+ doc="""Get a mapper extension that implements `get_session` using this context. Deprecated.""")
+
+
+class SessionContextExt(_ScopedExt):
+ def __init__(self, *args, **kwargs):
+ warn_deprecated("SessionContextExt is deprecated. Use ScopedSession(enhance_classes=True)")
+ super(SessionContextExt, self).__init__(*args, **kwargs)
+