class Keymap::ConnectionAdapters::AbstractAdapter

Attributes

in_use[R]
in_use?[R]
last_use[R]
logger[R]
pool[RW]

Public Instance Methods

active?() click to toggle source

Checks whether the connection to the database is still active. This includes checking whether the kv-store is actually capable of responding, i.e. whether the connection isn’t stale.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 68
def active?
  @active
end
adapter_name() click to toggle source

Returns the human-readable name of the adapter. Use mixed case - one can always use downcase if needed.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 59
def adapter_name
  'Abstract'
end
begin_db_transaction() click to toggle source

Begins the transaction (and turns off auto-committing).

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 122
def begin_db_transaction()
end
clear_cache!() click to toggle source

Clear any caching the kv-store adapter may be doing. This is kv-store specific.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 97
def clear_cache!
  # this should be overridden by concrete adapters
end
close() click to toggle source

Check the connection back in to the connection pool

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 135
def close
  pool.checkin self
end
commit_db_transaction() click to toggle source

Commits the transaction (and turns on auto-committing).

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 126
def commit_db_transaction()
end
disconnect!() click to toggle source

Disconnects from the kv-store if already connected. Otherwise, this method does nothing.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 80
def disconnect!
  @active = false
end
expire() click to toggle source
# File lib/keymap/connection_adapters/abstract_adapter.rb, line 53
def expire
  @in_use = false
end
lease() click to toggle source
# File lib/keymap/connection_adapters/abstract_adapter.rb, line 44
def lease
  synchronize do
    unless in_use
      @in_use = true
      @last_use = Time.now
    end
  end
end
raw_connection() click to toggle source

Provides access to the underlying kv-store driver for this adapter. For example, this method returns a Redis object in case of RedisAdapter.

This is useful for when you need to call a proprietary method.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 117
def raw_connection
  @connection
end
reconnect!() click to toggle source

Disconnects from the database if already connected, and establishes a new connection with the database.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 74
def reconnect!
  @active = true
end
requires_reloading?() click to toggle source

Returns true if its required to reload the connection between requests for development mode.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 102
def requires_reloading?
  false
end
reset!() click to toggle source

Reset the state of this connection, directing the kv-store to clear transactions and other connection-related server-side state. Usually a implementation-dependent operation.

The default implementation does nothing; the implementation should be overridden by concrete adapters.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 90
def reset!
  # this should be overridden by concrete adapters
end
rollback_db_transaction() click to toggle source

Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 131
def rollback_db_transaction()
end
verify!() click to toggle source

Checks whether the connection to the kv-store is still active (i.e. not stale). This is done under the hood by calling active?. If the connection is no longer active, then this method will reconnect to the kv-store.

# File lib/keymap/connection_adapters/abstract_adapter.rb, line 109
def verify!
  reconnect! unless active?
end