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

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

Instance Method Summary collapse

Constructor Details

#initialize(connection, max) ⇒ StatementPool

Returns a new instance of StatementPool.



173
174
175
176
177
# File '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 '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 '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 '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 '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 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 179

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#lengthObject



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

def length;       cache.length; end

#next_keyObject



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

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