Module: Foobara::Persistence::EntityBase::Transaction::Concerns::StateTransitions

Defined in:
foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb

Instance Method Summary collapse

Instance Method Details

#commit!Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb', line 44

def commit!
  state_machine.commit! do
    each_table(&:validate!)
    each_table(&:flush_created!)
    each_table(&:flush_updated_and_hard_deleted!)
    entity_attributes_crud_driver.close_transaction(raw_tx)
  end
rescue => e
  # :nocov:
  rollback!(e)
  raise
  # :nocov:
end

#each_tableObject

TODO: this belongs elsewhere



59
60
61
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb', line 59

def each_table(&)
  tables.values.each(&)
end

#flush!Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb', line 18

def flush!
  state_machine.flush! do
    each_table(&:validate!)
    each_table(&:flush_created!)
    each_table(&:flush_updated_and_hard_deleted!)
  end
rescue => e
  # :nocov:
  rollback!(e)
  raise
  # :nocov:
end

#open!Object



12
13
14
15
16
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb', line 12

def open!
  state_machine.open! do
    self.raw_tx = entity_attributes_crud_driver.open_transaction
  end
end

#revert!Object

Should communicate somehow that this is only in-memory. TODO: support multiple-reverts for databases that support checkpoints



33
34
35
36
37
38
39
40
41
42
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb', line 33

def revert!
  state_machine.revert! do
    each_table(&:revert!)
  end
rescue => e
  # :nocov:
  rollback!(e)
  raise
  # :nocov:
end

#rollback!(because_of = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb', line 63

def rollback!(because_of = nil)
  state_machine.rollback! do
    # TODO: raise error if already flushed and if crud_driver doesn't support true transactions
    entity_attributes_crud_driver.rollback_transaction(raw_tx)
    each_table(&:rollback!)
    entity_attributes_crud_driver.close_transaction(raw_tx)
  end

  if !because_of && (self == entity_base.current_transaction)
    raise RolledBack, "intentionally rolled back"
  end
rescue
  state_machine.error! if state_machine.currently_open?
  raise
end