Skip to content

Commit

Permalink
Split Open into Real and Savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Sep 14, 2012
1 parent dd48f0e commit 6d9e6b3
Showing 1 changed file with 38 additions and 25 deletions.
Expand Up @@ -15,7 +15,7 @@ def number
end

def begin
Open.new(connection, self)
Real.new(connection, self)
end

def closed?
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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.