60
reset_rollback = util.symbol('reset_rollback')
61
reset_commit = util.symbol('reset_commit')
62
reset_none = util.symbol('reset_none')
61
65
class Pool(log.Identified):
62
66
"""Abstract base class for connection pools."""
130
134
self._creator = creator
131
135
self._recycle = recycle
132
136
self._use_threadlocal = use_threadlocal
133
self._reset_on_return = reset_on_return
137
if reset_on_return in ('rollback', True, reset_rollback):
138
self._reset_on_return = reset_rollback
139
elif reset_on_return in (None, False, reset_none):
140
self._reset_on_return = reset_none
141
elif reset_on_return in ('commit', reset_commit):
142
self._reset_on_return = reset_commit
144
raise exc.ArgumentError(
145
"Invalid value for 'reset_on_return': %r"
136
150
self.dispatch._update(_dispatch, only_propagate=False)
331
345
if connection is not None:
333
if pool._reset_on_return:
347
if pool._reset_on_return is reset_rollback:
334
348
connection.rollback()
349
elif pool._reset_on_return is reset_commit:
335
351
# Immediately close detached instances
336
352
if connection_record is None:
337
353
connection.close()
624
640
:meth:`unique_connection` method is provided to bypass the
625
641
threadlocal behavior installed into :meth:`connect`.
627
:param reset_on_return: If true, reset the database state of
628
connections returned to the pool. This is typically a
629
ROLLBACK to release locks and transaction resources.
630
Disable at your own peril. Defaults to True.
643
:param reset_on_return: Determine steps to take on
644
connections as they are returned to the pool.
645
As of SQLAlchemy 0.7.6, reset_on_return can have any
648
* 'rollback' - call rollback() on the connection,
649
to release locks and transaction resources.
650
This is the default value. The vast majority
651
of use cases should leave this value set.
652
* True - same as 'rollback', this is here for
653
backwards compatibility.
654
* 'commit' - call commit() on the connection,
655
to release locks and transaction resources.
656
A commit here may be desirable for databases that
657
cache query plans if a commit is emitted,
658
such as Microsoft SQL Server. However, this
659
value is more dangerous than 'rollback' because
660
any data changes present on the transaction
661
are committed unconditionally.
662
* None - don't do anything on the connection.
663
This setting should only be made on a database
664
that has no transaction support at all,
665
namely MySQL MyISAM. By not doing anything,
666
performance can be improved. This
667
setting should **never be selected** for a
668
database that supports transactions,
669
as it will lead to deadlocks and stale
671
* False - same as None, this is here for
672
backwards compatibility.
632
674
:param listeners: A list of
633
675
:class:`~sqlalchemy.interfaces.PoolListener`-like objects or
634
676
dictionaries of callables that receive events when DB-API