diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-27 20:17:37 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-08-27 20:17:37 -0400 |
commit | 63c1800c568824b6828ac791f83fd2bf7626adcc (patch) | |
tree | fe1e8dd2643b3eea3ab0700fdcd28a1abeee82fd /lib/sqlalchemy/interfaces.py | |
parent | dc31eb352aed6b578b7cf0bbc0d4290b6d11f2b2 (diff) | |
download | sqlalchemy-63c1800c568824b6828ac791f83fd2bf7626adcc.tar.gz |
- its probably worthwhile to make the primary listen() interface humane, i.e.:
def listen(target, args)
so here we provide a "wrapper" approach that allows this, and it is
basically pass-by-value. a pass-by-value event *may* support rewriting
some of the args in the dictionary.
the current
listen will become "listen_raw" since it saves about 100% overhead versus
the coercion to dict, and will be used internally, and will remain
pass-by-reference.
proxyconnection probably will rely upon the newer style of pass-by-value
for "rewrite the args" types of calls.
Diffstat (limited to 'lib/sqlalchemy/interfaces.py')
-rw-r--r-- | lib/sqlalchemy/interfaces.py | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/lib/sqlalchemy/interfaces.py b/lib/sqlalchemy/interfaces.py index 36573bf43..d502afbd8 100644 --- a/lib/sqlalchemy/interfaces.py +++ b/lib/sqlalchemy/interfaces.py @@ -13,7 +13,7 @@ class PoolListener(object): """Hooks into the lifecycle of connections in a :class:`Pool`. .. note:: :class:`PoolListener` is deprecated. Please - refer to :func:`event.listen` as well as + refer to :func:`event.listen_raw` as well as :attr:`.Pool.events`. Usage:: @@ -75,13 +75,13 @@ class PoolListener(object): listener = as_interface(listener, methods=('connect', 'first_connect', 'checkout', 'checkin')) if hasattr(listener, 'connect'): - event.listen(listener.connect, 'on_connect', self) + event.listen_raw(listener.connect, 'on_connect', self) if hasattr(listener, 'first_connect'): - event.listen(listener.first_connect, 'on_first_connect', self) + event.listen_raw(listener.first_connect, 'on_first_connect', self) if hasattr(listener, 'checkout'): - event.listen(listener.checkout, 'on_checkout', self) + event.listen_raw(listener.checkout, 'on_checkout', self) if hasattr(listener, 'checkin'): - event.listen(listener.checkin, 'on_checkin', self) + event.listen_raw(listener.checkin, 'on_checkin', self) def connect(self, dbapi_con, con_record): @@ -146,7 +146,7 @@ class ConnectionProxy(object): """Allows interception of statement execution by Connections. .. note:: :class:`ConnectionProxy` is deprecated. Please - refer to :func:`event.listen` as well as + refer to :func:`event.listen_raw` as well as :attr:`.Engine.events`. Either or both of the ``execute()`` and ``cursor_execute()`` @@ -175,29 +175,48 @@ class ConnectionProxy(object): @classmethod def _adapt_listener(cls, self, listener): - event.listen(listener.execute, 'on_execute', self) + # TODO: suppose if new style listeners used here. then we say: + + # def _wrap_in_some_way(legacy_listener): + # def go(clauseelement, *multiparams, **params): + # # 'fake' execute function. in reality just repopulates + # # the event with the given args in case they were modified. + # args.update({'clauseelement':clauseelement, 'multiparams':multiparams, 'params':params}) + # return args + # def listen(evt, args): + # return legacy_listener(args['conn'], go, args['clauseelement'], *args['multiparams'], **args['params']) + # + # event.listen(_wrap_in_some_way(self.execute), 'on_execute', self) + # + # that way all the complex crap is left in the legacy adapter, and the "re-execute" idea is + # scrapped, since it was fairly pointless. The proxyconnection stuff in base.py can just + # iterate through listeners. + # + + event.listen_raw(listener.execute, 'on_execute', self) def _adapt_cursor_execute(conn, execute, cursor, statement, parameters, context, executemany): def _re_execute(cursor, statement, parameters, context): return execute(cursor, statement, parameters, context, executemany) return listener.cursor_execute(_re_execute, cursor, statement, parameters, context, executemany) - event.listen(_adapt_cursor_execute, 'on_cursor_execute', self) - event.listen(listener.begin, 'on_begin', self) - event.listen(listener.rollback, 'on_rollback', self) - event.listen(listener.commit, 'on_commit', self) - event.listen(listener.savepoint, 'on_savepoint', self) - event.listen(listener.rollback_savepoint, 'on_rollback_savepoint', self) - event.listen(listener.release_savepoint, 'on_release_savepoint', self) - event.listen(listener.begin_twophase, 'on_begin_twophase', self) - event.listen(listener.prepare_twophase, 'on_prepare_twophase', self) - event.listen(listener.rollback_twophase, 'on_rollback_twophase', self) - event.listen(listener.commit_twophase, 'on_commit_twophase', self) + event.listen_raw(_adapt_cursor_execute, 'on_cursor_execute', self) + event.listen_raw(listener.begin, 'on_begin', self) + event.listen_raw(listener.rollback, 'on_rollback', self) + event.listen_raw(listener.commit, 'on_commit', self) + event.listen_raw(listener.savepoint, 'on_savepoint', self) + event.listen_raw(listener.rollback_savepoint, 'on_rollback_savepoint', self) + event.listen_raw(listener.release_savepoint, 'on_release_savepoint', self) + event.listen_raw(listener.begin_twophase, 'on_begin_twophase', self) + event.listen_raw(listener.prepare_twophase, 'on_prepare_twophase', self) + event.listen_raw(listener.rollback_twophase, 'on_rollback_twophase', self) + event.listen_raw(listener.commit_twophase, 'on_commit_twophase', self) def execute(self, conn, execute, clauseelement, *multiparams, **params): """Intercept high level execute() events.""" + return execute(clauseelement, *multiparams, **params) def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): |