class Riagent::Persistence::RiakDTSetStrategy

Attributes

key_list_set[W]

Public Instance Methods

add_key(key) click to toggle source

Adds a key to the collection key list (usually done as part of an insert) Added as a standalone method for ease of testing @param [String] key Key to be added to list

# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 32
def add_key(key)
  self.key_list_set.add(key)
end
all(results_limit) click to toggle source

Return all the documents in the collection. Uses Riak 2.0 CRDT Set Data type to keep track of collection key list @param [Integer] results_limit Number of results returned (currently ignored) @return [Array<Riagent::ActiveDocument>] List of ActiveDocument instances

# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 40
def all(results_limit)
  keys = self.all_keys
  # TODO: Trim keys to results_limit
  all_docs_hash = self.bucket.get_many(keys)
  all_docs_hash.values
end
all_keys() click to toggle source

Return all keys in the collection @return [Array<String>] List of all keys in the collection

# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 49
def all_keys
  self.key_list_set.members.to_a
end
delete_key(key) click to toggle source

Deletes a key from the key list (usually called by remove()).

# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 54
def delete_key(key)
  key_list_set = self.key_list_set.reload
  key_list_set.remove(key)
end
delete_key_list() click to toggle source

Clears the key list set

# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 60
def delete_key_list
  # Perform a Riak DELETE operation (using the bucket type interface)
  self.key_lists_bucket.delete self.key_list_set_name, type: 'sets'
end
insert(document) click to toggle source

Insert a document into the collection. Also inserts the document’s key into the key list set. @param [Riagent::ActiveDocument] document Document to be inserted @return [String] Document key

Calls superclass method
# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 69
def insert(document)
  doc_key = super
  self.add_key(doc_key)
  doc_key
end
key_list_set() click to toggle source

Return the Crdt Set object that keeps track of keys in this collection @return [Riak::Crdt::Set]

# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 77
def key_list_set 
  # Note: Assumes that the Bucket Type for Sets is the default 'sets'
  @key_list_set || Riak::Crdt::Set.new(self.key_lists_bucket, self.key_list_set_name)
end
key_list_set_name() click to toggle source

Return the key name of the set that keeps track of keys in this collection @return [String]

# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 84
def key_list_set_name
  '_rg_keys_' + self.collection_name()
end
key_lists_bucket() click to toggle source

Return the bucket in which the Riagent collection key lists are kept @return [Riak::Bucket]

# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 90
def key_lists_bucket
  self.client.bucket('_rg_key_lists')
end
remove(document) click to toggle source

Delete a document from a collection, and delete its key from the key list set @param [Riagent::ActiveDocument] document Document to be removed

Calls superclass method
# File lib/riagent/persistence/riak_dt_set_strategy.rb, line 96
def remove(document)
  doc_key = document.key
  super
  self.delete_key(doc_key)
end