sessionm-cassandra_object 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,7 +39,9 @@ module CassandraObject
39
39
  def remove(key)
40
40
  begin
41
41
  ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: relationships_column_family, key: key) do
42
- connection.remove(relationships_column_family, key.to_s, consistency: thrift_write_consistency)
42
+ CassandraObject::Base.with_connection do
43
+ connection.remove(relationships_column_family, key.to_s, consistency: thrift_write_consistency)
44
+ end
43
45
  end
44
46
  rescue Cassandra::AccessError => e
45
47
  raise e unless e.message =~ /Invalid column family/
@@ -20,7 +20,9 @@ module CassandraObject
20
20
  key = owner.key
21
21
  attributes = {@association_name=>{new_key=>record.key.to_s}}
22
22
  ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
23
- connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
23
+ CassandraObject::Base.with_connection do
24
+ connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
25
+ end
24
26
  end
25
27
  if has_inverse? && set_inverse
26
28
  inverse.set_inverse(record, owner)
@@ -25,15 +25,19 @@ module CassandraObject
25
25
 
26
26
  def clear(owner)
27
27
  ActiveSupport::Notifications.instrument("remove.cassandra_object", :column_family => column_family, :key => owner.key, :columns => @association_name) do
28
- connection.remove(column_family, owner.key.to_s, @association_name)
28
+ CassandraObject::Base.with_connection do
29
+ connection.remove(column_family, owner.key.to_s, @association_name)
30
+ end
29
31
  end
30
32
  end
31
33
 
32
34
  def find(owner)
33
- if key = connection.get(column_family, owner.key.to_s, @association_name.to_s, :count=>1).values.first
34
- target_class.get(key)
35
- else
36
- nil
35
+ CassandraObject::Base.with_connection do
36
+ if key = connection.get(column_family, owner.key.to_s, @association_name.to_s, :count=>1).values.first
37
+ target_class.get(key)
38
+ else
39
+ nil
40
+ end
37
41
  end
38
42
  end
39
43
 
@@ -42,7 +46,9 @@ module CassandraObject
42
46
  key = owner.key
43
47
  attributes = {@association_name=>{new_key=>record.key.to_s}}
44
48
  ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
45
- connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
49
+ CassandraObject::Base.with_connection do
50
+ connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
51
+ end
46
52
  end
47
53
  if has_inverse? && set_inverse
48
54
  inverse.set_inverse(record, owner)
@@ -23,11 +23,16 @@ module CassandraObject
23
23
  end
24
24
 
25
25
  while objects.size < number_to_find && !out_of_keys
26
- index_results = connection.get(@column_family, @key, @super_column,
27
- count: limit,
28
- start: start_with,
29
- reversed: @options[:reversed],
30
- consistency: target_class.thrift_read_consistency)
26
+ index_results =
27
+ begin
28
+ CassandraObject::Base.with_connection do
29
+ connection.get(@column_family, @key, @super_column,
30
+ count: limit,
31
+ start: start_with,
32
+ reversed: @options[:reversed],
33
+ consistency: target_class.thrift_read_consistency)
34
+ end
35
+ end
31
36
 
32
37
  out_of_keys = index_results.size < limit
33
38
 
@@ -80,7 +85,9 @@ module CassandraObject
80
85
  end
81
86
 
82
87
  def remove(index_key)
83
- connection.remove(@column_family, @key, @super_column, index_key, consistency: target_class.thrift_write_consistency)
88
+ CassandraObject::Base.with_connection do
89
+ connection.remove(@column_family, @key, @super_column, index_key, consistency: target_class.thrift_write_consistency)
90
+ end
84
91
  end
85
92
 
86
93
  def validator(&validator)
@@ -9,8 +9,16 @@ module CassandraObject
9
9
  raise(ArgumentError, "unexpected conditions") if opts[:conditions].present?
10
10
  raise(CassandraObject::InvalidKey, "invalid key: #{key}") if key.blank? || ! parse_key(key)
11
11
 
12
- if (attributes = ActiveSupport::Notifications.instrument("get.cassandra_object", column_family: column_family, key: key) { connection.get(column_family, key, opts.slice(:consistency)) }) &&
13
- !attributes.empty?
12
+ attributes =
13
+ begin
14
+ ActiveSupport::Notifications.instrument("get.cassandra_object", column_family: column_family, key: key) do
15
+ CassandraObject::Base.with_connection do
16
+ connection.get column_family, key, opts.slice(:consistency)
17
+ end
18
+ end
19
+ end
20
+
21
+ if attributes && ! attributes.empty?
14
22
  instantiate(key, attributes)
15
23
  else
16
24
  raise CassandraObject::RecordNotFound
@@ -28,7 +36,9 @@ module CassandraObject
28
36
  opts[:consistency] ||= thrift_read_consistency
29
37
 
30
38
  result = ActiveSupport::Notifications.instrument("get_counter.cassandra_object", column_family: column_family, key: key, column: column) do
31
- connection.get(column_family, key, column, opts)
39
+ CassandraObject::Base.with_connection do
40
+ connection.get(column_family, key, column, opts)
41
+ end
32
42
  end
33
43
 
34
44
  if result
@@ -41,7 +51,9 @@ module CassandraObject
41
51
  def all(options = {})
42
52
  limit = options[:limit] || 100
43
53
  results = ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, key_count: limit) do
44
- connection.get_range(column_family, key_count: limit, consistency: thrift_read_consistency)
54
+ CassandraObject::Base.with_connection do
55
+ connection.get_range(column_family, key_count: limit, consistency: thrift_read_consistency)
56
+ end
45
57
  end
46
58
 
47
59
  results.map do |k, v|
@@ -76,13 +88,15 @@ module CassandraObject
76
88
 
77
89
  # Selecting a slice of a super column
78
90
  def get_slice(key, start, finish, opts={})
79
- connection.get_slice(column_family,
80
- key,
81
- start,
82
- finish,
83
- opts[:count] || 100,
84
- opts[:reversed] || false,
85
- opts[:consistency] || thrift_read_consistency)
91
+ CassandraObject::Base.with_connection do
92
+ connection.get_slice(column_family,
93
+ key,
94
+ start,
95
+ finish,
96
+ opts[:count] || 100,
97
+ opts[:reversed] || false,
98
+ opts[:consistency] || thrift_read_consistency)
99
+ end
86
100
  end
87
101
 
88
102
  private
@@ -105,7 +119,9 @@ module CassandraObject
105
119
 
106
120
  def multi_get(keys, options={})
107
121
  attribute_results = ActiveSupport::Notifications.instrument("multi_get.cassandra_object", column_family: column_family, keys: keys) do
108
- connection.multi_get(column_family, keys.map(&:to_s), consistency: thrift_read_consistency)
122
+ CassandraObject::Base.with_connection do
123
+ connection.multi_get(column_family, keys.map(&:to_s), consistency: thrift_read_consistency)
124
+ end
109
125
  end
110
126
 
111
127
  instantiate_many(attribute_results)
@@ -115,8 +131,10 @@ module CassandraObject
115
131
  options = options.reverse_merge(:consistency => thrift_read_consistency)
116
132
 
117
133
  attribute_results = ActiveSupport::Notifications.instrument("multi_get_by_expression.cassandra_object", column_family: column_family, expression: expression) do
118
- intermediate_results = connection.get_indexed_slices(column_family, expression, options)
119
- connection.send(:multi_columns_to_hash!, column_family, intermediate_results)
134
+ CassandraObject::Base.with_connection do
135
+ intermediate_results = connection.get_indexed_slices(column_family, expression, options)
136
+ connection.send(:multi_columns_to_hash!, column_family, intermediate_results)
137
+ end
120
138
  end
121
139
 
122
140
  instantiate_many(attribute_results)
@@ -4,12 +4,14 @@ module CassandraObject
4
4
 
5
5
  module ClassMethods
6
6
  def add(key, value, *columns_and_options)
7
- column_family, column, sub_column, options = connection.extract_and_validate_params(self.column_family, key, columns_and_options, {})
7
+ column_family, column, sub_column, options = CassandraObject::Base.with_connection { connection.extract_and_validate_params(self.column_family, key, columns_and_options, {}) }
8
8
  # the options are removed, leaving just columns
9
9
  columns = columns_and_options
10
10
 
11
11
  ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column, sub_column: sub_column, value: value) do
12
- connection.add(column_family, key, value, *columns, :consistency => thrift_write_consistency)
12
+ CassandraObject::Base.with_connection do
13
+ connection.add(column_family, key, value, *columns, :consistency => thrift_write_consistency)
14
+ end
13
15
  end
14
16
  end
15
17
 
@@ -27,13 +29,17 @@ module CassandraObject
27
29
  value_spec = values.length == 1 ? values[0] : '<various>'
28
30
 
29
31
  ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column_spec, value: value_spec) do
30
- connection.add_multiple_columns(column_family, key, hash, :consistency => thrift_write_consistency)
32
+ CassandraObject::Base.with_connection do
33
+ connection.add_multiple_columns(column_family, key, hash, :consistency => thrift_write_consistency)
34
+ end
31
35
  end
32
36
  end
33
37
 
34
38
  def remove(key)
35
- ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
36
- connection.remove(column_family, key.to_s, consistency: thrift_write_consistency)
39
+ ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
40
+ CassandraObject::Base.with_connection do
41
+ connection.remove(column_family, key.to_s, consistency: thrift_write_consistency)
42
+ end
37
43
  end
38
44
  end
39
45
 
@@ -42,13 +48,17 @@ module CassandraObject
42
48
  def remove_counter(key)
43
49
  ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
44
50
  parent = CassandraThrift::ColumnParent.new(:column_family => column_family)
45
- connection.send(:client).remove_counter(key, parent, thrift_write_consistency)
51
+ CassandraObject::Base.with_connection do
52
+ connection.send(:client).remove_counter(key, parent, thrift_write_consistency)
53
+ end
46
54
  end
47
55
  end
48
56
 
49
57
  def delete_all
50
58
  ActiveSupport::Notifications.instrument("truncate.cassandra_object", column_family: column_family) do
51
- connection.truncate!(column_family)
59
+ CassandraObject::Base.with_connection do
60
+ connection.truncate!(column_family)
61
+ end
52
62
  end
53
63
  end
54
64
 
@@ -68,7 +78,9 @@ module CassandraObject
68
78
  options[:consistency] = thrift_write_consistency
69
79
  options[:ttl] = row_ttl unless row_ttl.nil?
70
80
  end
71
- connection.insert(column_family, key.to_s, attributes, options)
81
+ CassandraObject::Base.with_connection do
82
+ connection.insert(column_family, key.to_s, attributes, options)
83
+ end
72
84
  end
73
85
  end
74
86
  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.0'
5
+ s.version = '2.5.1'
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.0
4
+ version: 2.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: