Class: FlexiRecord::IsolationLevel

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/flexirecord.rb

Overview

Transaction isolation levels are represented by (constant) IsolationLevel objects:

  • IsolationLevel::ReadUncommitted (Data written by concurrent uncommitted transactions may be read.)

  • IsolationLevel::ReadCommitted (Only data, which has been committed by other transactions is read.)

  • IsolationLevel::RepeatableRead

  • IsolationLevel::Serializable (The first query inside a transaction generates a “snapshot” of the database, which is then used for following read accesses.)

Constant Summary collapse

ReadUncommitted =
new(0, :read_uncommitted, 'READ UNCOMMITTED', 'ReadUncommitted')
ReadCommitted =
new(1, :read_committed,   'READ COMMITTED',   'ReadCommitted')
RepeatableRead =
new(2, :repeatable_read,  'REPEATABLE READ',  'RepeatableRead')
Serializable =
new(3, :serializable,     'SERIALIZABLE',     'Serializable')
@@symbols =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(integer, symbol, sql, name) ⇒ IsolationLevel

Used for generating the 4 constants representing the possible isolation levels.



77
78
79
80
81
82
83
84
# File 'lib/flexirecord.rb', line 77

def initialize(integer, symbol, sql, name)
  @integer = integer.to_i
  @symbol  = symbol.to_sym
  @sql     = sql.to_s.dup.freeze
  @name    = name.to_s.dup.freeze
  @@symbols[@symbol] = self
  nil
end

Class Method Details

.by_symbol(symbol) ⇒ Object

Returns an IsolationLevel object, matching one of these symbols:

  • :read_uncommitted

  • :read_committed

  • :repeatable_read

  • :serializable



72
73
74
# File 'lib/flexirecord.rb', line 72

def self.by_symbol(symbol)
  @@symbols[symbol.to_sym]
end

Instance Method Details

#<=>(other) ⇒ Object

Compares the isolation level with another. (Isolation levels providing fewer isolation are considered smaller.)



103
104
105
# File 'lib/flexirecord.rb', line 103

def <=>(other)
  self.to_i <=> other.to_i
end

#inspectObject

Returns the name of the constant referring to the isolation level.



97
98
99
# File 'lib/flexirecord.rb', line 97

def inspect
  "#{self.class.name}::#{@name}"
end

#to_iObject

Returns an integer representing the isolation level, which is also used for comparing/ordering them.



92
93
94
# File 'lib/flexirecord.rb', line 92

def to_i
  @integer
end

#to_sObject

Returns the SQL string representation of the isolation level.



87
88
89
# File 'lib/flexirecord.rb', line 87

def to_s
  @sql
end