diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-11 21:04:48 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-11 21:04:48 +0000 |
commit | 86c0504fa6fc95dc2ac644d1a37dc86a0e502fb1 (patch) | |
tree | add3e118a4148e69f02e2399fa2cf1e4e5426912 /lib/sqlalchemy/ext | |
parent | 280274812261868e8f665f706cd27e06eaff4302 (diff) | |
download | sqlalchemy-86c0504fa6fc95dc2ac644d1a37dc86a0e502fb1.tar.gz |
tableimpl and columnimpl proxy to actual impl objects per engine
Diffstat (limited to 'lib/sqlalchemy/ext')
-rw-r--r-- | lib/sqlalchemy/ext/proxy.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/proxy.py b/lib/sqlalchemy/ext/proxy.py index 6139164bf..4db001653 100644 --- a/lib/sqlalchemy/ext/proxy.py +++ b/lib/sqlalchemy/ext/proxy.py @@ -7,7 +7,7 @@ from sqlalchemy import sql from sqlalchemy.engine import create_engine from sqlalchemy.types import TypeEngine -import thread +import thread, weakref class ProxyEngine(object): """ @@ -84,13 +84,23 @@ class ProxyEngine(object): raise AttributeError('No connection established in ProxyEngine: ' ' no access to %s' % attr) + class ProxyColumnImpl(sql.ColumnImpl): """Proxy column; defers engine access to ProxyEngine """ def __init__(self, engine, column): sql.ColumnImpl.__init__(self, column) self._engine = engine - + self.impls = weakref.WeakKeyDictionary() + def _get_impl(self): + e = self.engine + try: + return self.impls[e] + except KeyError: + impl = e.columnimpl(self.column) + self.impls[e] = impl + def __getattr__(self, key): + return getattr(self._get_impl(), key) engine = property(lambda self: self._engine.engine) class ProxyTableImpl(sql.TableImpl): @@ -99,6 +109,17 @@ class ProxyTableImpl(sql.TableImpl): def __init__(self, engine, table): sql.TableImpl.__init__(self, table) self._engine = engine + self.impls = weakref.WeakKeyDictionary() + def _get_impl(self): + e = self.engine + try: + return self.impls[e] + except KeyError: + impl = e.tableimpl(self.table) + self.impls[e] = impl + return impl + def __getattr__(self, key): + return getattr(self._get_impl(), key) engine = property(lambda self: self._engine.engine) |