From ebbe4fb0d41feb45628715cd045d89e7bb8ab117 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Fri, 18 May 2007 01:02:08 +0000 Subject: Replace the transaction {|transaction|..} semantics with a new Exception ActiveRecord::Rollback. Closes #8030 [Koz] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6754 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ activerecord/lib/active_record/base.rb | 2 ++ .../connection_adapters/abstract/database_statements.rb | 11 +++-------- activerecord/test/transactions_test.rb | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 1e22280a1f..e1f6a91de4 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Replace the transaction {|transaction|..} semantics with a new Exception ActiveRecord::Rollback. [Koz] + * Oracle: extract column length for CHAR also. #7866 [ymendel] * Document :allow_nil option for validates_acceptance_of since it defaults to true. [tzaharia] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index bb3c58067d..31b25e5979 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -34,6 +34,8 @@ module ActiveRecord #:nodoc: end class ReadOnlyRecord < StandardError #:nodoc: end + class Rollback < StandardError #:nodoc: + end class AttributeAssignmentError < ActiveRecordError #:nodoc: attr_reader :exception, :attribute diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 1b75ab53fe..bc59f064aa 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -56,14 +56,14 @@ module ActiveRecord begin_db_transaction transaction_open = true end - yield self - end + yield + end rescue Exception => database_transaction_rollback if transaction_open transaction_open = false rollback_db_transaction end - raise + raise unless database_transaction_rollback.is_a? ActiveRecord::Rollback end ensure commit_db_transaction if transaction_open @@ -79,11 +79,6 @@ module ActiveRecord # done if the transaction block raises an exception or returns false. def rollback_db_transaction() end - # Alias for rollback_db_transaction to be used when yielding the transaction - def rollback! - rollback_db_transaction - end - # Alias for #add_limit_offset!. def add_limit!(sql, options) add_limit_offset!(sql, options) if options diff --git a/activerecord/test/transactions_test.rb b/activerecord/test/transactions_test.rb index 098e01c945..c23f405914 100644 --- a/activerecord/test/transactions_test.rb +++ b/activerecord/test/transactions_test.rb @@ -149,13 +149,13 @@ class TransactionTest < Test::Unit::TestCase end def test_manually_rolling_back_a_transaction - Topic.transaction do |transaction| + Topic.transaction do @first.approved = true @second.approved = false @first.save @second.save - transaction.rollback! + raise ActiveRecord::Rollback end assert @first.approved?, "First should still be changed in the objects" -- cgit v1.2.3