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.



132
133
134
135
136
137
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 132

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

Instance Method Details

#[](key) ⇒ Object



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

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

#[]=(sql, key) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 148

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

#clearObject



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

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

#delete(sql_key) ⇒ Object



163
164
165
166
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 163

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

#each(&block) ⇒ Object



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

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#lengthObject



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

def length;       cache.length; end

#next_keyObject



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

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