]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added unique_connection() method to engine, connection pool to return a connection
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Mar 2006 19:51:03 +0000 (19:51 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Mar 2006 19:51:03 +0000 (19:51 +0000)
that is not part of the thread-local context or any current transaction

CHANGES
lib/sqlalchemy/engine.py
lib/sqlalchemy/pool.py

diff --git a/CHANGES b/CHANGES
index 3ac27f1999df14164aeeddfdfe45e42166dcfbc3..8810b1db16bc64461bd5abeb56c7eee14bb4500f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
 0.1.5
 - fixed attributes bug where if an object is committed, its lazy-loaded list got 
 blown away if it hadnt been loaded
+- added unique_connection() method to engine, connection pool to return a connection
+that is not part of the thread-local context or any current transaction
 
 0.1.4
 - create_engine() now uses genericized parameters; host/hostname, db/dbname/database, 
index 8a29b847fc7a5ec469f0f84012a19005a46feb96..44ffadfeb3b9b30a395935e9d817eb8d43c2b57d 100644 (file)
@@ -395,6 +395,10 @@ class SQLEngine(schema.SchemaEngine):
         """returns a managed DBAPI connection from this SQLEngine's connection pool."""
         return self._pool.connect()
 
+    def unique_connection(self):
+        """returns a DBAPI connection from this SQLEngine's connection pool that is distinct from the current thread's connection."""
+        return self._pool.unique_connection()
+        
     def multi_transaction(self, tables, func):
         """provides a transaction boundary across tables which may be in multiple databases.
         If you have three tables, and a function that operates upon them, providing the tables as a 
index 783b4450bf943300f4b2d9d6d98b914250b6bb15..ad65f7462a6b6a25198c587843ffa1eedf61076d 100644 (file)
@@ -75,7 +75,10 @@ class Pool(object):
         self._use_threadlocal = use_threadlocal
         self._echo = echo
         self._logger = logger or util.Logger(origin='pool')
-        
+    
+    def unique_connection(self):
+        return ConnectionFairy(self)
+            
     def connect(self):
         if not self._use_threadlocal:
             return ConnectionFairy(self)
@@ -120,14 +123,17 @@ class Pool(object):
         self.logger.write(msg)
 
 class ConnectionFairy(object):
-    def __init__(self, pool):
+    def __init__(self, pool, connection=None):
         self.pool = pool
-        try:
-            self.connection = pool.get()
-        except:
-            self.connection = None
-            self.pool.return_invalid()
-            raise
+        if connection is not None:
+            self.connection = connection
+        else:
+            try:
+                self.connection = pool.get()
+            except:
+                self.connection = None
+                self.pool.return_invalid()
+                raise
     def cursor(self):
         return CursorFairy(self, self.connection.cursor())
     def __getattr__(self, key):
@@ -157,6 +163,9 @@ class SingletonThreadPool(Pool):
     def status(self):
         return "SingletonThreadPool size: %d" % len(self._conns)
 
+    def unique_connection(self):
+        return ConnectionFairy(self, self._creator())
+
     def do_return_conn(self, conn):
         pass
     def do_return_invalid(self):