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.


173
174
175
176
177
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 173

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

Instance Method Details

#[](key) ⇒ Object


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

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

#[]=(sql, key) ⇒ Object


188
189
190
191
192
193
194
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 188

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

#clearObject


196
197
198
199
200
201
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 196

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

#delete(sql_key) ⇒ Object


203
204
205
206
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 203

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

#each(&block) ⇒ Object


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

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#lengthObject


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

def length;       cache.length; end

#next_keyObject


184
185
186
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 184

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