Class: ActiveRecord::ConnectionAdapters::MysqlAdapter::StatementPool

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

Instance Method Summary collapse

Methods included from Enumerable

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

Constructor Details

#initialize(connection, max = 1000) ⇒ StatementPool

Returns a new instance of StatementPool.


72
73
74
75
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 72

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

Instance Method Details

#[](key) ⇒ Object


79
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 79

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

#[]=(sql, key) ⇒ Object


83
84
85
86
87
88
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 83

def []=(sql, key)
  while @max <= cache.size
    cache.shift.last[:stmt].close
  end
  cache[sql] = key
end

#clearObject


90
91
92
93
94
95
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 90

def clear
  cache.each_value do |hash|
    hash[:stmt].close
  end
  cache.clear
end

#delete(key) ⇒ Object


81
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 81

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

#each(&block) ⇒ Object


77
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 77

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

78
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 78

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

#lengthObject


80
# File 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb', line 80

def length;       cache.length; end