aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-09-14 17:54:27 +0100
committerJon Leighton <j@jonathanleighton.com>2012-09-15 00:00:50 +0100
commit6d9e6b3a80ef1406c16aeb42ebb786c0a1e5b4b0 (patch)
treeb5a30e5a6752aeecdbed162f24c499697fdc0cac
parentdd48f0ea4c9f83357c348a5f4ddd5b09ecfb23f2 (diff)
downloadrails-6d9e6b3a80ef1406c16aeb42ebb786c0a1e5b4b0.tar.gz
rails-6d9e6b3a80ef1406c16aeb42ebb786c0a1e5b4b0.tar.bz2
rails-6d9e6b3a80ef1406c16aeb42ebb786c0a1e5b4b0.zip
Split Open into Real and Savepoint
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/transaction.rb63
1 files changed, 38 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
index 7f82b8f666..a305480d9e 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
@@ -15,7 +15,7 @@ module ActiveRecord
end
def begin
- Open.new(connection, self)
+ Real.new(connection, self)
end
def closed?
@@ -40,12 +40,6 @@ module ActiveRecord
@parent = parent
@records = []
@finishing = false
-
- if parent.open?
- connection.create_savepoint
- else
- connection.begin_db_transaction
- end
end
def number
@@ -65,33 +59,18 @@ module ActiveRecord
end
def begin
- Open.new(connection, self)
+ Savepoint.new(connection, self)
end
def rollback
@finishing = true
-
- if parent.open?
- connection.rollback_to_savepoint
- else
- connection.rollback_db_transaction
- end
-
- rollback_records
+ perform_rollback
parent
end
def commit
@finishing = true
-
- if parent.open?
- connection.release_savepoint
- records.each { |r| parent.add_record(r) }
- else
- connection.commit_db_transaction
- commit_records
- end
-
+ perform_commit
parent
end
@@ -127,6 +106,40 @@ module ActiveRecord
true
end
end
+
+ class Real < Open
+ def initialize(connection, parent)
+ super
+ connection.begin_db_transaction
+ end
+
+ def perform_rollback
+ connection.rollback_db_transaction
+ rollback_records
+ end
+
+ def perform_commit
+ connection.commit_db_transaction
+ commit_records
+ end
+ end
+
+ class Savepoint < Open
+ def initialize(connection, parent)
+ super
+ connection.create_savepoint
+ end
+
+ def perform_rollback
+ connection.rollback_to_savepoint
+ rollback_records
+ end
+
+ def perform_commit
+ connection.release_savepoint
+ records.each { |r| parent.add_record(r) }
+ end
+ end
end
end
end