gotime-cassandra_object 4.7.1 → 4.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/base.rb +15 -6
- data/lib/cassandra_object/belongs_to.rb +4 -0
- data/lib/cassandra_object/belongs_to/association.rb +4 -9
- data/lib/cassandra_object/persistence.rb +14 -26
- data/lib/cassandra_object/schema.rb +1 -1
- data/lib/gotime-cassandra_object.rb +1 -0
- data/test/unit/base_test.rb +1 -0
- data/test/unit/belongs_to_test.rb +10 -0
- data/test/unit/config_test.rb +1 -1
- data/test/unit/persistence_test.rb +2 -17
- metadata +16 -16
@@ -2,7 +2,6 @@ require 'set'
|
|
2
2
|
|
3
3
|
require 'cassandra_object/log_subscriber'
|
4
4
|
require 'cassandra_object/types'
|
5
|
-
require 'cassandra_object/errors'
|
6
5
|
|
7
6
|
module CassandraObject
|
8
7
|
class Base
|
@@ -16,11 +15,7 @@ module CassandraObject
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def base_class
|
19
|
-
|
20
|
-
while klass.superclass != Base
|
21
|
-
klass = klass.superclass
|
22
|
-
end
|
23
|
-
klass
|
18
|
+
class_of_active_record_descendant(self)
|
24
19
|
end
|
25
20
|
|
26
21
|
def config=(config)
|
@@ -30,6 +25,20 @@ module CassandraObject
|
|
30
25
|
def config
|
31
26
|
@@config
|
32
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Returns the class descending directly from ActiveRecord::Base or an
|
32
|
+
# abstract class, if any, in the inheritance hierarchy.
|
33
|
+
def class_of_active_record_descendant(klass)
|
34
|
+
if klass == Base || klass.superclass == Base
|
35
|
+
klass
|
36
|
+
elsif klass.superclass.nil?
|
37
|
+
raise "#{name} doesn't belong in a hierarchy descending from CassandraObject"
|
38
|
+
else
|
39
|
+
class_of_active_record_descendant(klass.superclass)
|
40
|
+
end
|
41
|
+
end
|
33
42
|
end
|
34
43
|
|
35
44
|
extend ActiveModel::Naming
|
@@ -2,6 +2,7 @@ module CassandraObject
|
|
2
2
|
module BelongsTo
|
3
3
|
class Association
|
4
4
|
attr_reader :owner, :reflection
|
5
|
+
attr_accessor :record_variable
|
5
6
|
delegate :options, to: :reflection
|
6
7
|
|
7
8
|
def initialize(owner, reflection)
|
@@ -16,6 +17,7 @@ module CassandraObject
|
|
16
17
|
else
|
17
18
|
self.record_variable = nil
|
18
19
|
end
|
20
|
+
@loaded = true
|
19
21
|
end
|
20
22
|
|
21
23
|
record_variable
|
@@ -23,6 +25,7 @@ module CassandraObject
|
|
23
25
|
|
24
26
|
def writer(record)
|
25
27
|
self.record_variable = record
|
28
|
+
@loaded = true
|
26
29
|
owner.send("#{reflection.foreign_key}=", record.try(:id))
|
27
30
|
if reflection.polymorphic?
|
28
31
|
owner.send("#{reflection.polymorphic_column}=", record.class.name)
|
@@ -37,16 +40,8 @@ module CassandraObject
|
|
37
40
|
reflection.polymorphic? ? owner.send(reflection.polymorphic_column) : reflection.class_name
|
38
41
|
end
|
39
42
|
|
40
|
-
def record_variable
|
41
|
-
owner.instance_variable_get(reflection.instance_variable_name)
|
42
|
-
end
|
43
|
-
|
44
|
-
def record_variable=(record)
|
45
|
-
owner.instance_variable_set(reflection.instance_variable_name, record)
|
46
|
-
end
|
47
|
-
|
48
43
|
def loaded?
|
49
|
-
|
44
|
+
@loaded
|
50
45
|
end
|
51
46
|
end
|
52
47
|
end
|
@@ -29,39 +29,16 @@ module CassandraObject
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def batch_start
|
33
|
-
@batch = []
|
34
|
-
end
|
35
|
-
|
36
|
-
def batch_statement
|
37
|
-
return nil unless @batch.any?
|
38
|
-
|
39
|
-
[
|
40
|
-
"BEGIN BATCH#{write_option_string(true)}",
|
41
|
-
@batch * "\n",
|
42
|
-
'APPLY BATCH'
|
43
|
-
] * "\n"
|
44
|
-
end
|
45
|
-
|
46
|
-
def batch_end
|
47
|
-
if @batch.any?
|
48
|
-
execute_cql batch_statement
|
49
|
-
end
|
50
|
-
ensure
|
51
|
-
@batch = nil
|
52
|
-
end
|
53
|
-
|
54
32
|
def batching?
|
55
33
|
!@batch.nil?
|
56
34
|
end
|
57
35
|
|
58
36
|
def batch
|
59
|
-
|
60
|
-
|
37
|
+
@batch = []
|
61
38
|
yield
|
62
|
-
|
39
|
+
execute_cql(batch_statement) if @batch.any?
|
63
40
|
ensure
|
64
|
-
|
41
|
+
@batch = nil
|
65
42
|
end
|
66
43
|
|
67
44
|
def instantiate(id, attributes)
|
@@ -89,6 +66,16 @@ module CassandraObject
|
|
89
66
|
column_names.map { |name| "'#{name}'" }
|
90
67
|
end
|
91
68
|
|
69
|
+
def batch_statement
|
70
|
+
return nil unless @batch.any?
|
71
|
+
|
72
|
+
[
|
73
|
+
"BEGIN BATCH#{write_option_string(true)}",
|
74
|
+
@batch * "\n",
|
75
|
+
'APPLY BATCH'
|
76
|
+
] * "\n"
|
77
|
+
end
|
78
|
+
|
92
79
|
def execute_batchable_cql(cql_string, *bind_vars)
|
93
80
|
if @batch
|
94
81
|
@batch << CassandraCQL::Statement.sanitize(cql_string, bind_vars)
|
@@ -156,6 +143,7 @@ module CassandraObject
|
|
156
143
|
end
|
157
144
|
|
158
145
|
def reload
|
146
|
+
clear_belongs_to_cache
|
159
147
|
@attributes.update(self.class.find(id).instance_variable_get('@attributes'))
|
160
148
|
self
|
161
149
|
end
|
data/test/unit/base_test.rb
CHANGED
@@ -49,4 +49,14 @@ class CassandraObject::BelongsToTest < CassandraObject::TestCase
|
|
49
49
|
record = TestObject.find(record.id)
|
50
50
|
assert_equal issue, record.target
|
51
51
|
end
|
52
|
+
|
53
|
+
test 'belongs_to clear cache after reload' do
|
54
|
+
issue = Issue.create
|
55
|
+
record = TestObject.create(issue: issue)
|
56
|
+
issue.destroy
|
57
|
+
|
58
|
+
assert_not_nil record.issue
|
59
|
+
assert_nil TestObject.find(record.id).issue
|
60
|
+
assert_nil record.reload.issue
|
61
|
+
end
|
52
62
|
end
|
data/test/unit/config_test.rb
CHANGED
@@ -14,7 +14,7 @@ class CassandraObject::ConfigTest < CassandraObject::TestCase
|
|
14
14
|
assert_equal 10, config.thrift_options[:timeout]
|
15
15
|
assert_equal 'NetworkTopologyStrategy', config.keyspace_options[:placement_strategy]
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
test 'defaults' do
|
19
19
|
config = CassandraObject::Config.new(keyspace: 'widget_factory')
|
20
20
|
|
@@ -26,6 +26,8 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
|
|
26
26
|
first_issue = second_issue = nil
|
27
27
|
|
28
28
|
Issue.batch do
|
29
|
+
assert Issue.batching?
|
30
|
+
|
29
31
|
first_issue = Issue.create
|
30
32
|
second_issue = Issue.create
|
31
33
|
|
@@ -33,26 +35,9 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
|
|
33
35
|
assert_raise(CassandraObject::RecordNotFound) { Issue.find(second_issue.id) }
|
34
36
|
end
|
35
37
|
|
36
|
-
assert_nothing_raised(CassandraObject::RecordNotFound) { Issue.find(first_issue.id) }
|
37
|
-
assert_nothing_raised(CassandraObject::RecordNotFound) { Issue.find(second_issue.id) }
|
38
|
-
end
|
39
|
-
|
40
|
-
test "batch state" do
|
41
|
-
first_issue = Issue.create
|
42
|
-
|
43
38
|
assert !Issue.batching?
|
44
|
-
Issue.batch_start
|
45
|
-
|
46
|
-
second_issue = Issue.create
|
47
|
-
assert Issue.batching?
|
48
|
-
|
49
39
|
assert_nothing_raised(CassandraObject::RecordNotFound) { Issue.find(first_issue.id) }
|
50
|
-
assert_raise(CassandraObject::RecordNotFound) { Issue.find(second_issue.id) }
|
51
|
-
|
52
|
-
Issue.batch_end
|
53
|
-
|
54
40
|
assert_nothing_raised(CassandraObject::RecordNotFound) { Issue.find(second_issue.id) }
|
55
|
-
|
56
41
|
end
|
57
42
|
|
58
43
|
test 'persistance inquiries' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotime-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.7.
|
4
|
+
version: 4.7.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,72 +10,72 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
+
prerelease: false
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '3.0'
|
23
|
+
none: false
|
23
24
|
type: :runtime
|
24
|
-
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
26
|
requirements:
|
28
27
|
- - ! '>='
|
29
28
|
- !ruby/object:Gem::Version
|
30
29
|
version: '3.0'
|
30
|
+
none: false
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: cassandra-cql
|
33
|
+
prerelease: false
|
33
34
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
35
|
requirements:
|
36
36
|
- - ! '>='
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
|
+
none: false
|
39
40
|
type: :runtime
|
40
|
-
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
42
|
requirements:
|
44
43
|
- - ! '>='
|
45
44
|
- !ruby/object:Gem::Version
|
46
45
|
version: '0'
|
46
|
+
none: false
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: thrift_client
|
49
|
+
prerelease: false
|
49
50
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.8.0
|
55
|
+
none: false
|
55
56
|
type: :runtime
|
56
|
-
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
58
|
requirements:
|
60
59
|
- - ~>
|
61
60
|
- !ruby/object:Gem::Version
|
62
61
|
version: 0.8.0
|
62
|
+
none: false
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: bundler
|
65
|
+
prerelease: false
|
65
66
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
67
|
requirements:
|
68
68
|
- - ! '>='
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
|
+
none: false
|
71
72
|
type: :development
|
72
|
-
prerelease: false
|
73
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
74
|
requirements:
|
76
75
|
- - ! '>='
|
77
76
|
- !ruby/object:Gem::Version
|
78
77
|
version: '0'
|
78
|
+
none: false
|
79
79
|
description: Cassandra ActiveModel
|
80
80
|
email: gems@gotime.com
|
81
81
|
executables: []
|
@@ -184,17 +184,17 @@ rdoc_options: []
|
|
184
184
|
require_paths:
|
185
185
|
- lib
|
186
186
|
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
-
none: false
|
188
187
|
requirements:
|
189
188
|
- - ! '>='
|
190
189
|
- !ruby/object:Gem::Version
|
191
190
|
version: 1.9.2
|
192
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
191
|
none: false
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
193
|
requirements:
|
195
194
|
- - ! '>='
|
196
195
|
- !ruby/object:Gem::Version
|
197
196
|
version: 1.3.5
|
197
|
+
none: false
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
200
|
rubygems_version: 1.8.24
|