Class: ActiveRecord::ConnectionAdapters::TransactionState

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/abstract/transaction.rb

Instance Method Summary collapse

Constructor Details

#initialize(state = nil) ⇒ TransactionState

Returns a new instance of TransactionState.



6
7
8
9
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 6

def initialize(state = nil)
  @state = state
  @children = []
end

Instance Method Details

#add_child(state) ⇒ Object



11
12
13
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 11

def add_child(state)
  @children << state
end

#commit!Object



71
72
73
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 71

def commit!
  @state = :committed
end

#committed?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 19

def committed?
  @state == :committed || @state == :fully_committed
end

#completed?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 39

def completed?
  committed? || rolledback?
end

#finalized?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 15

def finalized?
  @state
end

#full_commit!Object



75
76
77
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 75

def full_commit!
  @state = :fully_committed
end

#full_rollback!Object



66
67
68
69
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 66

def full_rollback!
  @children.each { |c| c.rollback! }
  @state = :fully_rolledback
end

#fully_committed?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 23

def fully_committed?
  @state == :fully_committed
end

#fully_completed?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 35

def fully_completed?
  completed?
end

#fully_rolledback?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 31

def fully_rolledback?
  @state == :fully_rolledback
end

#nullify!Object



79
80
81
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 79

def nullify!
  @state = nil
end

#rollback!Object



61
62
63
64
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 61

def rollback!
  @children.each { |c| c.rollback! }
  @state = :rolledback
end

#rolledback?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 27

def rolledback?
  @state == :rolledback || @state == :fully_rolledback
end

#set_state(state) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 43

def set_state(state)
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
    The set_state method is deprecated and will be removed in
    Rails 6.0. Please use rollback! or commit! to set transaction
    state directly.
  MSG
  case state
  when :rolledback
    rollback!
  when :committed
    commit!
  when nil
    nullify!
  else
    raise ArgumentError, "Invalid transaction state: #{state}"
  end
end