summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/activemapper.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-07-10 21:53:49 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-07-10 21:53:49 +0000
commit2dfdf70660d747f02e628f8a5263d03820a50f35 (patch)
tree7a9ba273e64aa7e489ae5082fdee061fe340256d /lib/sqlalchemy/ext/activemapper.py
parent55edd4ce95a0bd2f92482474b866debb3a29b3cf (diff)
downloadsqlalchemy-2dfdf70660d747f02e628f8a5263d03820a50f35.tar.gz
activemapper will use threadlocal mod's objectstore if its installed
both objectstores no longer subclass SessionContext, get at it via .context attribute instead
Diffstat (limited to 'lib/sqlalchemy/ext/activemapper.py')
-rw-r--r--lib/sqlalchemy/ext/activemapper.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/sqlalchemy/ext/activemapper.py b/lib/sqlalchemy/ext/activemapper.py
index 6c6886c66..d21332e3a 100644
--- a/lib/sqlalchemy/ext/activemapper.py
+++ b/lib/sqlalchemy/ext/activemapper.py
@@ -6,6 +6,7 @@ from sqlalchemy import Table, Column, ForeignKey
from sqlalchemy.ext.sessioncontext import SessionContext
from sqlalchemy.ext.assignmapper import assign_mapper
from sqlalchemy import backref as create_backref
+import sqlalchemy
import inspect
import sys
@@ -15,18 +16,16 @@ import sys
#
metadata = DynamicMetaData("activemapper")
-#
-# thread local SessionContext
-#
-class Objectstore(object):
-
- def __init__(self, *args, **kwargs):
- self._context = SessionContext(*args, **kwargs)
-
- def __getattr__(self, name):
- return getattr(self._context.current, name)
-
-objectstore = Objectstore(create_session)
+try:
+ objectstore = sqlalchemy.objectstore
+except AttributeError:
+ # thread local SessionContext
+ class Objectstore(object):
+ def __init__(self, *args, **kwargs):
+ self.context = SessionContext(*args, **kwargs)
+ def __getattr__(self, name):
+ return getattr(self.context.current, name)
+ objectstore = Objectstore(create_session)
#
@@ -237,10 +236,10 @@ class ActiveMapperMeta(type):
# check for inheritence
if hasattr(bases[0], "mapping"):
cls._base_mapper= bases[0].mapper
- assign_mapper(objectstore._context, cls, cls.table,
+ assign_mapper(objectstore.context, cls, cls.table,
inherits=cls._base_mapper)
else:
- assign_mapper(objectstore._context, cls, cls.table)
+ assign_mapper(objectstore.context, cls, cls.table)
cls.relations = relations
ActiveMapperMeta.classes[clsname] = cls