Module: ActiveRecord::Bogacs::Validator::PoolAdaptor

Defined in:
lib/active_record/bogacs/validator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adapt!(pool) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/active_record/bogacs/validator.rb', line 136

def self.adapt!(pool)
  unless pool.class.include?(PoolAdaptor)
    pool.class.send :include, PoolAdaptor
  end

  return if pool.respond_to?(:thread_cached_conns)

  if pool.instance_variable_get :@reserved_connections
    class << pool
      attr_reader :reserved_connections
      alias_method :thread_cached_conns, :reserved_connections
    end
  elsif pool.instance_variable_get :@thread_cached_conns
    class << pool
      attr_reader :thread_cached_conns
    end
  else
    raise NotImplementedError, "could not adapt pool: #{pool}"
  end
end

Instance Method Details

#cached_conn_owner_id(conn) ⇒ Object



157
158
159
160
161
162
163
164
# File 'lib/active_record/bogacs/validator.rb', line 157

def cached_conn_owner_id(conn)
  thread_cached_conns.keys.each do |owner_id|
    if thread_cached_conns[ owner_id ] == conn
      return owner_id
    end
  end
  nil
end

#release_without_owner(conn) ⇒ Object



171
172
173
174
175
# File 'lib/active_record/bogacs/validator.rb', line 171

def release_without_owner(conn)
  if owner_id = cached_conn_owner_id(conn)
    thread_cached_conns.delete owner_id; return true
  end
end

#remove_without_owner(conn) ⇒ Object



166
167
168
169
# File 'lib/active_record/bogacs/validator.rb', line 166

def remove_without_owner(conn)
  remove conn # release(conn, nil) owner.object_id should do fine
  release_without_owner conn
end