gotime-cassandra_object 4.4.5 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/persistence.rb +28 -11
- data/lib/cassandra_object/schema/tasks.rb +13 -2
- data/lib/cassandra_object/tasks/ks.rake +3 -1
- data/test/support/connect.rb +2 -1
- data/test/support/teardown.rb +2 -0
- data/test/unit/persistence_test.rb +22 -4
- data/test/unit/schema/tasks_test.rb +13 -0
- metadata +2 -2
data/Gemfile
CHANGED
@@ -29,24 +29,41 @@ module CassandraObject
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def batch_start
|
33
33
|
@batch = []
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
36
|
+
def batch_statement
|
37
|
+
return nil unless @batch.any?
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
"BEGIN BATCH#{write_option_string}",
|
39
|
+
[
|
40
|
+
"BEGIN BATCH#{write_option_string(true)}",
|
42
41
|
@batch * "\n",
|
43
42
|
'APPLY BATCH'
|
44
|
-
|
43
|
+
] * "\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
def batch_end
|
47
|
+
if @batch.any?
|
48
|
+
execute_cql batch_statement
|
45
49
|
end
|
46
50
|
ensure
|
47
51
|
@batch = nil
|
48
52
|
end
|
49
53
|
|
54
|
+
def batching?
|
55
|
+
!@batch.nil?
|
56
|
+
end
|
57
|
+
|
58
|
+
def batch
|
59
|
+
batch_start
|
60
|
+
|
61
|
+
yield
|
62
|
+
|
63
|
+
ensure
|
64
|
+
batch_end
|
65
|
+
end
|
66
|
+
|
50
67
|
def instantiate(id, attributes)
|
51
68
|
allocate.tap do |object|
|
52
69
|
object.instance_variable_set("@id", id) if id
|
@@ -74,14 +91,14 @@ module CassandraObject
|
|
74
91
|
execute_cql cql_string, *bind_vars
|
75
92
|
end
|
76
93
|
end
|
77
|
-
|
94
|
+
|
78
95
|
def typecast_attributes(object, attributes)
|
79
96
|
attributes = attributes.symbolize_keys
|
80
97
|
Hash[attribute_definitions.map { |k, attribute_definition| [k.to_s, attribute_definition.instantiate(object, attributes[k])] }]
|
81
98
|
end
|
82
99
|
|
83
|
-
def write_option_string
|
84
|
-
if base_class.default_consistency
|
100
|
+
def write_option_string(ignore_batching = false)
|
101
|
+
if (ignore_batching || !batching?) && base_class.default_consistency
|
85
102
|
" USING CONSISTENCY #{base_class.default_consistency}"
|
86
103
|
end
|
87
104
|
end
|
@@ -8,8 +8,19 @@ module CassandraObject
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def load(
|
12
|
-
|
11
|
+
def load(io)
|
12
|
+
current_cql = ''
|
13
|
+
|
14
|
+
io.each_line do |line|
|
15
|
+
next if line.blank?
|
16
|
+
|
17
|
+
current_cql << line.rstrip
|
18
|
+
|
19
|
+
if current_cql =~ /;$/
|
20
|
+
CassandraObject::Base.execute_cql current_cql
|
21
|
+
current_cql = ''
|
22
|
+
end
|
23
|
+
end
|
13
24
|
end
|
14
25
|
|
15
26
|
def column_families
|
@@ -38,7 +38,9 @@ ks_namespace = namespace :ks do
|
|
38
38
|
|
39
39
|
task load: :environment do
|
40
40
|
filename = ENV['SCHEMA'] || "#{Rails.root}/ks/structure.cql"
|
41
|
-
|
41
|
+
File.open(filename) do |file|
|
42
|
+
CassandraObject::Schema.load(file)
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
data/test/support/connect.rb
CHANGED
data/test/support/teardown.rb
CHANGED
@@ -29,12 +29,30 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
|
|
29
29
|
first_issue = Issue.create
|
30
30
|
second_issue = Issue.create
|
31
31
|
|
32
|
-
assert_raise(CassandraObject::RecordNotFound) { Issue.find
|
33
|
-
assert_raise(CassandraObject::RecordNotFound) { Issue.find
|
32
|
+
assert_raise(CassandraObject::RecordNotFound) { Issue.find(first_issue.id) }
|
33
|
+
assert_raise(CassandraObject::RecordNotFound) { Issue.find(second_issue.id) }
|
34
34
|
end
|
35
35
|
|
36
|
-
assert_nothing_raised(CassandraObject::RecordNotFound) { Issue.find
|
37
|
-
assert_nothing_raised(CassandraObject::RecordNotFound) { Issue.find
|
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
|
+
assert !Issue.batching?
|
44
|
+
Issue.batch_start
|
45
|
+
|
46
|
+
second_issue = Issue.create
|
47
|
+
assert Issue.batching?
|
48
|
+
|
49
|
+
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
|
+
assert_nothing_raised(CassandraObject::RecordNotFound) { Issue.find(second_issue.id) }
|
55
|
+
|
38
56
|
end
|
39
57
|
|
40
58
|
test 'persistance inquiries' do
|
@@ -13,4 +13,17 @@ class CassandraObject::Schema::TasksTest < CassandraObject::TestCase
|
|
13
13
|
|
14
14
|
assert_match /Issues/, io.read
|
15
15
|
end
|
16
|
+
|
17
|
+
test "load" do
|
18
|
+
CassandraObject::Base.expects(:execute_cql).with("DO STUFF;")
|
19
|
+
CassandraObject::Base.expects(:execute_cql).with("AND MORE;")
|
20
|
+
|
21
|
+
CassandraObject::Schema.load StringIO.new(
|
22
|
+
"DO\n" +
|
23
|
+
" STUFF;\n" +
|
24
|
+
"\n" +
|
25
|
+
"AND\n" +
|
26
|
+
" MORE;\n"
|
27
|
+
)
|
28
|
+
end
|
16
29
|
end
|
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.
|
4
|
+
version: 4.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|