Permalink
Browse files

Move TransactionManager to bottom of class

  • Loading branch information...
1 parent 8888296 commit 62c75f4eacf6466a3bd1b22f97cda7ab7b597064 @arthurnn arthurnn committed Jul 31, 2014
Showing with 67 additions and 67 deletions.
  1. +67 −67 activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
@@ -1,72 +1,5 @@
module ActiveRecord
module ConnectionAdapters
- class TransactionManager #:nodoc:
- def initialize(connection)
- @stack = []
- @connection = connection
- end
-
- def begin_transaction(options = {})
- transaction_class = @stack.empty? ? RealTransaction : SavepointTransaction
- transaction = transaction_class.new(@connection, "active_record_#{@stack.size}", options)
-
- @stack.push(transaction)
- transaction
- end
-
- def commit_transaction
- @stack.pop.commit
- end
-
- def rollback_transaction
- @stack.pop.rollback
- end
-
- def within_new_transaction(options = {})
- transaction = begin_transaction options
- yield
- rescue Exception => error
- transaction.rollback if transaction
- raise
- ensure
- begin
- transaction.commit unless error
- rescue Exception
- transaction.rollback
- raise
- ensure
- @stack.pop if transaction
- end
- end
-
- def open_transactions
- @stack.size
- end
-
- def current_transaction
- @stack.last || closed_transaction
- end
-
- private
-
- def closed_transaction
- @closed_transaction ||= ClosedTransaction.new
- end
- end
-
- class Transaction #:nodoc:
- attr_reader :connection, :state
-
- def initialize(connection)
- @connection = connection
- @state = TransactionState.new
- end
-
- def savepoint_name
- nil
- end
- end
-
class TransactionState
attr_reader :parent
@@ -97,6 +30,19 @@ def set_state(state)
end
end
+ class Transaction #:nodoc:
+ attr_reader :connection, :state
+
+ def initialize(connection)
+ @connection = connection
+ @state = TransactionState.new
+ end
+
+ def savepoint_name
+ nil
+ end
+ end
+
class ClosedTransaction < Transaction #:nodoc:
def initialize; super(nil); end
def closed?; true; end
@@ -212,5 +158,59 @@ def perform_commit
connection.release_savepoint(savepoint_name)
end
end
+
+ class TransactionManager #:nodoc:
+ def initialize(connection)
+ @stack = []
+ @connection = connection
+ end
+
+ def begin_transaction(options = {})
+ transaction_class = @stack.empty? ? RealTransaction : SavepointTransaction
+ transaction = transaction_class.new(@connection, "active_record_#{@stack.size}", options)
+
+ @stack.push(transaction)
+ transaction
+ end
+
+ def commit_transaction
+ @stack.pop.commit
+ end
+
+ def rollback_transaction
+ @stack.pop.rollback
+ end
+
+ def within_new_transaction(options = {})
+ transaction = begin_transaction options
+ yield
+ rescue Exception => error
+ transaction.rollback if transaction
+ raise
+ ensure
+ begin
+ transaction.commit unless error
+ rescue Exception
+ transaction.rollback
+ raise
+ ensure
+ @stack.pop if transaction
+ end
+ end
+
+ def open_transactions
+ @stack.size
+ end
+
+ def current_transaction
+ @stack.last || closed_transaction
+ end
+
+ private
+
+ def closed_transaction
+ @closed_transaction ||= ClosedTransaction.new
+ end
+ end
end
end

0 comments on commit 62c75f4

Please sign in to comment.