Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6439

Show
Ignore:
Timestamp:
03/16/07 22:39:01 (3 years ago)
Author:
nzkoz
Message:

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]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r6433 r6439  
    11*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] 
    24 
    35* 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) 
    31require 'thread' 
    42 
     
    6765    # depend on or you can raise exceptions in the callbacks to rollback. 
    6866    # 
    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 Records 
    72     # that you want to enable object-level transactions for, like this: 
    73     # 
    74     #   Account.transaction(david, mary) do 
    75     #     david.withdrawal(100) 
    76     #     mary.deposit(100) 
    77     #   end 
    78     # 
    79     # If the transaction fails, David and Mary will be returned to their 
    80     # pre-transactional state. No money will have changed hands in neither 
    81     # 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 in 
    85     # Rails 1.2 and will be removed in the next release. Install the 
    86     # object_transactions plugin if you wish to continue using it. 
    87     # 
    8867    # == Exception handling 
    8968    # 
    9069    # Also have in mind that exceptions thrown within a transaction block will be propagated (after triggering the ROLLBACK), so you 
    9170    # should be ready to catch those in your application code. 
    92     # 
    93     # Tribute: Object-level transactions are implemented by Transaction::Simple by Austin Ziegler. 
    9471    module ClassMethods 
    95       def transaction(*objects, &block) 
     72      def transaction(&block) 
    9673        previous_handler = trap('TERM') { raise TransactionError, "Transaction aborted" } 
    9774        increment_open_transactions 
    9875 
    9976        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) 
    11378        ensure 
    11479          decrement_open_transactions 
     
    12994    end 
    13095 
    131     def transaction(*objects, &block) 
    132       self.class.transaction(*objects, &block) 
     96    def transaction(&block) 
     97      self.class.transaction(&block) 
    13398    end 
    13499 
  • trunk/activerecord/test/transactions_test.rb

    r6196 r6439  
    8787  end 
    8888   
    89   def test_failing_with_object_rollback 
    90     assert !@first.approved?, "First should be unapproved initially" 
    91    
    92     begin 
    93       assert_deprecated /Object transactions/ do 
    94         Topic.transaction(@first, @second) do 
    95           @first.approved  = true 
    96           @second.approved = false 
    97           @first.save 
    98           @second.save 
    99           raise "Bad things!" 
    100         end 
    101       end 
    102     rescue 
    103       # caught it 
    104     end 
    105      
    106     assert !@first.approved?, "First shouldn't have been approved" 
    107     assert @second.approved?, "Second should still be approved" 
    108   end 
    10989   
    11090  def test_callback_rollback_in_save