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, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum

Constructor Details

#initialize(connection, max) ⇒ StatementPool

Returns a new instance of StatementPool.



256
257
258
259
260
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 256

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

Instance Method Details

#[](key) ⇒ Object



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

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

#[]=(sql, key) ⇒ Object



271
272
273
274
275
276
277
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 271

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

#clearObject



279
280
281
282
283
284
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 279

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

#delete(sql_key) ⇒ Object



286
287
288
289
# File 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb', line 286

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

#each(&block) ⇒ Object



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

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#lengthObject



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

def length;       cache.length; end

#next_keyObject



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

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