sessionm-cassandra_object 2.5.1 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,8 +38,8 @@ module CassandraObject
38
38
 
39
39
  def remove(key)
40
40
  begin
41
- ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: relationships_column_family, key: key) do
42
- CassandraObject::Base.with_connection do
41
+ CassandraObject::Base.with_connection(key) do
42
+ ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: relationships_column_family, key: key) do
43
43
  connection.remove(relationships_column_family, key.to_s, consistency: thrift_write_consistency)
44
44
  end
45
45
  end
@@ -19,8 +19,8 @@ module CassandraObject
19
19
  def add(owner, record, set_inverse = true)
20
20
  key = owner.key
21
21
  attributes = {@association_name=>{new_key=>record.key.to_s}}
22
- ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
23
- CassandraObject::Base.with_connection do
22
+ CassandraObject::Base.with_connection(key) do
23
+ ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
24
24
  connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
25
25
  end
26
26
  end
@@ -24,15 +24,15 @@ module CassandraObject
24
24
  end
25
25
 
26
26
  def clear(owner)
27
- ActiveSupport::Notifications.instrument("remove.cassandra_object", :column_family => column_family, :key => owner.key, :columns => @association_name) do
28
- CassandraObject::Base.with_connection do
27
+ CassandraObject::Base.with_connection(owner.key) do
28
+ ActiveSupport::Notifications.instrument("remove.cassandra_object", :column_family => column_family, :key => owner.key, :columns => @association_name) do
29
29
  connection.remove(column_family, owner.key.to_s, @association_name)
30
30
  end
31
31
  end
32
32
  end
33
33
 
34
34
  def find(owner)
35
- CassandraObject::Base.with_connection do
35
+ CassandraObject::Base.with_connection(owner.key.to_s) do
36
36
  if key = connection.get(column_family, owner.key.to_s, @association_name.to_s, :count=>1).values.first
37
37
  target_class.get(key)
38
38
  else
@@ -45,8 +45,8 @@ module CassandraObject
45
45
  clear(owner)
46
46
  key = owner.key
47
47
  attributes = {@association_name=>{new_key=>record.key.to_s}}
48
- ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
49
- CassandraObject::Base.with_connection do
48
+ CassandraObject::Base.with_connection(key) do
49
+ ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
50
50
  connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
51
51
  end
52
52
  end
@@ -108,12 +108,12 @@ module CassandraObject
108
108
  end
109
109
  def self.connection?() !!connection end
110
110
 
111
- def self.with_connection(&block)
111
+ def self.with_connection(key=nil, &block)
112
112
  self.connection_pool.with_connection(&block)
113
113
  end
114
114
 
115
- def with_connection(&block)
116
- self.class.with_connection(&block)
115
+ def with_connection(key=nil, &block)
116
+ self.class.with_connection(key, &block)
117
117
  end
118
118
 
119
119
  def self.disconnect!
@@ -25,7 +25,7 @@ module CassandraObject
25
25
  while objects.size < number_to_find && !out_of_keys
26
26
  index_results =
27
27
  begin
28
- CassandraObject::Base.with_connection do
28
+ CassandraObject::Base.with_connection(@key) do
29
29
  connection.get(@column_family, @key, @super_column,
30
30
  count: limit,
31
31
  start: start_with,
@@ -85,7 +85,7 @@ module CassandraObject
85
85
  end
86
86
 
87
87
  def remove(index_key)
88
- CassandraObject::Base.with_connection do
88
+ CassandraObject::Base.with_connection(@key) do
89
89
  connection.remove(@column_family, @key, @super_column, index_key, consistency: target_class.thrift_write_consistency)
90
90
  end
91
91
  end
@@ -11,8 +11,8 @@ module CassandraObject
11
11
 
12
12
  attributes =
13
13
  begin
14
- ActiveSupport::Notifications.instrument("get.cassandra_object", column_family: column_family, key: key) do
15
- CassandraObject::Base.with_connection do
14
+ CassandraObject::Base.with_connection(key) do
15
+ ActiveSupport::Notifications.instrument("get.cassandra_object", column_family: column_family, key: key) do
16
16
  connection.get column_family, key, opts.slice(:consistency)
17
17
  end
18
18
  end
@@ -35,8 +35,8 @@ module CassandraObject
35
35
  opts.assert_valid_keys(:consistency)
36
36
  opts[:consistency] ||= thrift_read_consistency
37
37
 
38
- result = ActiveSupport::Notifications.instrument("get_counter.cassandra_object", column_family: column_family, key: key, column: column) do
39
- CassandraObject::Base.with_connection do
38
+ CassandraObject::Base.with_connection(key) do
39
+ result = ActiveSupport::Notifications.instrument("get_counter.cassandra_object", column_family: column_family, key: key, column: column) do
40
40
  connection.get(column_family, key, column, opts)
41
41
  end
42
42
  end
@@ -50,8 +50,8 @@ module CassandraObject
50
50
 
51
51
  def all(options = {})
52
52
  limit = options[:limit] || 100
53
- results = ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, key_count: limit) do
54
- CassandraObject::Base.with_connection do
53
+ results = CassandraObject::Base.with_connection do
54
+ ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, key_count: limit) do
55
55
  connection.get_range(column_family, key_count: limit, consistency: thrift_read_consistency)
56
56
  end
57
57
  end
@@ -88,7 +88,7 @@ module CassandraObject
88
88
 
89
89
  # Selecting a slice of a super column
90
90
  def get_slice(key, start, finish, opts={})
91
- CassandraObject::Base.with_connection do
91
+ CassandraObject::Base.with_connection(key) do
92
92
  connection.get_slice(column_family,
93
93
  key,
94
94
  start,
@@ -118,8 +118,8 @@ module CassandraObject
118
118
  end
119
119
 
120
120
  def multi_get(keys, options={})
121
- attribute_results = ActiveSupport::Notifications.instrument("multi_get.cassandra_object", column_family: column_family, keys: keys) do
122
- CassandraObject::Base.with_connection do
121
+ attribute_results = CassandraObject::Base.with_connection do
122
+ ActiveSupport::Notifications.instrument("multi_get.cassandra_object", column_family: column_family, keys: keys) do
123
123
  connection.multi_get(column_family, keys.map(&:to_s), consistency: thrift_read_consistency)
124
124
  end
125
125
  end
@@ -130,8 +130,8 @@ module CassandraObject
130
130
  def multi_get_by_expression(expression, options={})
131
131
  options = options.reverse_merge(:consistency => thrift_read_consistency)
132
132
 
133
- attribute_results = ActiveSupport::Notifications.instrument("multi_get_by_expression.cassandra_object", column_family: column_family, expression: expression) do
134
- CassandraObject::Base.with_connection do
133
+ attribute_results = CassandraObject::Base.with_connection do
134
+ ActiveSupport::Notifications.instrument("multi_get_by_expression.cassandra_object", column_family: column_family, expression: expression) do
135
135
  intermediate_results = connection.get_indexed_slices(column_family, expression, options)
136
136
  connection.send(:multi_columns_to_hash!, column_family, intermediate_results)
137
137
  end
@@ -8,8 +8,8 @@ module CassandraObject
8
8
  # the options are removed, leaving just columns
9
9
  columns = columns_and_options
10
10
 
11
- ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column, sub_column: sub_column, value: value) do
12
- CassandraObject::Base.with_connection do
11
+ CassandraObject::Base.with_connection(key) do
12
+ ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column, sub_column: sub_column, value: value) do
13
13
  connection.add(column_family, key, value, *columns, :consistency => thrift_write_consistency)
14
14
  end
15
15
  end
@@ -28,16 +28,16 @@ module CassandraObject
28
28
  values.uniq!
29
29
  value_spec = values.length == 1 ? values[0] : '<various>'
30
30
 
31
- ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column_spec, value: value_spec) do
32
- CassandraObject::Base.with_connection do
31
+ CassandraObject::Base.with_connection(key) do
32
+ ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column_spec, value: value_spec) do
33
33
  connection.add_multiple_columns(column_family, key, hash, :consistency => thrift_write_consistency)
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
38
  def remove(key)
39
- ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
40
- CassandraObject::Base.with_connection do
39
+ CassandraObject::Base.with_connection(key) do
40
+ ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
41
41
  connection.remove(column_family, key.to_s, consistency: thrift_write_consistency)
42
42
  end
43
43
  end
@@ -46,17 +46,17 @@ module CassandraObject
46
46
  # remove_counter is not exposed by Cassandra gem.
47
47
  # TODO: move this to Cassandra gem.
48
48
  def remove_counter(key)
49
- ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
50
- parent = CassandraThrift::ColumnParent.new(:column_family => column_family)
51
- CassandraObject::Base.with_connection do
49
+ CassandraObject::Base.with_connection(key) do
50
+ ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
51
+ parent = CassandraThrift::ColumnParent.new(:column_family => column_family)
52
52
  connection.send(:client).remove_counter(key, parent, thrift_write_consistency)
53
53
  end
54
54
  end
55
55
  end
56
56
 
57
57
  def delete_all
58
- ActiveSupport::Notifications.instrument("truncate.cassandra_object", column_family: column_family) do
59
- CassandraObject::Base.with_connection do
58
+ CassandraObject::Base.with_connection do
59
+ ActiveSupport::Notifications.instrument("truncate.cassandra_object", column_family: column_family) do
60
60
  connection.truncate!(column_family)
61
61
  end
62
62
  end
@@ -72,13 +72,14 @@ module CassandraObject
72
72
  key.tap do |key|
73
73
  unless attributes.blank?
74
74
  attributes = encode_columns_hash(attributes, schema_version)
75
- ActiveSupport::Notifications.instrument("insert.cassandra_object", column_family: column_family, key: key, attributes: attributes) do
75
+ CassandraObject::Base.with_connection(key) do
76
+ ActiveSupport::Notifications.instrument("insert.cassandra_object", column_family: column_family, key: key, attributes: attributes) do
76
77
 
77
- options = {}.tap do |options|
78
- options[:consistency] = thrift_write_consistency
79
- options[:ttl] = row_ttl unless row_ttl.nil?
80
- end
81
- CassandraObject::Base.with_connection do
78
+ options = {}.tap do |options|
79
+ options[:consistency] = thrift_write_consistency
80
+ options[:ttl] = row_ttl unless row_ttl.nil?
81
+ end
82
+
82
83
  connection.insert(column_family, key.to_s, attributes, options)
83
84
  end
84
85
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '2.5.1'
5
+ s.version = '2.5.2'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-06-05 00:00:00.000000000 Z
14
+ date: 2013-06-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails