diff options
author | Arthur Neves <arthurnn@gmail.com> | 2014-07-24 16:25:34 -0400 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2014-07-24 16:25:34 -0400 |
commit | 368525a5a5b43a2955d063c2f81af5d6ed1c2188 (patch) | |
tree | b33947db55e08c993ca827d7dce3ea570bedbfdb /activerecord | |
parent | 3f4e97f807eb475ac8c311e5baf138249a8a1ab2 (diff) | |
download | rails-368525a5a5b43a2955d063c2f81af5d6ed1c2188.tar.gz rails-368525a5a5b43a2955d063c2f81af5d6ed1c2188.tar.bz2 rails-368525a5a5b43a2955d063c2f81af5d6ed1c2188.zip |
Remove finishing? method from transaction.
The finishing variable on the transaction object was a work-around for
the savepoint name, so after a rollback/commit the savepoint could be
released with the previous name.
related:
9296e6939bcc786149a07dac334267c4035b623a
60c88e64e26682a954f7c8cd6669d409ffffcc8b
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/transaction.rb | 33 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 4 |
2 files changed, 13 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb index bc4884b538..1721437615 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb @@ -78,45 +78,28 @@ module ActiveRecord @parent = parent @records = [] - @finishing = false @joinable = options.fetch(:joinable, true) end - # This state is necessary so that we correctly handle stuff that might - # happen in a commit/rollback. But it's kinda distasteful. Maybe we can - # find a better way to structure it in the future. - def finishing? - @finishing - end def joinable? - @joinable && !finishing? + @joinable end def number - if finishing? - parent.number - else - parent.number + 1 - end + parent.number + 1 end def begin(options = {}) - if finishing? - parent.begin - else - SavepointTransaction.new(connection, self, options) - end + SavepointTransaction.new(connection, self, options) end def rollback - @finishing = true perform_rollback parent end def commit - @finishing = true perform_commit parent end @@ -183,24 +166,28 @@ module ActiveRecord end class SavepointTransaction < OpenTransaction #:nodoc: + attr_reader :savepoint_name + def initialize(connection, parent, options = {}) if options[:isolation] raise ActiveRecord::TransactionIsolationError, "cannot set transaction isolation in a nested transaction" end super - connection.create_savepoint + + @savepoint_name = "active_record_#{number}" + connection.create_savepoint(@savepoint_name) end def perform_rollback - connection.rollback_to_savepoint + connection.rollback_to_savepoint(@savepoint_name) rollback_records end def perform_commit @state.set_state(:committed) @state.parent = parent.state - connection.release_savepoint + connection.release_savepoint(@savepoint_name) end end end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index f8c054eb69..1397358f79 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -357,7 +357,9 @@ module ActiveRecord end def current_savepoint_name - "active_record_#{open_transactions}" + if current_transaction.is_a? SavepointTransaction + current_transaction.savepoint_name + end end # Check the connection back in to the connection pool |