couchbase-jruby-client 0.1.0-java → 0.1.5-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.jrubyrc +722 -0
- data/.ruby-version +1 -1
- data/README.md +12 -90
- data/couchbase-jruby-client.gemspec +6 -6
- data/lib/couchbase/async.rb +18 -0
- data/lib/couchbase/bucket.rb +90 -180
- data/lib/couchbase/constants.rb +17 -0
- data/lib/couchbase/design_doc.rb +83 -0
- data/lib/couchbase/error.rb +31 -0
- data/lib/couchbase/operations/arithmetic.rb +17 -0
- data/lib/couchbase/operations/delete.rb +17 -0
- data/lib/couchbase/operations/design_docs.rb +99 -0
- data/lib/couchbase/operations/get.rb +73 -67
- data/lib/couchbase/operations/stats.rb +28 -1
- data/lib/couchbase/operations/store.rb +114 -97
- data/lib/couchbase/operations/touch.rb +49 -19
- data/lib/couchbase/operations/unlock.rb +209 -0
- data/lib/couchbase/operations/utils.rb +22 -10
- data/lib/couchbase/operations.rb +21 -0
- data/lib/couchbase/query.rb +92 -0
- data/lib/couchbase/result.rb +18 -1
- data/lib/couchbase/transcoder.rb +36 -42
- data/lib/couchbase/version.rb +18 -1
- data/lib/couchbase/view.rb +30 -172
- data/lib/couchbase/view_row.rb +38 -98
- data/lib/couchbase.rb +74 -72
- data/test/profile/.jrubyrc +722 -0
- data/test/profile/Gemfile +5 -5
- data/test/profile/benchmark.rb +106 -124
- data/test/profile/profile.rb +59 -0
- data/test/setup.rb +10 -145
- data/test/test_arithmetic.rb +54 -77
- data/test/test_async.rb +74 -102
- data/test/test_bucket.rb +74 -60
- data/test/test_cas.rb +10 -23
- data/test/test_couchbase.rb +11 -3
- data/test/test_delete.rb +41 -43
- data/test/test_design_docs.rb +62 -0
- data/test/test_errors.rb +9 -18
- data/test/test_format.rb +21 -31
- data/test/test_get.rb +107 -151
- data/test/test_query.rb +23 -0
- data/test/test_stats.rb +9 -24
- data/test/test_store.rb +52 -65
- data/test/test_timer.rb +4 -12
- data/test/test_touch.rb +26 -33
- data/test/test_unlock.rb +47 -78
- data/test/test_utils.rb +2 -11
- data/test/test_version.rb +5 -14
- data/test/test_view.rb +87 -0
- metadata +27 -14
- data/lib/couchbase/jruby/couchbase_client.rb +0 -22
- 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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
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
|
168
|
+
def get_bulk(keys, options)
|
151
169
|
results = if options[:extended]
|
152
|
-
|
170
|
+
get_bulk_extended(keys)
|
153
171
|
else
|
154
|
-
|
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
|
-
|
168
|
-
|
169
|
-
def sync_get(key, options)
|
184
|
+
def async_get(key)
|
170
185
|
case key
|
171
186
|
when String, Symbol
|
172
|
-
|
187
|
+
meta = { op: :get, key: key }
|
188
|
+
future = client.asyncGet(key)
|
173
189
|
when Array
|
174
|
-
|
190
|
+
meta = { op: :get }
|
191
|
+
future = client.asyncGetBulk(key)
|
175
192
|
when Hash
|
176
|
-
|
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
|
-
|
198
|
+
private
|
199
|
+
|
200
|
+
def get_key(key, options)
|
181
201
|
case key
|
182
202
|
when String, Symbol
|
183
|
-
|
203
|
+
get_single(key, options)
|
184
204
|
when Array
|
185
|
-
|
205
|
+
get_bulk(key, options)
|
186
206
|
when Hash
|
187
|
-
|
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[:
|
200
|
-
|
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?(:
|
203
|
-
|
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
|
-
|
227
|
+
client.get(key)
|
208
228
|
end
|
209
229
|
|
210
230
|
not_found_error(value.nil?, options)
|
211
|
-
value.nil? ? nil :
|
231
|
+
value.nil? ? nil : value
|
212
232
|
end
|
213
233
|
end
|
214
234
|
|
215
|
-
def
|
216
|
-
|
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
|
-
|
246
|
+
get_bulk_and_touch(key, options)
|
234
247
|
else
|
235
248
|
key, ttl = key.first
|
236
|
-
value =
|
249
|
+
value = client_get_and_touch(key, ttl)
|
237
250
|
not_found_error(value.nil?)
|
238
|
-
{ key =>
|
251
|
+
{ key => value }
|
239
252
|
end
|
240
253
|
end
|
241
254
|
|
242
|
-
def
|
255
|
+
def get_bulk_and_touch(keys, options = {})
|
243
256
|
options.merge!(assemble_hash: true)
|
244
|
-
results =
|
257
|
+
results = get_bulk(keys.keys, options)
|
245
258
|
touch(keys)
|
246
259
|
results.to_hash
|
247
260
|
end
|
248
261
|
|
249
|
-
def
|
262
|
+
def get_bulk_extended(keys, options = {})
|
250
263
|
{}.tap do |results|
|
251
264
|
keys.each do |key|
|
252
|
-
results[key] =
|
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
|
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
|
270
|
-
|
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
|
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
|
-
[
|
294
|
+
[cas_value.getValue, nil, cas_value.getCas]
|
280
295
|
end
|
281
296
|
end
|
282
297
|
|
283
|
-
def
|
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.
|
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
|