Repository URL to install this package:
Version:
4.0.108 ▾
|
ó EYc @ sL d Z d d l m Z m Z d e f d YZ d e f d YZ d S( si Deprecated core event interfaces. This module is **deprecated** and is superseded by the event system. i ( t eventt utilt PoolListenerc B sA e Z d Z e d Z d Z d Z d Z d Z RS( s, Hooks into the lifecycle of connections in a :class:`.Pool`. .. note:: :class:`.PoolListener` is deprecated. Please refer to :class:`.PoolEvents`. Usage:: class MyListener(PoolListener): def connect(self, dbapi_con, con_record): '''perform connect operations''' # etc. # create a new pool with a listener p = QueuePool(..., listeners=[MyListener()]) # add a listener after the fact p.add_listener(MyListener()) # usage with create_engine() e = create_engine("url://", listeners=[MyListener()]) All of the standard connection :class:`~sqlalchemy.pool.Pool` types can accept event listeners for key connection lifecycle events: creation, pool check-out and check-in. There are no events fired when a connection closes. For any given DB-API connection, there will be one ``connect`` event, `n` number of ``checkout`` events, and either `n` or `n - 1` ``checkin`` events. (If a ``Connection`` is detached from its pool via the ``detach()`` method, it won't be checked back in.) These are low-level events for low-level objects: raw Python DB-API connections, without the conveniences of the SQLAlchemy ``Connection`` wrapper, ``Dialect`` services or ``ClauseElement`` execution. If you execute SQL through the connection, explicitly closing all cursors and other resources is recommended. Events also receive a ``_ConnectionRecord``, a long-lived internal ``Pool`` object that basically represents a "slot" in the connection pool. ``_ConnectionRecord`` objects have one public attribute of note: ``info``, a dictionary whose contents are scoped to the lifetime of the DB-API connection managed by the record. You can use this shared storage area however you like. There is no need to subclass ``PoolListener`` to handle events. Any class that implements one or more of these methods can be used as a pool listener. The ``Pool`` will inspect the methods provided by a listener object and add the listener to one or more internal event queues based on its capabilities. In terms of efficiency and function call overhead, you're much better off only providing implementations for the hooks you'll be using. c C s¹ t j | d d } t | d r= t j | d | j n t | d re t j | d | j n t | d r t j | d | j n t | d rµ t j | d | j n d S( s^ Adapt a :class:`.PoolListener` to individual :class:`event.Dispatch` events. t methodst connectt first_connectt checkoutt checkinN( s connects first_connects checkouts checkin( R t as_interfacet hasattrR t listenR R R R ( t clst selft listener( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyt _adapt_listenerL s c C s d S( s( Called once for each new DB-API connection or Pool's ``creator()``. dbapi_con A newly connected raw DB-API connection (not a SQLAlchemy ``Connection`` wrapper). con_record The ``_ConnectionRecord`` that persistently manages the connection N( ( R t dbapi_cont con_record( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyR _ s c C s d S( s Called exactly once for the first DB-API connection. dbapi_con A newly connected raw DB-API connection (not a SQLAlchemy ``Connection`` wrapper). con_record The ``_ConnectionRecord`` that persistently manages the connection N( ( R R R ( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyR k s c C s d S( sC Called when a connection is retrieved from the Pool. dbapi_con A raw DB-API connection con_record The ``_ConnectionRecord`` that persistently manages the connection con_proxy The ``_ConnectionFairy`` which manages the connection for the span of the current checkout. If you raise an ``exc.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. N( ( R R R t con_proxy( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyR w s c C s d S( s£ 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 DB-API connection con_record The ``_ConnectionRecord`` that persistently manages the connection N( ( R R R ( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyR s ( t __name__t __module__t __doc__t classmethodR R R R R ( ( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyR s 7 t ConnectionProxyc B s e Z d Z e d Z d Z d Z d Z d Z d Z d d Z d Z d Z d Z d Z d Z d Z RS( s¾ Allows interception of statement execution by Connections. .. note:: :class:`.ConnectionProxy` is deprecated. Please refer to :class:`.ConnectionEvents`. Either or both of the ``execute()`` and ``cursor_execute()`` may be implemented to intercept compiled statement and cursor level executions, e.g.:: class MyProxy(ConnectionProxy): def execute(self, conn, execute, clauseelement, *multiparams, **params): print "compiled statement:", clauseelement return execute(clauseelement, *multiparams, **params) def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): print "raw statement:", statement return execute(cursor, statement, parameters, context) The ``execute`` argument is a function that will fulfill the default execution behavior for the operation. The signature illustrated in the example should be used. The proxy is installed into an :class:`~sqlalchemy.engine.Engine` via the ``proxy`` argument:: e = create_engine('someurl://', proxy=MyProxy()) c sx f d } t j | d | f d } t j | d | d f d } t j | d | j t j | d | j t j | d | j t j | d | j t j | d | j t j | d | j t j | d | j t j | d | j t j | d | j t j | d | j d S( Nc s" d } j | | | | | S( Nc _ s | | | f S( N( ( t clauseelementt multiparamst params( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyt execute_wrapperÁ s ( t execute( t connR R R R ( R ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyt adapt_execute¿ s t before_executec s% d } j | | | | | | S( Nc S s | | f S( N( ( t cursort statementt parameterst context( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyR Í s ( t cursor_execute( R R R R! R" t executemanyR ( R ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyt adapt_cursor_executeÊ s t before_cursor_executec _ s d S( N( ( t argt kw( ( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyt do_nothing_callbackà s c s" f d } t j | S( Nc s | | | d S( N( ( R R' R( ( R) t fn( sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyt goå s ( R t update_wrapper( R* R+ ( R) ( R* sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyt adapt_listenerã s t begint rollbackt committ savepointt rollback_savepointt release_savepointt begin_twophaset prepare_twophaset rollback_twophaset commit_twophase( R R R. R/ R0 R1 R2 R3 R4 R5 R6 R7 ( R R R R R% R- ( ( R) R sJ /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/interfaces.pyR ¼ s0 c O s | | | | S( s&