]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
removed ConnectionProvider. engines have a "pool" attribute now.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Jun 2007 20:58:08 +0000 (20:58 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Jun 2007 20:58:08 +0000 (20:58 +0000)
doc/build/content/dbengine.txt
doc/build/gen_docstrings.py
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/engine/strategies.py
lib/sqlalchemy/engine/threadlocal.py
test/engine/parseconnect.py
test/engine/reconnect.py

index a3cc899e334741aacfd3421789f6f36ae8983e17..412a0c7a71a143c6fb2603e5912b60619c81259f 100644 (file)
@@ -13,9 +13,9 @@ A database engine is a subclass of `sqlalchemy.sql.Engine`, and is the starting
 Underneath the public-facing API of `Engine`, several components are provided by database implementations to provide the full behavior, including:
 
 * [Dialect](boldrel:docstrings_sqlalchemy.engine_Dialect) - this object is provided by database implementations to describe the behavior of a particular database.  It acts as a repository for metadata about a database's characteristics, and provides factory methods for other objects that deal with generating SQL strings and objects that handle some of the details of statement execution.  
-* [ConnectionProvider](boldrel:docstrings_sqlalchemy.engine_ConnectionProvider) - this object knows how to return a DBAPI connection object.  It typically talks to a connection pool which maintains one or more connections in memory for quick re-use.
+* [Pool](boldrel:docstrings_sqlalchemy.pool_Pool) - provides DBAPI connections from a managed pool of connections.  All `Engine` objects use a connection pool, which can be provided by a variety of different backend strategies.  The most common is [QueuePool](rel:docstrings_sqlalchemy.pool_QueuePool).
 * [ExecutionContext](boldrel:docstrings_sqlalchemy.engine_ExecutionContext) - this object is created for each execution of a single SQL statement, and tracks information about its execution such as primary keys inserted, the total count of rows affected, etc.  It also may implement any special logic that various DBAPI implementations may require before or after a statement execution.
-* [Compiled](boldrel:docstrings_sqlalchemy.sql_Compiled) - represents a "compiled" SQL expression object.  Includes a `compile()` method which receives SQL expression objects and assembles them into strings that are suitable for direct execution.  Also collects default bind parameters into a datastructure that will be converted at execution time into a dictionary or list, depending on the dialect's paramstyle.
+* [Compiled](boldrel:docstrings_sqlalchemy.engine_Compiled) - represents a "compiled" SQL expression object.  Includes a `compile()` method which receives SQL expression objects and assembles them into strings that are suitable for direct execution.  Also collects default bind parameters into a datastructure that will be converted at execution time into a dictionary or list, depending on the dialect's paramstyle.
 
 ### Supported Databases {@name=supported}
 
index 6b370fe80dc02d3c48793d1f920d510ec17f256c..85e47a3f0c49e218c1f095a89e688c9b211c9a2f 100644 (file)
@@ -3,7 +3,6 @@ import docstring
 import re
 
 from sqlalchemy import schema, types, ansisql, engine, sql, pool, orm, exceptions, databases
-import sqlalchemy.ext.proxy as proxy
 import sqlalchemy.ext.sessioncontext as sessioncontext
 import sqlalchemy.mods.threadlocal as threadlocal
 import sqlalchemy.ext.selectresults as selectresults
@@ -38,7 +37,6 @@ def make_all_docs():
         make_doc(obj=sessioncontext),
         make_doc(obj=threadlocal),
         make_doc(obj=selectresults),
-        make_doc(obj=proxy),
         make_doc(obj=orderinglist, classes=[orderinglist.OrderingList]),
         make_doc(obj=associationproxy, classes=[associationproxy.AssociationProxy]),
     ] + [make_doc(getattr(__import__('sqlalchemy.databases.%s' % m).databases, m)) for m in databases.__all__]
index de4d6b2aeb16cb6a16853eca8676f82f102605a3..f318cf4b32f3db296d3f1404e0b36ea9b7020b3c 100644 (file)
@@ -12,29 +12,6 @@ from sqlalchemy import exceptions, sql, schema, util, types, logging
 import StringIO, sys, re
 
 
-class ConnectionProvider(object):
-    """Define an interface that returns raw Connection objects (or compatible)."""
-
-    def get_connection(self):
-        """Return a Connection or compatible object from a DBAPI which also contains a close() method.
-
-        It is not defined what context this connection belongs to.  It
-        may be newly connected, returned from a pool, part of some
-        other kind of context such as thread-local, or can be a fixed
-        member of this object.
-        """
-
-        raise NotImplementedError()
-
-    def dispose(self):
-        """Release all resources corresponding to this ConnectionProvider.
-
-        This includes any underlying connection pools.
-        """
-
-        raise NotImplementedError()
-
-
 class Dialect(sql.AbstractDialect):
     """Define the behavior of a specific database/DBAPI.
 
@@ -677,7 +654,7 @@ class Connection(Connectable):
         except Exception, e:
             if self.dialect.is_disconnect(e):
                 self.__connection.invalidate(e=e)
-                self.engine.connection_provider.dispose()
+                self.engine.dispose()
             self._autorollback()
             if self.__close_with_result:
                 self.close()
@@ -689,7 +666,7 @@ class Connection(Connectable):
         except Exception, e:
             if self.dialect.is_disconnect(e):
                 self.__connection.invalidate(e=e)
-                self.engine.connection_provider.dispose()
+                self.engine.dispose()
             self._autorollback()
             if self.__close_with_result:
                 self.close()
@@ -759,12 +736,13 @@ class Transaction(object):
 
 class Engine(Connectable):
     """
-    Connects a ConnectionProvider, a Dialect and a CompilerFactory together to
+    Connects a Pool, a Dialect and a CompilerFactory together to
     provide a default implementation of SchemaEngine.
     """
 
-    def __init__(self, connection_provider, dialect, echo=None):
-        self.connection_provider = connection_provider
+    def __init__(self, pool, dialect, url, echo=None):
+        self.pool = pool
+        self.url = url
         self._dialect=dialect
         self.echo = echo
         self.logger = logging.instance_logger(self)
@@ -773,10 +751,10 @@ class Engine(Connectable):
     engine = property(lambda s:s)
     dialect = property(lambda s:s._dialect, doc="the [sqlalchemy.engine#Dialect] in use by this engine.")
     echo = logging.echo_property()
-    url = property(lambda s:s.connection_provider.url, doc="The [sqlalchemy.engine.url#URL] object representing this ``Engine`` object's datasource.")
     
     def dispose(self):
-        self.connection_provider.dispose()
+        self.pool.dispose()
+        self.pool = self.pool.recreate()
 
     def create(self, entity, connection=None, **kwargs):
         """Create a table or index within this engine's database connection given a schema.Table object."""
@@ -899,7 +877,7 @@ class Engine(Connectable):
     def raw_connection(self):
         """Return a DBAPI connection."""
 
-        return self.connection_provider.get_connection()
+        return self.pool.connect()
 
     def log(self, msg):
         """Log a message using this SQLEngine's logger stream."""
index 64c5de2b0afe6c2c5a4ccac5080434d0a22be39f..3633473cd5606f0dc3c21576b39bcbef8f7e3218 100644 (file)
@@ -11,17 +11,6 @@ from sqlalchemy.engine import base
 
 """Provide default implementations of the engine interfaces"""
 
-class PoolConnectionProvider(base.ConnectionProvider):
-    def __init__(self, url, pool):
-        self.url = url
-        self._pool = pool
-
-    def get_connection(self):
-        return self._pool.connect()
-
-    def dispose(self):
-        self._pool.dispose()
-        self._pool = self._pool.recreate()
         
 class DefaultDialect(base.Dialect):
     """Default implementation of Dialect"""
index 7d85de9addf48c81fdb627e511b87ceaef6bf18a..9dea32e84977b17fe78a4c3b5e30915de9ae423c 100644 (file)
@@ -92,8 +92,6 @@ class DefaultEngineStrategy(EngineStrategy):
             else:
                 pool = pool
 
-        provider = self.get_pool_provider(u, pool)
-
         # create engine.
         engineclass = self.get_engine_cls()
         engine_args = {}
@@ -105,14 +103,11 @@ class DefaultEngineStrategy(EngineStrategy):
         if len(kwargs):
             raise TypeError("Invalid argument(s) %s sent to create_engine(), using configuration %s/%s/%s.  Please check that the keyword arguments are appropriate for this combination of components." % (','.join(["'%s'" % k for k in kwargs]), dialect.__class__.__name__, pool.__class__.__name__, engineclass.__name__))
 
-        return engineclass(provider, dialect, **engine_args)
+        return engineclass(pool, dialect, u, **engine_args)
 
     def pool_threadlocal(self):
         raise NotImplementedError()
 
-    def get_pool_provider(self, url, pool):
-        raise NotImplementedError()
-
     def get_engine_cls(self):
         raise NotImplementedError()
 
@@ -123,9 +118,6 @@ class PlainEngineStrategy(DefaultEngineStrategy):
     def pool_threadlocal(self):
         return False
 
-    def get_pool_provider(self, url, pool):
-        return default.PoolConnectionProvider(url, pool)
-
     def get_engine_cls(self):
         return base.Engine
 
@@ -138,9 +130,6 @@ class ThreadLocalEngineStrategy(DefaultEngineStrategy):
     def pool_threadlocal(self):
         return True
 
-    def get_pool_provider(self, url, pool):
-        return threadlocal.TLocalConnectionProvider(url, pool)
-
     def get_engine_cls(self):
         return threadlocal.TLEngine
 
index 2bbb1ed43ae6cf4714b182f5b3c46e27f507e798..35313271bad39a62bd7a46864a56c07b3fb585f3 100644 (file)
@@ -112,7 +112,7 @@ class TLEngine(base.Engine):
     """
 
     def __init__(self, *args, **kwargs):
-        """The TLEngine relies upon the ConnectionProvider having
+        """The TLEngine relies upon the Pool having
         "threadlocal" behavior, so that once a connection is checked out
         for the current thread, you get that same connection
         repeatedly.
@@ -124,7 +124,7 @@ class TLEngine(base.Engine):
     def raw_connection(self):
         """Return a DBAPI connection."""
 
-        return self.connection_provider.get_connection()
+        return self.pool.connect()
 
     def connect(self, **kwargs):
         """Return a Connection that is not thread-locally scoped.
@@ -133,7 +133,7 @@ class TLEngine(base.Engine):
         ComposedSQLEngine.
         """
 
-        return base.Connection(self, self.connection_provider.unique_connection())
+        return base.Connection(self, self.pool.unique_connection())
 
     def _session(self):
         if not hasattr(self.context, 'session'):
@@ -156,6 +156,3 @@ class TLEngine(base.Engine):
     def rollback(self):
         self.session.rollback()
 
-class TLocalConnectionProvider(default.PoolConnectionProvider):
-    def unique_connection(self):
-        return self._pool.unique_connection()
index 967a20ed5d02b6814d20e0cede79181590454e1e..f393b9f7d015e1e3bde329144b7a1d0f02cd639a 100644 (file)
@@ -65,7 +65,7 @@ class CreateEngineTest(PersistTest):
     def testrecycle(self):
         dbapi = MockDBAPI(foober=12, lala=18, hoho={'this':'dict'}, fooz='somevalue')
         e = create_engine('postgres://', pool_recycle=472, module=dbapi)
-        assert e.connection_provider._pool._recycle == 472
+        assert e.pool._recycle == 472
         
     def testbadargs(self):
         # good arg, use MockDBAPI to prevent oracle import errors
@@ -139,8 +139,8 @@ class CreateEngineTest(PersistTest):
     def testpoolargs(self):
         """test that connection pool args make it thru"""
         e = create_engine('postgres://', creator=None, pool_recycle=-1, echo_pool=None, auto_close_cursors=False, disallow_open_cursors=True, module=MockDBAPI())
-        assert e.connection_provider._pool.auto_close_cursors is False
-        assert e.connection_provider._pool.disallow_open_cursors is True
+        assert e.pool.auto_close_cursors is False
+        assert e.pool.disallow_open_cursors is True
 
         # these args work for QueuePool
         e = create_engine('postgres://', max_overflow=8, pool_timeout=60, poolclass=pool.QueuePool, module=MockDBAPI())
index defc878ab34e4306ac20e6255720f34d9a0514f3..1c8594d0eeb3918e451a1fd1b42a98072a065fe3 100644 (file)
@@ -50,7 +50,7 @@ class ReconnectTest(testbase.PersistTest):
         # monkeypatch disconnect checker
         db.dialect.is_disconnect = lambda e: isinstance(e, MockDisconnect)
         
-        pid = id(db.connection_provider._pool)
+        pid = id(db.pool)
         
         # make a connection
         conn = db.connect()
@@ -81,7 +81,7 @@ class ReconnectTest(testbase.PersistTest):
         # close shouldnt break
         conn.close()
 
-        assert id(db.connection_provider._pool) != pid
+        assert id(db.pool) != pid
         
         # ensure all connections closed (pool was recycled)
         assert len(dbapi.connections) == 0