Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::StatementPool

Inherits:
StatementPool show all
Defined in:
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Instance Method Summary collapse

Methods inherited from StatementPool

#delete

Methods included from Enumerable

#as_json, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum

Constructor Details

#initialize(connection, max) ⇒ StatementPool


252
253
254
255
256
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 252

def initialize(connection, max)
  super
  @counter = 0
  @cache   = Hash.new { |h,pid| h[pid] = {} }
end

Instance Method Details

#[](key) ⇒ Object


260
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 260

def [](key);      cache[key]; end

#[]=(sql, key) ⇒ Object


267
268
269
270
271
272
273
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 267

def []=(sql, key)
  while @max <= cache.size
    dealloc(cache.shift.last)
  end
  @counter += 1
  cache[sql] = key
end

#clearObject


275
276
277
278
279
280
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 275

def clear
  cache.each_value do |stmt_key|
    dealloc stmt_key
  end
  cache.clear
end

#each(&block) ⇒ Object


258
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 258

def each(&block); cache.each(&block); end

#key?(key) ⇒ Boolean


259
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 259

def key?(key);    cache.key?(key); end

#lengthObject


261
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 261

def length;       cache.length; end

#next_keyObject


263
264
265
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 263

def next_key
  "a#{@counter + 1}"
end