Class: CassandraModel::CounterRecord

Inherits:
Record
  • Object
show all
Defined in:
lib/cassandra_model/counter_record.rb

Instance Attribute Summary

Attributes inherited from Record

#attributes, #execution_info, #valid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#==, batch_type, before_save, before_save_callbacks, cassandra_columns, #clustering_columns, columns, connection_name=, create, create_async, #delete, #delete_async, first, first_async, #initialize, #inspect, #invalidate!, normalized_attributes, normalized_column, order_by_clause, #partition_key, #primary_key, query_for_delete, query_for_save, query_for_update, request, request_async, request_meta, restriction_attributes, #save, select_column, select_columns, shard, shard_key, table, table=, table_name=, #update, #update_async

Methods included from QueryHelper

#after, #all, #before, def_query_helper, #find_by

Methods included from RecordDebug

#debug

Methods included from DisplayableAttributes

#as_json, included

Methods included from MetaColumns

included

Constructor Details

This class inherits a constructor from CassandraModel::Record

Class Method Details

.counter_columnsObject



53
54
55
# File 'lib/cassandra_model/counter_record.rb', line 53

def counter_columns
  table_data.counter_columns ||= columns - (partition_key + clustering_columns)
end

.save_in_batchObject



57
58
59
# File 'lib/cassandra_model/counter_record.rb', line 57

def save_in_batch
  table_config.batch_type = :counter
end

Instance Method Details

#increment!(options) ⇒ Object



25
26
27
# File 'lib/cassandra_model/counter_record.rb', line 25

def increment!(options)
  increment_async!(options).get
end

#increment_async!(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cassandra_model/counter_record.rb', line 4

def increment_async!(options)
  counter_clause = counter_clause(options)
  row_key = internal_primary_key.values
  statement = increment_statement(counter_clause)
  column_values = options.values + row_key

  validation_error = validate_primary_key!(statement, column_values)
  return validation_error if validation_error

  future = if batch_reactor
             execute_async_in_batch(statement, column_values)
           else
             session.execute_async(statement, *column_values, write_query_options)
           end
  future.on_success { execute_callback(:record_saved) }
  future.on_failure do |error|
    Logging.logger.error("Error incrementing #{self.class}: #{error}")
    execute_callback(:save_record_failed, error, statement, column_values)
  end.then { self }
end

#save_asyncObject

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/cassandra_model/counter_record.rb', line 29

def save_async
  raise NotImplementedError
end