Sha256: 4b4029ec8ae83fbbb096eabb3e4f260b75a74fd1fdd2faf5a8603b98f896db0a

Contents?: true

Size: 1.41 KB

Versions: 24

Compression:

Stored size: 1.41 KB

Contents

module Lev
  class TransactionIsolation

    def initialize(symbol)
      raise Lev.configuration.illegal_argument_error, "Invalid isolation symbol" if !@@symbols_to_isolation_levels.has_key?(symbol)
      @symbol = symbol
    end

    def self.no_transaction;   new(:no_transaction);   end
    def self.read_uncommitted; new(:read_uncommitted); end
    def self.read_committed;   new(:read_committed);   end
    def self.repeatable_read;  new(:repeatable_read);  end
    def self.serializable;     new(:serializable);     end


    def replace_if_more_isolated(other_transaction_isolation)
      if other_transaction_isolation.isolation_level > self.isolation_level
        self.symbol = other_transaction_isolation.symbol
      end
      self
    end

    def weaker_than(other)
      self.isolation_level < other.isolation_level
    end

    def self.mysql_default
      # MySQL default per https://blog.engineyard.com/2010/a-gentle-introduction-to-isolation-levels
      repeatable_read
    end

    def ==(other)
      self.symbol == other.symbol
    end

    def eql?(other)
      self == other
    end

    attr_reader :symbol

  protected

    def isolation_level
      @@symbols_to_isolation_levels[symbol]
    end

    @@symbols_to_isolation_levels = {
      no_transaction:   0,
      read_uncommitted: 1,
      read_committed:   2,
      repeatable_read:  3,
      serializable:     4
    }

    attr_writer :symbol

  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
lev-12.1.0 lib/lev/transaction_isolation.rb
lev-12.0.0 lib/lev/transaction_isolation.rb
lev-11.0.0 lib/lev/transaction_isolation.rb
lev-10.1.0 lib/lev/transaction_isolation.rb
lev-10.0.0 lib/lev/transaction_isolation.rb
lev-9.0.4 lib/lev/transaction_isolation.rb
lev-9.0.3 lib/lev/transaction_isolation.rb
lev-9.0.2 lib/lev/transaction_isolation.rb
lev-9.0.1 lib/lev/transaction_isolation.rb
lev-9.0.0 lib/lev/transaction_isolation.rb
lev-8.1.0 lib/lev/transaction_isolation.rb
lev-8.0.0 lib/lev/transaction_isolation.rb
lev-7.1.0 lib/lev/transaction_isolation.rb
lev-7.0.3 lib/lev/transaction_isolation.rb
lev-7.0.2 lib/lev/transaction_isolation.rb
lev-7.0.1 lib/lev/transaction_isolation.rb
lev-7.0.0 lib/lev/transaction_isolation.rb
lev-6.0.0 lib/lev/transaction_isolation.rb
lev-5.0.0 lib/lev/transaction_isolation.rb
lev-4.3.2 lib/lev/transaction_isolation.rb