summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/interfaces.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-07-24 13:19:59 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-07-24 13:19:59 -0400
commit8a7ae371535342bb35491d59aaa1131ba7c435fa (patch)
tree23794b40afd01c275a2831361c19a02bd4cd388e /lib/sqlalchemy/interfaces.py
parent8e0618aa650c43b483dbae443ddca94fcdd5b945 (diff)
downloadsqlalchemy-8a7ae371535342bb35491d59aaa1131ba7c435fa.tar.gz
- initial "events" idea. will replace all Extension, Proxy, Listener
implementations with a single interface.
Diffstat (limited to 'lib/sqlalchemy/interfaces.py')
-rw-r--r--lib/sqlalchemy/interfaces.py41
1 files changed, 39 insertions, 2 deletions
diff --git a/lib/sqlalchemy/interfaces.py b/lib/sqlalchemy/interfaces.py
index c2a267d5f..2447b15bf 100644
--- a/lib/sqlalchemy/interfaces.py
+++ b/lib/sqlalchemy/interfaces.py
@@ -6,10 +6,14 @@
"""Interfaces and abstract types."""
+from sqlalchemy.util import as_interface, adapt_kw_to_positional
class PoolListener(object):
- """Hooks into the lifecycle of connections in a ``Pool``.
+ """Hooks into the lifecycle of connections in a :class:`Pool`.
+ .. note:: :class:`PoolListener` is deprecated. Please
+ refer to :func:`event.listen`.
+
Usage::
class MyListener(PoolListener):
@@ -58,7 +62,32 @@ class PoolListener(object):
providing implementations for the hooks you'll be using.
"""
-
+
+ @classmethod
+ def _adapt_listener(cls, self, listener):
+ """Adapt a :class:`PoolListener` to individual
+ :class:`event.Dispatch` events.
+
+ """
+ listener = as_interface(listener,
+ methods=('connect', 'first_connect', 'checkout', 'checkin'))
+
+ if hasattr(listener, 'connect'):
+ self._dispatch.append('on_connect',
+ adapt_kw_to_positional(listener.connect,
+ 'dbapi_con', 'con_record'),
+ self)
+ if hasattr(listener, 'first_connect'):
+ self._dispatch.append('on_first_connect',
+ adapt_kw_to_positional(listener.first_connect,
+ 'dbapi_con', 'con_record'),
+ self)
+ if hasattr(listener, 'checkout'):
+ self._dispatch.append('on_checkout', listener.checkout, self)
+ if hasattr(listener, 'checkin'):
+ self._dispatch.append('on_checkin', listener.checkin, self)
+
+
def connect(self, dbapi_con, con_record):
"""Called once for each new DB-API connection or Pool's ``creator()``.
@@ -119,6 +148,9 @@ class PoolListener(object):
class ConnectionProxy(object):
"""Allows interception of statement execution by Connections.
+
+ .. note:: :class:`ConnectionProxy` is deprecated. Please
+ refer to :func:`event.listen`.
Either or both of the ``execute()`` and ``cursor_execute()``
may be implemented to intercept compiled statement and
@@ -143,6 +175,11 @@ class ConnectionProxy(object):
e = create_engine('someurl://', proxy=MyProxy())
"""
+
+ @classmethod
+ def _adapt_listener(cls, self, listener):
+ pass
+
def execute(self, conn, execute, clauseelement, *multiparams, **params):
"""Intercept high level execute() events."""