diff options
author | Jason Kirtland <jek@discorporate.us> | 2007-07-28 19:51:55 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2007-07-28 19:51:55 +0000 |
commit | 9f100231798d83f2bf4a53494eb5199864a0094d (patch) | |
tree | 829e6165c1f38ae042ac5c41da673d1a397370a7 /lib/sqlalchemy/interfaces.py | |
parent | 7a0a1cbc817eb0cab90118f288e9a65c7ac35aaa (diff) | |
download | sqlalchemy-9f100231798d83f2bf4a53494eb5199864a0094d.tar.gz |
Added pool hooks for connection creation, check out and check in.
Diffstat (limited to 'lib/sqlalchemy/interfaces.py')
-rw-r--r-- | lib/sqlalchemy/interfaces.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/sqlalchemy/interfaces.py b/lib/sqlalchemy/interfaces.py new file mode 100644 index 000000000..5df19ceef --- /dev/null +++ b/lib/sqlalchemy/interfaces.py @@ -0,0 +1,51 @@ +# interfaces.py +# Copyright (C) 2007 Jason Kirtland jek@discorporate.us +# +# This module is part of SQLAlchemy and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php + + +class PoolListener(object): + """Hooks into the lifecycle of connections in a ``Pool``. + + """ + + def connect(dbapi_con, con_record): + """Called once for each new DBAPI connection or pool's ``creator()``. + + dbapi_con: + A newly connected raw DBAPI connection (not a SQLAlchemy + ``Connection`` wrapper). + + con_record: + The ``_ConnectionRecord`` that currently owns the connection + """ + + def checkout(dbapi_con, con_record): + """Called when a connection is retrieved from the pool. + + dbapi_con: + A raw DBAPI connection + + con_record: + The ``_ConnectionRecord`` that currently owns the connection + + If you raise an ``exceptions.DisconnectionError``, the current + connection will be disposed and a fresh connection retrieved. + Processing of all checkout listeners will abort and restart + using the new connection. + """ + + def checkin(dbapi_con, con_record): + """Called when a connection returns to the pool. + + Note that the connection may be closed, and may be None if the + connection has been invalidated. ``checkin`` will not be called + for detached connections. (They do not return to the pool.) + + dbapi_con: + A raw DBAPI connection + + con_record: + The _ConnectionRecord that currently owns the connection + """ |