Permalink
Browse files

Split Open into Real and Savepoint

  • Loading branch information...
jonleighton committed Sep 14, 2012
1 parent dd48f0e commit 6d9e6b3a80ef1406c16aeb42ebb786c0a1e5b4b0
Showing with 38 additions and 25 deletions.
  1. +38 −25 activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
@@ -15,7 +15,7 @@ def number
end
def begin
- Open.new(connection, self)
+ Real.new(connection, self)
end
def closed?
@@ -40,12 +40,6 @@ def initialize(connection, parent)
@parent = parent
@records = []
@finishing = false
-
- if parent.open?
- connection.create_savepoint
- else
- connection.begin_db_transaction
- end
end
def number
@@ -65,33 +59,18 @@ def finishing?
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 @@ def open?
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

0 comments on commit 6d9e6b3

Please sign in to comment.