Skip to content

Commit

Permalink
still need to track whether we're the toplevel transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Sep 4, 2008
1 parent 045713e commit 039d78a
Showing 1 changed file with 10 additions and 3 deletions.
Expand Up @@ -529,17 +529,24 @@ def transaction_active?


# Wrap a block in a transaction. Returns result of block. # Wrap a block in a transaction. Returns result of block.
def transaction(start_db_transaction = true) def transaction(start_db_transaction = true)
transaction_open = false
begin begin
if block_given? if block_given?
begin_db_transaction if start_db_transaction if start_db_transaction
begin_db_transaction
transaction_open = true
end
yield yield
end end
rescue Exception => database_transaction_rollback rescue Exception => database_transaction_rollback
rollback_db_transaction if transaction_active? if transaction_open && transaction_active?
transaction_open = false
rollback_db_transaction
end
raise unless database_transaction_rollback.is_a? ActiveRecord::Rollback raise unless database_transaction_rollback.is_a? ActiveRecord::Rollback
end end
ensure ensure
if transaction_active? if transaction_open && transaction_active?
begin begin
commit_db_transaction commit_db_transaction
rescue Exception => database_transaction_rollback rescue Exception => database_transaction_rollback
Expand Down

0 comments on commit 039d78a

Please sign in to comment.