Class: ActiveRecord::ConnectionAdapters::RedshiftAdapter::StatementPool

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

Instance Method Summary collapse

Constructor Details

#initialize(connection, max) ⇒ StatementPool

Returns a new instance of StatementPool.



142
143
144
145
146
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 142

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

Instance Method Details

#[](key) ⇒ Object



150
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 150

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

#[]=(sql, key) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 157

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

#clearObject



165
166
167
168
169
170
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 165

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

#delete(sql_key) ⇒ Object



172
173
174
175
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 172

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

#each(&block) ⇒ Object



148
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 148

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


149
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 149

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

#lengthObject



151
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 151

def length;       cache.length; end

#next_keyObject



153
154
155
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 153

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