diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-07-02 13:14:21 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-07-02 13:14:21 -0400 |
commit | d3d10c982c8a44c85a0114c491207297eac7611d (patch) | |
tree | bdfda394fb23cc8d65c0acb77ca070937d93580a /lib/sqlalchemy/engine/base.py | |
parent | 38c5e870a7883df0ae104df828217e326f6cff6a (diff) | |
download | sqlalchemy-d3d10c982c8a44c85a0114c491207297eac7611d.tar.gz |
- refactor pool a bit so that intent between ConnectionRecord/ConnectionFairy is clear;
make sure that the DBAPI connection passed to the reset-on-return events/dialect hooks
is also a "fairy", so that dictionaries like "info" are available. [ticket:2770]
- rework the execution_options system so that the dialect is given the job of making
any immediate adjustments based on a set event. move the "isolation level" logic to use
this new system. Also work things out so that even engine-level execution options
can be used for things like isolation level; the dialect attaches a connect-event
handler in this case to handle the task.
- to support this new system as well as further extensibiltiy of execution options
add events engine_connect(), set_connection_execution_options(), set_engine_execution_options()
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 2d9f3af94..f69bd3d4b 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -46,7 +46,7 @@ class Connection(Connectable): def __init__(self, engine, connection=None, close_with_result=False, _branch=False, _execution_options=None, _dispatch=None, - _has_events=False): + _has_events=None): """Construct a new Connection. The constructor here is not public and is only called only by an @@ -67,7 +67,8 @@ class Connection(Connectable): self.dispatch = _dispatch elif engine._has_events: self.dispatch = self.dispatch._join(engine.dispatch) - self._has_events = _has_events or engine._has_events + self._has_events = _has_events or ( + _has_events is None and engine._has_events) self._echo = self.engine._should_log_info() if _execution_options: @@ -76,6 +77,9 @@ class Connection(Connectable): else: self._execution_options = engine._execution_options + if self._has_events: + self.dispatch.engine_connect(self, _branch) + def _branch(self): """Return a new Connection which references this Connection's engine and connection; but does not have close_with_result enabled, @@ -200,16 +204,11 @@ class Connection(Connectable): """ c = self._clone() c._execution_options = c._execution_options.union(opt) - if 'isolation_level' in opt: - c._set_isolation_level() + if self._has_events: + self.dispatch.set_connection_execution_options(c, opt) + self.dialect.set_connection_execution_options(c, opt) return c - def _set_isolation_level(self): - self.dialect.set_isolation_level(self.connection, - self._execution_options['isolation_level']) - self.connection._connection_record.finalize_callback = \ - self.dialect.reset_isolation_level - @property def closed(self): """Return True if this connection is closed.""" @@ -1336,15 +1335,10 @@ class Engine(Connectable, log.Identified): :meth:`.Engine.execution_options` """ - if 'isolation_level' in opt: - raise exc.ArgumentError( - "'isolation_level' execution option may " - "only be specified on Connection.execution_options(). " - "To set engine-wide isolation level, " - "use the isolation_level argument to create_engine()." - ) self._execution_options = \ self._execution_options.union(opt) + self.dispatch.set_engine_execution_options(self, opt) + self.dialect.set_engine_execution_options(self, opt) def execution_options(self, **opt): """Return a new :class:`.Engine` that will provide |