Class: IncrementalCacheSQLResolver

Inherits:
SQLResolver show all
Defined in:
lib/etl/transform/foreign_key_lookup_transform.rb

Instance Method Summary collapse

Methods inherited from SQLResolver

#cache, #table_name

Constructor Details

#initialize(atable, afield, connection = nil) ⇒ IncrementalCacheSQLResolver

Returns a new instance of IncrementalCacheSQLResolver.



157
158
159
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 157

def initialize(atable, afield, connection=nil)
  super
end

Instance Method Details

#load_cacheObject



174
175
176
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 174

def load_cache
  @cache = {}
end

#resolve(value) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 161

def resolve(value)
  return nil if value.nil?
  r = cache[value]
  unless r
    q = "SELECT id FROM #{table_name} WHERE #{wheres(value)}"
    r = @connection.select_value(q)
    if r
      cache[value] = r
    end
  end
  r
end