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
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DatabaseAdapter.
27
28
29
30
|
# File 'lib/solid_objects/database_adapter.rb', line 27
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.
92
93
94
|
# File 'lib/solid_objects/database_adapter.rb', line 92
def connection_pool
@connection_pool
end
|
#fixed_connection ⇒ Object
Returns the value of attribute fixed_connection.
92
93
94
|
# File 'lib/solid_objects/database_adapter.rb', line 92
def fixed_connection
@fixed_connection
end
|
Instance Method Details
#claim_lock ⇒ String?
38
39
40
|
# File 'lib/solid_objects/database_adapter.rb', line 38
def claim_lock
nil
end
|
This method returns an undefined value.
100
101
|
# File 'lib/solid_objects/database_adapter.rb', line 100
def configure_transaction_deadline(_connection)
end
|
#current_time_expression ⇒ String
43
44
45
|
# File 'lib/solid_objects/database_adapter.rb', line 43
def current_time_expression
"CURRENT_TIMESTAMP"
end
|
#database_now ⇒ Time
48
49
50
51
52
53
|
# File 'lib/solid_objects/database_adapter.rb', line 48
def 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
|
#deadline_error?(_error) ⇒ Boolean
104
105
106
|
# File 'lib/solid_objects/database_adapter.rb', line 104
def deadline_error?(_error)
false
end
|
86
87
88
|
# File 'lib/solid_objects/database_adapter.rb', line 86
def lock_candidates(relation)
claim_lock ? relation.lock(claim_lock) : relation
end
|
#supports_skip_locked? ⇒ Boolean
33
34
35
|
# File 'lib/solid_objects/database_adapter.rb', line 33
def supports_skip_locked?
false
end
|
#transaction { ... } ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/solid_objects/database_adapter.rb', line 66
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)
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
109
110
111
112
113
|
# File 'lib/solid_objects/database_adapter.rb', line 109
def with_connection
return yield fixed_connection unless connection_pool
connection_pool.with_connection { |connection| yield connection }
end
|
#with_lock_probe { ... } ⇒ Object
61
62
63
|
# File 'lib/solid_objects/database_adapter.rb', line 61
def with_lock_probe
yield
end
|
#with_lock_retry { ... } ⇒ Object
56
57
58
|
# File 'lib/solid_objects/database_adapter.rb', line 56
def with_lock_retry
yield
end
|
#with_transaction_deadline(_connection) { ... } ⇒ Object
95
96
97
|
# File 'lib/solid_objects/database_adapter.rb', line 95
def with_transaction_deadline(_connection)
yield
end
|