Permalink
Browse files

Reduce duplicate code between versions

Everyone 0.8+ has counters, don't need to duplicate

Going forward this should be factored better/differently
  • Loading branch information...
1 parent 3a8c5ab commit 9a1869912f7735b58285f2c679f071c98b17f29b @natemueller natemueller committed Sep 26, 2012
@@ -1,25 +1 @@
-class Cassandra
-
- ## Counters
-
- # Add a value to the counter in cf:key:super column:column
- def add(column_family, key, value, *columns_and_options)
- column_family, column, sub_column, options = extract_and_validate_params(column_family, key, columns_and_options, WRITE_DEFAULTS)
-
- mutation_map = if is_super(column_family)
- {
- key => {
- column_family => [_super_counter_mutation(column_family, column, sub_column, value)]
- }
- }
- else
- {
- key => {
- column_family => [_standard_counter_mutation(column_family, column, value)]
- }
- }
- end
-
- @batch ? @batch << [mutation_map, options[:consistency]] : _mutate(mutation_map, options[:consistency])
- end
-end
+require "#{File.expand_path(File.dirname(__FILE__))}/../0.8/cassandra"
@@ -1,28 +1 @@
-class Cassandra
- module Columns #:nodoc:
- def _standard_counter_mutation(column_family, column_name, value)
- CassandraThrift::Mutation.new(
- :column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
- :counter_column => CassandraThrift::CounterColumn.new(
- :name => column_name_class(column_family).new(column_name).to_s,
- :value => value
- )
- )
- )
- end
-
- def _super_counter_mutation(column_family, super_column_name, sub_column, value)
- CassandraThrift::Mutation.new(:column_or_supercolumn =>
- CassandraThrift::ColumnOrSuperColumn.new(
- :counter_super_column => CassandraThrift::SuperColumn.new(
- :name => column_name_class(column_family).new(super_column_name).to_s,
- :columns => [CassandraThrift::CounterColumn.new(
- :name => sub_column_name_class(column_family).new(sub_column).to_s,
- :value => value
- )]
- )
- )
- )
- end
- end
-end
+require "#{File.expand_path(File.dirname(__FILE__))}/../0.8/columns"
@@ -1,12 +1 @@
-require "#{File.expand_path(File.dirname(__FILE__))}/../0.7/protocol"
-
-class Cassandra
- # Inner methods for actually doing the Thrift calls
- module Protocol #:nodoc:
- private
-
- def _remove_counter(key, column_path, consistency_level)
- client.remove_counter(key, column_path, consistency_level)
- end
- end
-end
+require "#{File.expand_path(File.dirname(__FILE__))}/../0.8/protocol"
@@ -1,25 +1 @@
-class Cassandra
-
- ## Counters
-
- # Add a value to the counter in cf:key:super column:column
- def add(column_family, key, value, *columns_and_options)
- column_family, column, sub_column, options = extract_and_validate_params(column_family, key, columns_and_options, WRITE_DEFAULTS)
-
- mutation_map = if is_super(column_family)
- {
- key => {
- column_family => [_super_counter_mutation(column_family, column, sub_column, value)]
- }
- }
- else
- {
- key => {
- column_family => [_standard_counter_mutation(column_family, column, value)]
- }
- }
- end
-
- @batch ? @batch << [mutation_map, options[:consistency]] : _mutate(mutation_map, options[:consistency])
- end
-end
+require "#{File.expand_path(File.dirname(__FILE__))}/../1.0/cassandra"
@@ -1,28 +1 @@
-class Cassandra
- module Columns #:nodoc:
- def _standard_counter_mutation(column_family, column_name, value)
- CassandraThrift::Mutation.new(
- :column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
- :counter_column => CassandraThrift::CounterColumn.new(
- :name => column_name_class(column_family).new(column_name).to_s,
- :value => value
- )
- )
- )
- end
-
- def _super_counter_mutation(column_family, super_column_name, sub_column, value)
- CassandraThrift::Mutation.new(:column_or_supercolumn =>
- CassandraThrift::ColumnOrSuperColumn.new(
- :counter_super_column => CassandraThrift::SuperColumn.new(
- :name => column_name_class(column_family).new(super_column_name).to_s,
- :columns => [CassandraThrift::CounterColumn.new(
- :name => sub_column_name_class(column_family).new(sub_column).to_s,
- :value => value
- )]
- )
- )
- )
- end
- end
-end
+require "#{File.expand_path(File.dirname(__FILE__))}/../1.0/columns"
@@ -1,12 +1 @@
-require "#{File.expand_path(File.dirname(__FILE__))}/../0.7/protocol"
-
-class Cassandra
- # Inner methods for actually doing the Thrift calls
- module Protocol #:nodoc:
- private
-
- def _remove_counter(key, column_path, consistency_level)
- client.remove_counter(key, column_path, consistency_level)
- end
- end
-end
+require "#{File.expand_path(File.dirname(__FILE__))}/../1.0/protocol"

0 comments on commit 9a18699

Please sign in to comment.