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.



126
127
128
129
130
131
# File 'lib/active_record/connection_adapters/redshift_adapter.rb', line 126

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

Instance Method Details

#[](key) ⇒ Object



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

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

#[]=(sql, key) ⇒ Object



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

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

#clearObject



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

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

#delete(sql_key) ⇒ Object



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

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

#each(&block) ⇒ Object



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

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#lengthObject



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

def length;       cache.length; end

#next_keyObject



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

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