diff options
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/transaction.rb | 29 |
2 files changed, 24 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 7cfaf3b0e5..5eb0f0f132 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -198,7 +198,6 @@ module ActiveRecord @transaction_joinable = last_transaction_joinable if outside_transaction? - @open_transactions = 0 @transaction = Transactions::Closed.new(self) elsif @transaction.open? && transaction_open begin diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb index 0a4649ffa7..4f1f9223ec 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb @@ -10,6 +10,10 @@ module ActiveRecord end class Closed < State + def number + 0 + end + def begin Open.new(connection, self) end @@ -33,16 +37,31 @@ module ActiveRecord def initialize(connection, parent) super connection - @parent = parent - @records = [] + @parent = parent + @records = [] + @finishing = false if parent.open? connection.create_savepoint else connection.begin_db_transaction end + end + + def number + if finishing? + parent.number + else + parent.number + 1 + end + end - connection.increment_open_transactions + # Database adapters expect that #open_transactions will be decremented + # before we've actually executed a COMMIT or ROLLBACK. This is kinda + # annoying, but for now we use this @finishing flag to toggle what value + # #number should return. + def finishing? + @finishing end def begin @@ -50,7 +69,7 @@ module ActiveRecord end def rollback - connection.decrement_open_transactions + @finishing = true if parent.open? connection.rollback_to_savepoint @@ -63,7 +82,7 @@ module ActiveRecord end def commit - connection.decrement_open_transactions + @finishing = true begin if parent.open? |