~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/pool.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2012-03-15 21:05:49 UTC
  • mfrom: (1.4.19)
  • Revision ID: package-import@ubuntu.com-20120315210549-fiuynu6jue9keqlh
Tags: 0.7.6-1
* New upstream release
* debhelper's compatibility bumped to 7
* Standards-Version bumped to 3.9.3 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
        manager.close()
58
58
    proxies.clear()
59
59
 
 
60
reset_rollback = util.symbol('reset_rollback')
 
61
reset_commit = util.symbol('reset_commit')
 
62
reset_none = util.symbol('reset_none')
 
63
 
60
64
 
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
 
143
        else:
 
144
            raise exc.ArgumentError(
 
145
                        "Invalid value for 'reset_on_return': %r" 
 
146
                                    % reset_on_return)
 
147
 
134
148
        self.echo = echo
135
149
        if _dispatch:
136
150
            self.dispatch._update(_dispatch, only_propagate=False)
330
344
 
331
345
    if connection is not None:
332
346
        try:
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:
 
350
                connection.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`.
626
642
 
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.
631
 
 
 
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 
 
646
          of these values:
 
647
          
 
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
 
670
             state.
 
671
            * False - same as None, this is here for
 
672
              backwards compatibility.
 
673
          
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