Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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:
9296e69
60c88e6
  • Loading branch information...
commit 368525a5a5b43a2955d063c2f81af5d6ed1c2188 1 parent 3f4e97f
Arthur Nogueira Neves arthurnn authored
33 activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
View
@@ -78,45 +78,28 @@ def initialize(connection, parent, options = {})
@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 @@ def perform_commit
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
4 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
View
@@ -357,7 +357,9 @@ def case_insensitive_comparison(table, attribute, column, value)
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
Please sign in to comment.
Something went wrong with that request. Please try again.