def commit
if block_given?
unless @state == :none
raise "Illegal state for commit with block: #{@state}"
end
begin
self.begin
rval = within { |*block_args| yield(*block_args) }
if @state == :begin
self.commit
end
return rval
rescue Exception => exception
if @state == :begin
self.rollback
end
raise exception
end
else
unless @state == :begin
raise "Illegal state for commit without block: #{@state}"
end
each_adapter(:commit_adapter, [:log_fatal_transaction_breakage])
each_adapter(:close_adapter, [:log_fatal_transaction_breakage])
@state = :commit
end
end