Class: SolidObjects::DatabaseAdapter
- Inherits:
-
Object
- Object
- SolidObjects::DatabaseAdapter
show all
- Defined in:
- lib/solid_objects/database_adapter.rb,
sig/generated/lib/solid_objects/database_adapter.rbs
Constant Summary
collapse
- TRANSACTION_CLOCK =
:solid_objects_transaction_clock
- TRANSACTION_CLOCK_SCOPE =
:solid_objects_transaction_clock_scope
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DatabaseAdapter.
30
31
32
33
|
# File 'lib/solid_objects/database_adapter.rb', line 30
def initialize(connection)
@connection_pool = connection.respond_to?(:pool) ? connection.pool : nil
@fixed_connection = connection_pool ? nil : connection
end
|
Instance Attribute Details
#connection_pool ⇒ Object
Returns the value of attribute connection_pool.
94
95
96
|
# File 'lib/solid_objects/database_adapter.rb', line 94
def connection_pool
@connection_pool
end
|
#fixed_connection ⇒ Object
Returns the value of attribute fixed_connection.
94
95
96
|
# File 'lib/solid_objects/database_adapter.rb', line 94
def fixed_connection
@fixed_connection
end
|
Instance Method Details
#claim_lock ⇒ String?
41
42
43
|
# File 'lib/solid_objects/database_adapter.rb', line 41
def claim_lock
nil
end
|
This method returns an undefined value.
123
124
|
# File 'lib/solid_objects/database_adapter.rb', line 123
def configure_transaction_deadline(_connection)
end
|
#current_time_expression ⇒ String
46
47
48
|
# File 'lib/solid_objects/database_adapter.rb', line 46
def current_time_expression
"CURRENT_TIMESTAMP"
end
|
#deadline_error?(_error) ⇒ Boolean
127
128
129
|
# File 'lib/solid_objects/database_adapter.rb', line 127
def deadline_error?(_error)
false
end
|
88
89
90
|
# File 'lib/solid_objects/database_adapter.rb', line 88
def lock_candidates(relation)
claim_lock ? relation.lock(claim_lock) : relation
end
|
#read_database_now ⇒ Time
110
111
112
113
114
115
|
# File 'lib/solid_objects/database_adapter.rb', line 110
def read_database_now
value = with_connection do |connection|
connection.select_value("SELECT #{current_time_expression}")
end
value.is_a?(Time) ? value.utc : Time.parse("#{value} UTC").utc
end
|
#supports_skip_locked? ⇒ Boolean
36
37
38
|
# File 'lib/solid_objects/database_adapter.rb', line 36
def supports_skip_locked?
false
end
|
#transaction { ... } ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/solid_objects/database_adapter.rb', line 68
def transaction(&block)
raise DatabaseDeadlineExceeded, "synchronous invocation deadline expired" if SyncDeadline.expired?
with_connection do |connection|
with_transaction_deadline(connection) do
connection.transaction(requires_new: true) do
configure_transaction_deadline(connection)
with_transaction_clock { block.call }
end
end
end
rescue => error
raise unless deadline_error?(error)
raise DatabaseDeadlineExceeded,
"database lock wait exceeded the synchronous invocation deadline",
cause: error
end
|
#with_connection {|arg0| ... } ⇒ Object
132
133
134
135
136
|
# File 'lib/solid_objects/database_adapter.rb', line 132
def with_connection
return yield fixed_connection unless connection_pool
connection_pool.with_connection { |connection| yield connection }
end
|
#with_lock_probe { ... } ⇒ Object
63
64
65
|
# File 'lib/solid_objects/database_adapter.rb', line 63
def with_lock_probe
yield
end
|
#with_lock_retry { ... } ⇒ Object
58
59
60
|
# File 'lib/solid_objects/database_adapter.rb', line 58
def with_lock_retry
yield
end
|
#with_transaction_clock { ... } ⇒ Object
#with_transaction_deadline(_connection) { ... } ⇒ Object
118
119
120
|
# File 'lib/solid_objects/database_adapter.rb', line 118
def with_transaction_deadline(_connection)
yield
end
|