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



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/active_record/bogacs/validator.rb', line 130

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



151
152
153
154
155
156
157
158
# File 'lib/active_record/bogacs/validator.rb', line 151

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



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

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



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

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