couchbase-jruby-client 0.1.0-java → 0.1.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.jrubyrc +722 -0
  3. data/.ruby-version +1 -1
  4. data/README.md +12 -90
  5. data/couchbase-jruby-client.gemspec +6 -6
  6. data/lib/couchbase/async.rb +18 -0
  7. data/lib/couchbase/bucket.rb +90 -180
  8. data/lib/couchbase/constants.rb +17 -0
  9. data/lib/couchbase/design_doc.rb +83 -0
  10. data/lib/couchbase/error.rb +31 -0
  11. data/lib/couchbase/operations/arithmetic.rb +17 -0
  12. data/lib/couchbase/operations/delete.rb +17 -0
  13. data/lib/couchbase/operations/design_docs.rb +99 -0
  14. data/lib/couchbase/operations/get.rb +73 -67
  15. data/lib/couchbase/operations/stats.rb +28 -1
  16. data/lib/couchbase/operations/store.rb +114 -97
  17. data/lib/couchbase/operations/touch.rb +49 -19
  18. data/lib/couchbase/operations/unlock.rb +209 -0
  19. data/lib/couchbase/operations/utils.rb +22 -10
  20. data/lib/couchbase/operations.rb +21 -0
  21. data/lib/couchbase/query.rb +92 -0
  22. data/lib/couchbase/result.rb +18 -1
  23. data/lib/couchbase/transcoder.rb +36 -42
  24. data/lib/couchbase/version.rb +18 -1
  25. data/lib/couchbase/view.rb +30 -172
  26. data/lib/couchbase/view_row.rb +38 -98
  27. data/lib/couchbase.rb +74 -72
  28. data/test/profile/.jrubyrc +722 -0
  29. data/test/profile/Gemfile +5 -5
  30. data/test/profile/benchmark.rb +106 -124
  31. data/test/profile/profile.rb +59 -0
  32. data/test/setup.rb +10 -145
  33. data/test/test_arithmetic.rb +54 -77
  34. data/test/test_async.rb +74 -102
  35. data/test/test_bucket.rb +74 -60
  36. data/test/test_cas.rb +10 -23
  37. data/test/test_couchbase.rb +11 -3
  38. data/test/test_delete.rb +41 -43
  39. data/test/test_design_docs.rb +62 -0
  40. data/test/test_errors.rb +9 -18
  41. data/test/test_format.rb +21 -31
  42. data/test/test_get.rb +107 -151
  43. data/test/test_query.rb +23 -0
  44. data/test/test_stats.rb +9 -24
  45. data/test/test_store.rb +52 -65
  46. data/test/test_timer.rb +4 -12
  47. data/test/test_touch.rb +26 -33
  48. data/test/test_unlock.rb +47 -78
  49. data/test/test_utils.rb +2 -11
  50. data/test/test_version.rb +5 -14
  51. data/test/test_view.rb +87 -0
  52. metadata +27 -14
  53. data/lib/couchbase/jruby/couchbase_client.rb +0 -22
  54. data/lib/couchbase/jruby/future.rb +0 -8
@@ -1,3 +1,20 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
1
18
  module Couchbase::Operations
2
19
  module Arithmetic
3
20
 
@@ -1,3 +1,20 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
1
18
  module Couchbase::Operations
2
19
  module Delete
3
20
 
@@ -0,0 +1,99 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the 'License');
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an 'AS IS' BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module Couchbase::Operations
19
+ module DesignDocs
20
+
21
+ java_import com.couchbase.client.protocol.views.DesignDocument
22
+ java_import com.couchbase.client.protocol.views.ViewDesign
23
+
24
+ class DesignDocAccess
25
+ def initialize(bucket)
26
+ @bucket = bucket
27
+ end
28
+
29
+ def [](name)
30
+ doc = @bucket.client.getDesignDocument(name)
31
+ Couchbase::DesignDoc.new(@bucket, doc)
32
+ rescue Java::ComCouchbaseClientProtocolViews::InvalidViewException
33
+ nil
34
+ end
35
+ end
36
+
37
+ # Fetch design docs stored in current bucket
38
+ #
39
+ # @since 1.2.0
40
+ #
41
+ # @return [Hash]
42
+ def design_docs
43
+ DesignDocAccess.new(self)
44
+ end
45
+
46
+ # Update or create design doc with supplied views
47
+ #
48
+ # @since 1.2.0
49
+ #
50
+ # @param [Hash, IO, String] data The source object containing JSON
51
+ # encoded design document. It must have +_id+ key set, this key
52
+ # should start with +_design/+.
53
+ #
54
+ # @return [true, false]
55
+ def save_design_doc(data)
56
+ attrs = case data
57
+ when String
58
+ MultiJson.load(data)
59
+ when IO
60
+ MultiJson.load(data.read)
61
+ when Hash
62
+ data
63
+ else
64
+ raise ArgumentError, "Document should be Hash, String or IO instance"
65
+ end
66
+
67
+ id = attrs.delete('_id').to_s.split('/')[1]
68
+
69
+ design_doc = DesignDocument.new(id)
70
+
71
+ attrs['views'].each_pair do |view, functions|
72
+ view_design = if functions['reduce']
73
+ ViewDesign.new(view.to_s.to_java_string, functions['map'].to_java_string, functions['reduce'].to_java_string)
74
+ else
75
+ ViewDesign.new(view.to_s.to_java_string, functions['map'].to_java_string)
76
+ end
77
+ design_doc.getViews.add(view_design)
78
+ end
79
+
80
+ client.createDesignDoc(design_doc)
81
+ end
82
+
83
+ # Delete design doc with given id and revision.
84
+ #
85
+ # @since 1.2.0
86
+ #
87
+ # @param [String] id Design document id. It might have '_design/'
88
+ # prefix.
89
+ #
90
+ # @param [String] rev Document revision. It uses latest revision if
91
+ # +rev+ parameter is nil.
92
+ #
93
+ # @return [true, false]
94
+ def delete_design_doc(id, rev = nil)
95
+ client.deleteDesignDoc(id)
96
+ end
97
+
98
+ end
99
+ end
@@ -1,3 +1,20 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
1
18
  module Couchbase::Operations
2
19
  module Get
3
20
 
@@ -129,17 +146,18 @@ module Couchbase::Operations
129
146
  # #=> {"foo" => val1, "bar" => val2}
130
147
  #
131
148
  def get(*args, &block)
132
- sync_block_error if !async? && block_given?
133
149
  key, options = expand_get_args(args)
134
150
 
135
151
  if async?
136
- if block_given?
137
- async_get(key, options, &Proc.new)
138
- else
139
- async_get(key, options)
140
- end
152
+ async_get(key, &block)
153
+ # if block_given?
154
+ # async_get(key, &Proc.new)
155
+ # else
156
+ # async_get(key)
157
+ # end
141
158
  else
142
- sync_get(key, options)
159
+ sync_block_error if block_given?
160
+ get_key(key, options)
143
161
  end
144
162
  end
145
163
 
@@ -147,15 +165,14 @@ module Couchbase::Operations
147
165
  get(key, options)
148
166
  end
149
167
 
150
- def get_multi(keys, options)
168
+ def get_bulk(keys, options)
151
169
  results = if options[:extended]
152
- get_multi_extended(keys)
170
+ get_bulk_extended(keys)
153
171
  else
154
- java_get_multi(keys)
172
+ client_get_bulk(keys)
155
173
  end
156
174
 
157
175
  not_found_error(results.size != keys.size, options)
158
- results = transcode_multi_results(results) unless options[:extended]
159
176
 
160
177
  if options[:assemble_hash] || options[:extended]
161
178
  results
@@ -164,27 +181,30 @@ module Couchbase::Operations
164
181
  end
165
182
  end
166
183
 
167
- private
168
-
169
- def sync_get(key, options)
184
+ def async_get(key)
170
185
  case key
171
186
  when String, Symbol
172
- get_single(key, options)
187
+ meta = { op: :get, key: key }
188
+ future = client.asyncGet(key)
173
189
  when Array
174
- get_multi(key, options)
190
+ meta = { op: :get }
191
+ future = client.asyncGetBulk(key)
175
192
  when Hash
176
- get_and_touch(key, options)
193
+ # async_get_and_touch(key, options, &block)
177
194
  end
195
+ register_future(future, meta, &Proc.new) if block_given?
178
196
  end
179
197
 
180
- def async_get(key, options, &block)
198
+ private
199
+
200
+ def get_key(key, options)
181
201
  case key
182
202
  when String, Symbol
183
- async_get_single(key, options, &block)
203
+ get_single(key, options)
184
204
  when Array
185
- async_get_multi(key, options, &block)
205
+ get_bulk(key, options)
186
206
  when Hash
187
- async_get_and_touch(key, options, &block)
207
+ get_and_touch(key, options)
188
208
  end
189
209
  end
190
210
 
@@ -196,60 +216,53 @@ module Couchbase::Operations
196
216
  end
197
217
 
198
218
  def get_single(key, options)
199
- if options[:extended]
200
- get_single_extended(key, options)
219
+ if options[:lock]
220
+ client_get_and_lock(key, options)
221
+ elsif options[:extended]
222
+ get_extended(key, options)
201
223
  else
202
- value = if options.key?(:lock)
203
- java_get_and_lock(key, options[:lock])
204
- elsif options.key?(:ttl)
205
- java_get_and_touch(key, options[:ttl])
224
+ value = if options.key?(:ttl)
225
+ client_get_and_touch(key, options[:ttl])
206
226
  else
207
- java_get(key)
227
+ client.get(key)
208
228
  end
209
229
 
210
230
  not_found_error(value.nil?, options)
211
- value.nil? ? nil : load(value)
231
+ value.nil? ? nil : value
212
232
  end
213
233
  end
214
234
 
215
- def get_single_extended(key, options = {})
216
- extended = java_get_extended(key)
235
+ def get_extended(key, options = {})
236
+ if options.key?(:lock)
237
+ client_get_and_lock(key, options[:lock])
238
+ end
239
+ extended = client_get_extended(key)
217
240
  not_found_error(extended.nil?, options)
218
241
  extended
219
242
  end
220
243
 
221
- def async_get_single(key, options, &block)
222
- future = client.asyncGet(key)
223
- register_future(future, { op: :get, key: key }, &block)
224
- end
225
-
226
- def async_get_multi(keys, options, &block)
227
- future = client.asyncGetBulk(keys)
228
- register_future(future, { op: :get }, &block)
229
- end
230
-
231
244
  def get_and_touch(key, options = {})
232
245
  if key.size > 1
233
- get_multi_and_touch(key, options)
246
+ get_bulk_and_touch(key, options)
234
247
  else
235
248
  key, ttl = key.first
236
- value = java_get_and_touch(key, ttl)
249
+ value = client_get_and_touch(key, ttl)
237
250
  not_found_error(value.nil?)
238
- { key => load(value) }
251
+ { key => value }
239
252
  end
240
253
  end
241
254
 
242
- def get_multi_and_touch(keys, options = {})
255
+ def get_bulk_and_touch(keys, options = {})
243
256
  options.merge!(assemble_hash: true)
244
- results = get_multi(keys.keys, options)
257
+ results = get_bulk(keys.keys, options)
245
258
  touch(keys)
246
259
  results.to_hash
247
260
  end
248
261
 
249
- def get_multi_extended(keys, options = {})
262
+ def get_bulk_extended(keys, options = {})
250
263
  {}.tap do |results|
251
264
  keys.each do |key|
252
- results[key] = get_single_extended(key, options)
265
+ results[key] = get_extended(key, options)
253
266
  end
254
267
  end
255
268
  end
@@ -258,41 +271,34 @@ module Couchbase::Operations
258
271
  keys.map { |key| results[key] }
259
272
  end
260
273
 
261
- def java_get(key)
262
- client.get(key)
263
- end
264
-
265
- def java_get_and_touch(key, ttl)
274
+ def client_get_and_touch(key, ttl)
266
275
  client.getAndTouch(key, ttl).getValue
267
276
  end
268
277
 
269
- def java_get_and_lock(key, lock)
270
- client.getAndLock(key, lock).value
278
+ def client_get_and_lock(key, options)
279
+ lock = options[:lock] == true ? 30 : options[:lock]
280
+ cas = client.getAndLock(key, lock)
281
+ if options[:extended]
282
+ [cas.getValue, nil, cas.getCas]
283
+ else
284
+ cas.getValue
285
+ end
271
286
  end
272
287
 
273
- def java_get_extended(key)
288
+ def client_get_extended(key)
274
289
  cas_value = client.gets(key)
275
290
 
276
291
  if cas_value.nil?
277
292
  nil
278
293
  else
279
- [load(cas_value.getValue), nil, cas_value.getCas]
294
+ [cas_value.getValue, nil, cas_value.getCas]
280
295
  end
281
296
  end
282
297
 
283
- def java_get_multi(keys)
298
+ def client_get_bulk(keys)
284
299
  client.getBulk(keys)
285
300
  rescue java.lang.ClassCastException
286
301
  raise TypeError.new
287
302
  end
288
-
289
- def transcode_multi_results(results)
290
- {}.tap do |new_results|
291
- results.each do |k, v|
292
- new_results[k] = load(v)
293
- end
294
- end
295
- end
296
-
297
303
  end
298
304
  end
@@ -1,3 +1,20 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
1
18
  module Couchbase::Operations
2
19
  module Stats
3
20
 
@@ -9,7 +26,17 @@ module Couchbase::Operations
9
26
  client.getStats(statname)
10
27
  end
11
28
 
12
- stats.first.last.to_hash
29
+ stats = stats.to_hash
30
+
31
+ {}.tap do |hash|
32
+ stats.each_pair do |node, values|
33
+ node_value = node.to_s
34
+ values.each_pair do |stat, value|
35
+ hash[stat] ||= {}
36
+ hash[stat][node_value] = value
37
+ end
38
+ end
39
+ end
13
40
  end
14
41
 
15
42
  end