From 5b2cc84aa8d43c503b24bf5342c0babeed5d6d83 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 20 Mar 2007 23:29:31 +0000 Subject: [PATCH] contextual_connection() -> contextual_connect() [ticket:515] --- doc/build/content/dbengine.txt | 14 +++++++------- doc/build/content/unitofwork.txt | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/build/content/dbengine.txt b/doc/build/content/dbengine.txt index e20eb4250a..ae818ec03b 100644 --- a/doc/build/content/dbengine.txt +++ b/doc/build/content/dbengine.txt @@ -326,19 +326,19 @@ Using the "threadlocal" strategy, all calls to `execute` within the same thread # are returned to the pool. r2 = None -To get at the actual `Connection` object which is used by implicit executions, call the `contextual_connection()` method on `Engine`: +To get at the actual `Connection` object which is used by implicit executions, call the `contextual_connect()` method on `Engine`: {python title="Contextual Connection"} # threadlocal strategy db = create_engine('mysql://localhost/test', strategy='threadlocal') - conn1 = db.contextual_connection() - conn2 = db.contextual_connection() + conn1 = db.contextual_connect() + conn2 = db.contextual_connect() >>> conn1.connection is conn2.connection True -When the `plain` strategy is used, the `contextual_connection()` method is synonymous with the `connect()` method; both return a distinct connection from the pool. +When the `plain` strategy is used, the `contextual_connect()` method is synonymous with the `connect()` method; both return a distinct connection from the pool. One programming pattern that the `threadlocal` strategy supports is transparent connection and transaction sharing. @@ -351,13 +351,13 @@ One programming pattern that the `threadlocal` strategy supports is transparent def dosomethingelse(): table2.execute("some sql") - conn = db.contextual_connection() + conn = db.contextual_connect() # do stuff with conn conn.execute("some other sql") conn.close() def dosomethingtransactional(): - conn = db.contextual_connection() + conn = db.contextual_connect() trans = conn.begin() # do stuff trans.commit() @@ -371,5 +371,5 @@ One programming pattern that the `threadlocal` strategy supports is transparent except: db.rollback() -In the above example, the program calls three functions `dosomethingimplicit()`, `dosomethingelse()` and `dosomethingtransactional()`. In all three functions, either implicit execution is used, **or** an explicit `Connection` is used via the `contextual_connection()` method. This indicates that they all will share the same underlying dbapi connection as well as the same parent `Transaction` instance, which is created in the main body of the program via the call to `db.create_transaction()`. So while there are several calls that return "new" `Transaction` or `Connection` objects, in reality only one "real" connection is ever used, and there is only one transaction (i.e. one begin/commit pair) executed. +In the above example, the program calls three functions `dosomethingimplicit()`, `dosomethingelse()` and `dosomethingtransactional()`. In all three functions, either implicit execution is used, **or** an explicit `Connection` is used via the `contextual_connect()` method. This indicates that they all will share the same underlying dbapi connection as well as the same parent `Transaction` instance, which is created in the main body of the program via the call to `db.create_transaction()`. So while there are several calls that return "new" `Transaction` or `Connection` objects, in reality only one "real" connection is ever used, and there is only one transaction (i.e. one begin/commit pair) executed. diff --git a/doc/build/content/unitofwork.txt b/doc/build/content/unitofwork.txt index ddf4bbe473..261799e41b 100644 --- a/doc/build/content/unitofwork.txt +++ b/doc/build/content/unitofwork.txt @@ -422,7 +422,7 @@ The other way is just to use the `Connection` referenced by the `SessionTransact raise trans.commit() -The `connection()` method also exists on the `Session` object itself, and can be called regardless of whether or not a `SessionTransaction` is in progress. If a `SessionTransaction` is in progress, it will return the connection referenced by the transaction. If an `Engine` is being used with `threadlocal` strategy, the `Connection` returned will correspond to the connection resources that are bound to the current thread, if any (i.e. it is obtained by calling `contextual_connection()`). +The `connection()` method also exists on the `Session` object itself, and can be called regardless of whether or not a `SessionTransaction` is in progress. If a `SessionTransaction` is in progress, it will return the connection referenced by the transaction. If an `Engine` is being used with `threadlocal` strategy, the `Connection` returned will correspond to the connection resources that are bound to the current thread, if any (i.e. it is obtained by calling `contextual_connect()`). #### Using Engine-level Transactions with Sessions -- 2.47.2