eurydice 1.1.0.b4-java → 1.1.1.b1-java

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,11 +1,9 @@
1
1
  source :rubygems
2
2
 
3
- gem 'pelops-jars', '1.3.0.b3'
4
-
5
3
  gemspec
6
4
 
7
5
  group :development do
8
6
  gem 'jruby-openssl'
9
7
  gem 'rake'
10
- gem 'rspec'
8
+ gem 'rspec', '2.7.0' # 2.8.0 doesn't work with JRuby because of JRUBY-6324
11
9
  end
data/Gemfile.lock CHANGED
@@ -1,28 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eurydice (1.1.0.b3-java)
5
- pelops-jars (>= 1.2.9)
4
+ eurydice (1.1.0.b4-java)
5
+ pelops-jars (>= 1.3.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  bouncy-castle-java (1.5.0146.1)
11
11
  cassandra-jars (1.0.0-java)
12
- diff-lcs (1.1.2)
12
+ diff-lcs (1.1.3)
13
13
  jruby-openssl (0.7.4)
14
14
  bouncy-castle-java
15
- pelops-jars (1.3.0.b3-java)
15
+ pelops-jars (1.3.0-java)
16
16
  cassandra-jars (~> 1.0.0)
17
17
  rake (0.9.2)
18
- rspec (2.6.0)
19
- rspec-core (~> 2.6.0)
20
- rspec-expectations (~> 2.6.0)
21
- rspec-mocks (~> 2.6.0)
22
- rspec-core (2.6.4)
23
- rspec-expectations (2.6.0)
18
+ rspec (2.7.0)
19
+ rspec-core (~> 2.7.0)
20
+ rspec-expectations (~> 2.7.0)
21
+ rspec-mocks (~> 2.7.0)
22
+ rspec-core (2.7.1)
23
+ rspec-expectations (2.7.0)
24
24
  diff-lcs (~> 1.1.2)
25
- rspec-mocks (2.6.0)
25
+ rspec-mocks (2.7.0)
26
26
 
27
27
  PLATFORMS
28
28
  java
@@ -30,6 +30,5 @@ PLATFORMS
30
30
  DEPENDENCIES
31
31
  eurydice!
32
32
  jruby-openssl
33
- pelops-jars (= 1.3.0.b3)
34
33
  rake
35
- rspec
34
+ rspec (= 2.7.0)
data/eurydice.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.rubyforge_project = 'eurydice'
19
19
 
20
- s.add_dependency 'pelops-jars', '>= 1.2.9'
20
+ s.add_dependency 'pelops-jars', '>= 1.3.0'
21
21
 
22
22
  s.files = `git ls-files`.split("\n")
23
23
  s.require_paths = %w(lib)
@@ -5,7 +5,7 @@ require_relative 'common'
5
5
 
6
6
  # Connect to the default host (localhost) and port (9160), these can be
7
7
  # overridden by passing then :host and :port options.
8
- cluster = Eurydice.connect(:timeout => 3000)
8
+ cluster = Eurydice.connect
9
9
 
10
10
  # Get a reference to a keyspace, it will be created if it does not exist
11
11
  # (pass the option :create => false to not automatically create the keyspace).
@@ -47,34 +47,20 @@ module Eurydice
47
47
  end
48
48
 
49
49
  def delete_column(row_key, column_key, options={})
50
- thrift_exception_handler do
51
- mutator = @keyspace.create_mutator
52
- mutator.delete_column(@name, row_key, to_pelops_bytes(column_key))
53
- mutator.execute(get_cl(options))
50
+ batch(options) do |b|
51
+ b.delete_column(row_key, column_key)
54
52
  end
55
53
  end
56
54
 
57
55
  def delete_columns(row_key, column_keys, options={})
58
- thrift_exception_handler do
59
- mutator = @keyspace.create_mutator
60
- mutator.delete_columns(@name, row_key, column_keys.map { |k| to_pelops_bytes(k) })
61
- mutator.execute(get_cl(options))
56
+ batch(options) do |b|
57
+ b.delete_columns(row_key, column_keys)
62
58
  end
63
59
  end
64
60
 
65
61
  def update(row_key, properties, options={})
66
- thrift_exception_handler do
67
- types = options[:validations] || {}
68
- key_type = options[:comparator]
69
- mutator = @keyspace.create_mutator
70
- columns = properties.map do |k, v|
71
- key = to_pelops_bytes(k, key_type)
72
- value = to_pelops_bytes(v, types[k])
73
- ttl = options.fetch(:ttl, mutator.class::NO_TTL)
74
- mutator.new_column(key, value, ttl)
75
- end
76
- mutator.write_columns(@name, row_key, columns)
77
- mutator.execute(get_cl(options))
62
+ batch(options) do |b|
63
+ b.update(row_key, properties, options)
78
64
  end
79
65
  end
80
66
  alias_method :insert, :update
@@ -170,6 +156,15 @@ module Eurydice
170
156
  end
171
157
  end
172
158
 
159
+ def batch(options={})
160
+ batch = Batch.new(@name, @keyspace)
161
+ if block_given?
162
+ yield batch
163
+ batch.execute!(options)
164
+ end
165
+ nil
166
+ end
167
+
173
168
  private
174
169
 
175
170
  EMPTY_STRING = ''.freeze
@@ -252,10 +247,53 @@ module Eurydice
252
247
  end
253
248
  return key, value
254
249
  end
255
-
256
- def get_cl(options)
257
- cl = options.fetch(:consistency_level, options.fetch(:cl, :one))
258
- Cassandra::CONSISTENCY_LEVELS[cl]
250
+
251
+ module ConsistencyLevelHelpers
252
+ def get_cl(options)
253
+ cl = options.fetch(:consistency_level, options.fetch(:cl, :one))
254
+ Cassandra::CONSISTENCY_LEVELS[cl]
255
+ end
256
+ end
257
+
258
+ include ConsistencyLevelHelpers
259
+
260
+ class Batch
261
+ include ExceptionHelpers
262
+ include ByteHelpers
263
+ include ConsistencyLevelHelpers
264
+
265
+ def initialize(name, keyspace)
266
+ @name = name
267
+ @keyspace = keyspace
268
+ @mutator = @keyspace.create_mutator
269
+ end
270
+
271
+ def delete_column(row_key, column_key)
272
+ @mutator.delete_column(@name, row_key, to_pelops_bytes(column_key))
273
+ end
274
+
275
+ def delete_columns(row_key, column_keys)
276
+ @mutator.delete_columns(@name, row_key, column_keys.map { |k| to_pelops_bytes(k) })
277
+ end
278
+
279
+ def update(row_key, properties, options={})
280
+ types = options[:validations] || {}
281
+ key_type = options[:comparator]
282
+ columns = properties.map do |k, v|
283
+ key = to_pelops_bytes(k, key_type)
284
+ value = to_pelops_bytes(v, types[k])
285
+ ttl = options.fetch(:ttl, @mutator.class::NO_TTL)
286
+ @mutator.new_column(key, value, ttl)
287
+ end
288
+ @mutator.write_columns(@name, row_key, columns)
289
+ end
290
+ alias_method :insert, :update
291
+
292
+ def execute!(options={})
293
+ thrift_exception_handler do
294
+ @mutator.execute(get_cl(options))
295
+ end
296
+ end
259
297
  end
260
298
  end
261
299
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
 
4
4
  module Eurydice
5
- VERSION = '1.1.0.b4'
5
+ VERSION = '1.1.1.b1'
6
6
  end
@@ -4,36 +4,11 @@ require_relative '../../spec_helper'
4
4
  module Eurydice
5
5
  module Pelops
6
6
  describe Cluster do
7
- it 'can connect' do
7
+ before :all do
8
8
  @cluster = Eurydice.connect
9
- @cluster.should be_connected
10
9
  end
11
-
12
- describe '#keyspace' do
13
- before do
14
- @cluster = Eurydice.connect
15
- @keyspace_name = "eurydice_test_space_#{rand(1000)}"
16
- if @cluster.keyspaces.include?(@keyspace_name)
17
- @cluster.keyspace(@keyspace_name).drop!
18
- end
19
- end
20
10
 
21
- after do
22
- @keyspace.drop! rescue nil
23
- end
24
-
25
- it 'creates a keyspace' do
26
- @keyspace = @cluster.keyspace(@keyspace_name)
27
- @keyspace.exists?.should be_true
28
- end
29
-
30
- it 'defers the creation of a keyspace with :create => false' do
31
- @keyspace = @cluster.keyspace(@keyspace_name, :create => false)
32
- @keyspace.exists?.should be_false
33
- @keyspace.create!
34
- @keyspace.exists?.should be_true
35
- end
36
- end
11
+ it_behaves_like 'Cluster', @cluster
37
12
  end
38
13
  end
39
14
  end