Class: ActiveRecord::ConnectionAdapters::Transaction
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::Transaction
show all
- Defined in:
- lib/active_record/connection_adapters/abstract/transaction.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(connection, options, run_commit_callbacks: false) ⇒ Transaction
Returns a new instance of Transaction.
80
81
82
83
84
85
86
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 80
def initialize(connection, options, run_commit_callbacks: false)
@connection = connection
@state = TransactionState.new
@records = []
@joinable = options.fetch(:joinable, true)
@run_commit_callbacks = run_commit_callbacks
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
77
78
79
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 77
def connection
@connection
end
|
#joinable=(value) ⇒ Object
Sets the attribute joinable
78
79
80
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 78
def joinable=(value)
@joinable = value
end
|
#records ⇒ Object
Returns the value of attribute records.
77
78
79
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 77
def records
@records
end
|
#savepoint_name ⇒ Object
Returns the value of attribute savepoint_name.
77
78
79
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 77
def savepoint_name
@savepoint_name
end
|
#state ⇒ Object
Returns the value of attribute state.
77
78
79
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 77
def state
@state
end
|
Instance Method Details
#add_record(record) ⇒ Object
88
89
90
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 88
def add_record(record)
records << record
end
|
#before_commit_records ⇒ Object
111
112
113
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 111
def before_commit_records
records.uniq.each(&:before_committed!) if @run_commit_callbacks
end
|
#closed? ⇒ Boolean
131
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 131
def closed?; false; end
|
#commit ⇒ Object
107
108
109
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 107
def commit
@state.commit!
end
|
#commit_records ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 115
def commit_records
ite = records.uniq
while record = ite.shift
if @run_commit_callbacks
record.committed!
else
record.add_to_transaction
end
end
ensure
ite.each { |i| i.committed!(should_run_callbacks: false) }
end
|
#full_rollback? ⇒ Boolean
129
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 129
def full_rollback?; true; end
|
#joinable? ⇒ Boolean
130
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 130
def joinable?; @joinable; end
|
#open? ⇒ Boolean
132
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 132
def open?; !closed?; end
|
#rollback ⇒ Object
92
93
94
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 92
def rollback
@state.rollback!
end
|
#rollback_records ⇒ Object
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 96
def rollback_records
ite = records.uniq
while record = ite.shift
record.rolledback!(force_restore_state: full_rollback?)
end
ensure
ite.each do |i|
i.rolledback!(force_restore_state: full_rollback?, should_run_callbacks: false)
end
end
|