Sha256: 8ffc548c55e46b9ee4378a2c1ddfa152455d7fa84c36f7ba870fc7733c569554

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

require 'active_record/connection_adapters/abstract/transaction'

module ActiveRecord
  module ConnectionAdapters

    module SQLServerTransaction

      private

      def sqlserver?
        connection.respond_to?(:sqlserver?) && connection.sqlserver?
      end

      def current_isolation_level
        return unless sqlserver?
        level = connection.user_options_isolation_level
        # When READ_COMMITTED_SNAPSHOT is set to ON,
        # user_options_isolation_level will be equal to 'read committed
        # snapshot' which is not a valid isolation level
        if level.blank? || level == 'read committed snapshot'
          'READ COMMITTED'
        else
          level.upcase
        end
      end

    end

    Transaction.send :prepend, SQLServerTransaction

    module SQLServerRealTransaction

      attr_reader :starting_isolation_level

      def initialize(connection, options, *args)
        @connection = connection
        @starting_isolation_level = current_isolation_level if options[:isolation]
        super
      end

      def commit
        super
        reset_starting_isolation_level
      end

      def rollback
        super
        reset_starting_isolation_level
      end

      private

      def reset_starting_isolation_level
        if sqlserver? && starting_isolation_level
          connection.set_transaction_isolation_level(starting_isolation_level)
        end
      end

    end

    RealTransaction.send :prepend, SQLServerRealTransaction
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
activerecord-jdbcsqlserver-adapter-52.0.0 lib/active_record/connection_adapters/sqlserver/transaction.rb
activerecord-sqlserver-adapter-5.2.1 lib/active_record/connection_adapters/sqlserver/transaction.rb
activerecord-sqlserver-adapter-5.2.0 lib/active_record/connection_adapters/sqlserver/transaction.rb
activerecord-sqlserver-adapter-5.2.0.rc2 lib/active_record/connection_adapters/sqlserver/transaction.rb
activerecord-sqlserver-adapter-5.2.0.rc1 lib/active_record/connection_adapters/sqlserver/transaction.rb