Module: ArJdbc::Util::QuotedCache

Overview

Caches table and column name (quoted) outcomes. Uses ThreadSafe::Cache as a concurrent lock free (on JRuby) cache backend. The thread_safe gem is a dependency since ActiveSupport 4.0, when using ActiveRecord <= 3.2 one should add gem 'thread_safe' into the Gemfile as it is not forced (currently) as an explicit gem dependency.

Caching can also be disabled by setting the arjdbc.quoted_cache.disabled system property = 'true'.

Instance Method Summary collapse

Instance Method Details

#quote_column_name(name, *args) ⇒ String

Caches quoted table names, the cache is stored in the class' QUOTED_COLUMN_NAMES constant.

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/arjdbc/util/quoted_cache.rb', line 48

def quote_column_name(name, *args)
  if cache = self.class::QUOTED_COLUMN_NAMES
    unless quoted = cache[name]
      quoted = super
      cache.put_if_absent name, quoted.freeze
    end
    quoted
  else
    super
  end
end

#quote_table_name(name, *args) ⇒ String

Caches quoted table names, the cache is stored in the class' QUOTED_TABLE_NAMES constant.

Returns:

  • (String)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/arjdbc/util/quoted_cache.rb', line 33

def quote_table_name(name, *args)
  if cache = self.class::QUOTED_TABLE_NAMES
    unless quoted = cache[name]
      quoted = super
      cache.put_if_absent name, quoted.freeze
    end
    quoted
  else
    super
  end
end