diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-07-24 17:55:06 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-07-24 17:55:06 -0400 |
| commit | 693e2dcacf7c6317c131ad11fcc0466e6c9164b8 (patch) | |
| tree | f807bae733831f9b09fc59447b8ffabd022d7a66 /lib/sqlalchemy/engine | |
| parent | 8a7ae371535342bb35491d59aaa1131ba7c435fa (diff) | |
| download | sqlalchemy-693e2dcacf7c6317c131ad11fcc0466e6c9164b8.tar.gz | |
- worked it out so that classes declare a nested class "event",
with methods representing events. This is self-documenting via sphinx.
- implemented new model for pool, classmanager. Most events are
one or two args, so going back to allowing any kind of *arg, **kw
signature for events - this is simpler and improves performance,
though we don't get the "we can add new kw's anytime". perhaps
there's some other way to approach that.
Diffstat (limited to 'lib/sqlalchemy/engine')
| -rw-r--r-- | lib/sqlalchemy/engine/base.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/strategies.py | 17 |
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 51620dd37..ae7df83f6 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -1546,7 +1546,7 @@ class TwoPhaseTransaction(Transaction): def _do_commit(self): self.connection._commit_twophase_impl(self.xid, self._is_prepared) -class _EngineDispatch(event.Dispatch): +class _EngineDispatch(event.Events): def append(self, fn, identifier, target): if isinstance(target.Connection, Connection): target.Connection = _proxy_connection_cls(target.Connection, self) @@ -1575,6 +1575,7 @@ class Engine(Connectable, log.Identified): Connection = Connection _dispatch = event.dispatcher(_EngineDispatch) + def __init__(self, pool, dialect, url, logging_name=None, echo=None, proxy=None, execution_options=None diff --git a/lib/sqlalchemy/engine/strategies.py b/lib/sqlalchemy/engine/strategies.py index 7fc39b91a..1ef3ae624 100644 --- a/lib/sqlalchemy/engine/strategies.py +++ b/lib/sqlalchemy/engine/strategies.py @@ -11,7 +11,7 @@ New strategies can be added via new ``EngineStrategy`` classes. from operator import attrgetter from sqlalchemy.engine import base, threadlocal, url -from sqlalchemy import util, exc +from sqlalchemy import util, exc, event from sqlalchemy import pool as poollib strategies = {} @@ -132,18 +132,19 @@ class DefaultEngineStrategy(EngineStrategy): if _initialize: do_on_connect = dialect.on_connect() if do_on_connect: - def on_connect(conn, rec): - conn = getattr(conn, '_sqla_unwrap', conn) + def on_connect(dbapi_connection, connection_record): + conn = getattr(dbapi_connection, '_sqla_unwrap', dbapi_connection) if conn is None: return do_on_connect(conn) + + event.listen(on_connect, 'on_first_connect', pool) + event.listen(on_connect, 'on_connect', pool) - pool.add_listener({'first_connect': on_connect, 'connect':on_connect}) - - def first_connect(conn, rec): - c = base.Connection(engine, connection=conn) + def first_connect(dbapi_connection, connection_record): + c = base.Connection(engine, connection=dbapi_connection) dialect.initialize(c) - pool.add_listener({'first_connect':first_connect}) + event.listen(first_connect, 'on_first_connect', pool) return engine |
