module ArJdbc::Abstract::StatementCache

Public Class Methods

new(connection, logger, config) click to toggle source
Calls superclass method
# File lib/arjdbc/abstract/statement_cache.rb, line 20
def initialize(connection, logger, config)
  super

  # Only say we support the statement cache if we are using prepared statements
  # and have a max number of statements defined
  statement_limit = self.class.type_cast_config_to_integer(config[:statement_limit])
  @jdbc_statement_cache_enabled = config[:prepared_statements] && (statement_limit.nil? || statement_limit > 0)

  @statements = StatementPool.new(statement_limit) # AR (5.0) expects this to be stored as @statements
end

Public Instance Methods

clear_cache!() click to toggle source

Clears the prepared statements cache.

# File lib/arjdbc/abstract/statement_cache.rb, line 32
def clear_cache!
  @statements.clear
end
delete_cached_statement(sql) click to toggle source
# File lib/arjdbc/abstract/statement_cache.rb, line 36
def delete_cached_statement(sql)
  @statements.delete(cached_statement_key(sql))
end
fetch_cached_statement(sql) click to toggle source
# File lib/arjdbc/abstract/statement_cache.rb, line 40
def fetch_cached_statement(sql)
  @statements[cached_statement_key(sql)] ||= @connection.connection.prepare_statement(sql)
end
supports_statement_cache?() click to toggle source
# File lib/arjdbc/abstract/statement_cache.rb, line 44
def supports_statement_cache?
  @jdbc_statement_cache_enabled
end

Private Instance Methods

cached_statement_key(sql) click to toggle source

This should be overridden by the adapter if the sql itself is not enough to make the key unique

# File lib/arjdbc/abstract/statement_cache.rb, line 52
def cached_statement_key(sql)
  sql
end