提交 f87db851 编写于 作者: M Michael Koziarski

Remove deprecated object transactions. People relying on this functionality...

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]



git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6439 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 16b4739e
*SVN*
* 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]
* 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]
* find_or_create_by_* takes a hash so you can create with more attributes than are in the method name. For example, Person.find_or_create_by_name(:name => 'Henry', :comments => 'Hi new user!') is equivalent to Person.find_by_name('Henry') || Person.create(:name => 'Henry', :comments => 'Hi new user!'). #7368 [Josh Susser]
......
require 'active_record/vendor/simple.rb'
Transaction::Simple.send(:remove_method, :transaction)
require 'thread'
module ActiveRecord
......@@ -66,50 +64,17 @@ def self.included(base)
# will happen under the protected cover of a transaction. So you can use validations to check for values that the transaction
# depend on or you can raise exceptions in the callbacks to rollback.
#
# == Object-level transactions (deprecated)
#
# You can enable object-level transactions for Active Record objects, though. You do this by naming each of the Active Records
# that you want to enable object-level transactions for, like this:
#
# Account.transaction(david, mary) do
# david.withdrawal(100)
# mary.deposit(100)
# end
#
# If the transaction fails, David and Mary will be returned to their
# pre-transactional state. No money will have changed hands in neither
# object nor database.
#
# However, useful state such as validation errors are also rolled back,
# limiting the usefulness of this feature. As such it is deprecated in
# Rails 1.2 and will be removed in the next release. Install the
# object_transactions plugin if you wish to continue using it.
#
# == Exception handling
#
# Also have in mind that exceptions thrown within a transaction block will be propagated (after triggering the ROLLBACK), so you
# should be ready to catch those in your application code.
#
# Tribute: Object-level transactions are implemented by Transaction::Simple by Austin Ziegler.
module ClassMethods
def transaction(*objects, &block)
def transaction(&block)
previous_handler = trap('TERM') { raise TransactionError, "Transaction aborted" }
increment_open_transactions
begin
unless objects.empty?
ActiveSupport::Deprecation.warn "Object transactions are deprecated and will be removed from Rails 2.0. See http://www.rubyonrails.org/deprecation for details.", caller
objects.each { |o| o.extend(Transaction::Simple) }
objects.each { |o| o.start_transaction }
end
result = connection.transaction(Thread.current['start_db_transaction'], &block)
objects.each { |o| o.commit_transaction }
return result
rescue Exception => object_transaction_rollback
objects.each { |o| o.abort_transaction }
raise
connection.transaction(Thread.current['start_db_transaction'], &block)
ensure
decrement_open_transactions
trap('TERM', previous_handler)
......@@ -128,8 +93,8 @@ def decrement_open_transactions #:nodoc:
end
end
def transaction(*objects, &block)
self.class.transaction(*objects, &block)
def transaction(&block)
self.class.transaction(&block)
end
def destroy_with_transactions #:nodoc:
......
......@@ -86,26 +86,6 @@ def test_failing_on_exception
assert Topic.find(2).approved?, "Second should still be approved"
end
def test_failing_with_object_rollback
assert !@first.approved?, "First should be unapproved initially"
begin
assert_deprecated /Object transactions/ do
Topic.transaction(@first, @second) do
@first.approved = true
@second.approved = false
@first.save
@second.save
raise "Bad things!"
end
end
rescue
# caught it
end
assert !@first.approved?, "First shouldn't have been approved"
assert @second.approved?, "Second should still be approved"
end
def test_callback_rollback_in_save
add_exception_raising_after_save_callback_to_topic
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册