Part of twisted.enterprise.adbapi View Source View In Hierarchy
|Instance Variables||connectionFactory||factory for connections, default to |
|transactionFactory||factory for transactions, default to |
|Method||__init__||Create a new ConnectionPool.|
|Method||start||Start the connection pool.|
|Method||runWithConnection||Execute a function with a database connection and return the result.|
|Method||runInteraction||Interact with the database and return the result.|
|Method||runQuery||Execute an SQL query and return the result.|
|Method||runOperation||Execute an SQL query and return None.|
|Method||close||Close all pool connections and shutdown the pool.|
|Method||finalClose||This should only be called by the shutdown trigger.|
|Method||connect||Return a database connection when one becomes available.|
|Method||disconnect||Disconnect a database connection associated with this pool.|
Create a new ConnectionPool.Any positional or keyword arguments other than those documented here are passed to the DB-API object when connecting. Use these arguments to pass database names, usernames, passwords, etc.
|Parameters||dbapiName||an import string to use to obtain a DB-API compatible module (e.g. 'pyPgSQL.PgSQL')|
|cp_min||the minimum number of connections in pool (default 3)|
|cp_max||the maximum number of connections in pool (default 5)|
|cp_noisy||generate informational log messages during operation (default False)|
|cp_openfun||a callback invoked after every connect() on the underlying DB-API object. The callback is passed a new DB-API connection object. This callback can setup per-connection state such as charset, timezone, etc.|
|cp_reconnect||detect connections which have failed and reconnect (default False). Failed connections may result in ConnectionLost exceptions, which indicate the query may need to be re-sent.|
|cp_good_sql||an sql query which should always succeed and change no state (default 'select 1')|
Start the connection pool.If you are using the reactor normally, this function does *not* need to be called.
|Parameters||func||A callable object of one argument which will be executed in a thread
with a connection from the pool. It will be passed as its first argument a
|*args||positional arguments to be passed to func|
|**kw||keyword arguments to be passed to func|
|Returns||a Deferred which will fire the return value of
Interact with the database and return the result.
The 'interaction' is a callable object which will be executed in a
thread using a pooled connection. It will be passed an
object as an argument (whose interface is identical to that of the database
cursor for your DB-API module of choice), and its results will be returned
as a Deferred. If running the method raises an exception, the transaction
will be rolled back. If the method returns a value, the transaction will be
|Parameters||interaction||a callable object whose first argument is an |
|*args||additional positional arguments to be passed to interaction|
|**kw||keyword arguments to be passed to interaction|
|Returns||a Deferred which will fire the return value of 'interaction(Transaction(...), *args, **kw)', or a Failure.|
Execute an SQL query and return the result.
A DB-API cursor will will be invoked with cursor.execute(*args, **kw). The exact nature of the arguments will depend on the specific flavor of DB-API being used, but the first argument in *args be an SQL statement. The result of a subsequent cursor.fetchall() will be fired to the Deferred which is returned. If either the 'execute' or 'fetchall' methods raise an exception, the transaction will be rolled back and a Failure returned.The *args and **kw arguments will be passed to the DB-API cursor's 'execute' method.
|Returns||a Deferred which will fire the return value of a DB-API cursor's 'fetchall' method, or a Failure.|
Execute an SQL query and return None.
A DB-API cursor will will be invoked with cursor.execute(*args, **kw). The exact nature of the arguments will depend on the specific flavor of DB-API being used, but the first argument in *args will be an SQL statement. This method will not attempt to fetch any results from the query and is thus suitable for INSERT, DELETE, and other SQL statements which do not return values. If the 'execute' method raises an exception, the transaction will be rolled back and a Failure returned.
The args and kw arguments will be passed to the DB-API cursor's 'execute' method.return: a Deferred which will fire None or a Failure.
Return a database connection when one becomes available.This method blocks and should be run in a thread from the internal threadpool. Don't call this method directly from non-threaded code. Using this method outside the external threadpool may exceed the maximum number of connections in the pool.
|Returns||a database connection from the pool.|
Disconnect a database connection associated with this pool.Note: This function should only be used by the same thread which called connect(). As with connect(), this function is not used in normal non-threaded twisted code.