Changeset 6439
- Timestamp:
- 03/16/07 22:39:01 (1 year ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/transactions.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/vendor/simple.rb (deleted)
- trunk/activerecord/test/transactions_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6433 r6439 1 1 *SVN* 2 3 * Remove deprecated object transactions. People relying on this functionality should install the object_transactions plugin at http://code.bitsweat.net/svn/object_transactions. Closes #5637 [Koz, Jeremy Kemper] 2 4 3 5 * PostgreSQL: remove DateTime -> Time downcast. Warning: do not enable translate_results for the C bindings if you have timestamps outside Time's domain. [Jeremy Kemper] trunk/activerecord/lib/active_record/transactions.rb
r6196 r6439 1 require 'active_record/vendor/simple.rb'2 Transaction::Simple.send(:remove_method, :transaction)3 1 require 'thread' 4 2 … … 67 65 # depend on or you can raise exceptions in the callbacks to rollback. 68 66 # 69 # == Object-level transactions (deprecated)70 #71 # You can enable object-level transactions for Active Record objects, though. You do this by naming each of the Active Records72 # that you want to enable object-level transactions for, like this:73 #74 # Account.transaction(david, mary) do75 # david.withdrawal(100)76 # mary.deposit(100)77 # end78 #79 # If the transaction fails, David and Mary will be returned to their80 # pre-transactional state. No money will have changed hands in neither81 # object nor database.82 #83 # However, useful state such as validation errors are also rolled back,84 # limiting the usefulness of this feature. As such it is deprecated in85 # Rails 1.2 and will be removed in the next release. Install the86 # object_transactions plugin if you wish to continue using it.87 #88 67 # == Exception handling 89 68 # 90 69 # Also have in mind that exceptions thrown within a transaction block will be propagated (after triggering the ROLLBACK), so you 91 70 # should be ready to catch those in your application code. 92 #93 # Tribute: Object-level transactions are implemented by Transaction::Simple by Austin Ziegler.94 71 module ClassMethods 95 def transaction( *objects,&block)72 def transaction(&block) 96 73 previous_handler = trap('TERM') { raise TransactionError, "Transaction aborted" } 97 74 increment_open_transactions 98 75 99 76 begin 100 unless objects.empty? 101 ActiveSupport::Deprecation.warn "Object transactions are deprecated and will be removed from Rails 2.0. See http://www.rubyonrails.org/deprecation for details.", caller 102 objects.each { |o| o.extend(Transaction::Simple) } 103 objects.each { |o| o.start_transaction } 104 end 105 106 result = connection.transaction(Thread.current['start_db_transaction'], &block) 107 108 objects.each { |o| o.commit_transaction } 109 return result 110 rescue Exception => object_transaction_rollback 111 objects.each { |o| o.abort_transaction } 112 raise 77 connection.transaction(Thread.current['start_db_transaction'], &block) 113 78 ensure 114 79 decrement_open_transactions … … 129 94 end 130 95 131 def transaction( *objects,&block)132 self.class.transaction( *objects,&block)96 def transaction(&block) 97 self.class.transaction(&block) 133 98 end 134 99 trunk/activerecord/test/transactions_test.rb
r6196 r6439 87 87 end 88 88 89 def test_failing_with_object_rollback90 assert !@first.approved?, "First should be unapproved initially"91 92 begin93 assert_deprecated /Object transactions/ do94 Topic.transaction(@first, @second) do95 @first.approved = true96 @second.approved = false97 @first.save98 @second.save99 raise "Bad things!"100 end101 end102 rescue103 # caught it104 end105 106 assert !@first.approved?, "First shouldn't have been approved"107 assert @second.approved?, "Second should still be approved"108 end109 89 110 90 def test_callback_rollback_in_save