Sha256: 4398da60bfd27a6f74e9e9ac48307c7fe4fc49809360088be643160cbed506e8

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

module Micronaut
  module Rails
    module TransactionalDatabaseSupport

      module InstanceMethods

        def active_record_configured?
          defined?(::ActiveRecord) && !::ActiveRecord::Base.configurations.blank?
        end

        def transactional_protection_start
          return unless active_record_configured?

          ::ActiveRecord::Base.connection.increment_open_transactions
          ::ActiveRecord::Base.connection.begin_db_transaction
        end

        def transactional_protection_cleanup
          return unless active_record_configured?

          if ::ActiveRecord::Base.connection.open_transactions != 0
            ::ActiveRecord::Base.connection.rollback_db_transaction
            ::ActiveRecord::Base.connection.decrement_open_transactions
          end

          ::ActiveRecord::Base.clear_active_connections!
        end

      end

      def self.extended(kls)
        kls.send(:include, InstanceMethods)
        kls.before { transactional_protection_start }
        kls.after { transactional_protection_cleanup }
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
spicycode-micronaut-rails-0.2.4 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.2.5 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.2.6 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.2.7 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.3.0 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.3.1 lib/micronaut/rails/transactional_database_support.rb
spicycode-micronaut-rails-0.3.2 lib/micronaut/rails/transactional_database_support.rb
micronaut-rails-1.0.1 lib/micronaut/rails/transactional_database_support.rb
micronaut-rails-1.0.0 lib/micronaut/rails/transactional_database_support.rb
micronaut-rails-0.3.3 lib/micronaut/rails/transactional_database_support.rb