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 included from Enumerable

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

Constructor Details

#initialize(connection, max) ⇒ StatementPool

Returns a new instance of StatementPool.


495
496
497
498
499
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 495

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

Instance Method Details

#[](key) ⇒ Object


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

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

#[]=(sql, key) ⇒ Object


510
511
512
513
514
515
516
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 510

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

#clearObject


518
519
520
521
522
523
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 518

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

#delete(sql_key) ⇒ Object


525
526
527
528
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 525

def delete(sql_key)
  dealloc cache[sql_key]
  cache.delete sql_key
end

#each(&block) ⇒ Object


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

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#lengthObject


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

def length;       cache.length; end

#next_keyObject


506
507
508
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 506

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