couchbase-jruby-client 0.2.2-java → 1.0.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +103 -0
- data/.ruby-version +1 -1
- data/Rakefile +13 -2
- data/couchbase-jruby-client.gemspec +7 -6
- data/lib/couchbase/bucket.rb +11 -338
- data/lib/couchbase/cluster.rb +10 -88
- data/lib/couchbase/configuration.rb +39 -0
- data/lib/couchbase/design_doc.rb +18 -73
- data/lib/couchbase/document.rb +34 -0
- data/lib/couchbase/error.rb +0 -35
- data/lib/couchbase/operations.rb +60 -40
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view.rb +55 -345
- data/lib/couchbase.rb +37 -141
- data/lib/jars/couchbase-core-io-1.1.4.jar +0 -0
- data/lib/jars/couchbase-java-client-2.1.4.jar +0 -0
- data/lib/jars/rxjava-1.0.8.jar +0 -0
- data/lib/jars/rxjruby-0.0.1.jar +0 -0
- data/test/{test_cas.rb → helper.rb} +15 -10
- data/test/test_bucket.rb +14 -228
- data/test/test_cluster.rb +1 -29
- data/test/test_configuration.rb +51 -0
- data/test/test_couchbase.rb +28 -28
- data/test/test_design_doc.rb +29 -0
- data/test/test_document.rb +51 -0
- data/test/test_operations.rb +49 -0
- data/test/test_view.rb +62 -116
- metadata +43 -125
- data/lib/couchbase/async/callback.rb +0 -38
- data/lib/couchbase/async/queue.rb +0 -26
- data/lib/couchbase/async.rb +0 -32
- data/lib/couchbase/constants.rb +0 -29
- data/lib/couchbase/operations/arithmetic.rb +0 -290
- data/lib/couchbase/operations/delete.rb +0 -115
- data/lib/couchbase/operations/design_docs.rb +0 -99
- data/lib/couchbase/operations/fetch.rb +0 -33
- data/lib/couchbase/operations/get.rb +0 -303
- data/lib/couchbase/operations/stats.rb +0 -42
- data/lib/couchbase/operations/store.rb +0 -463
- data/lib/couchbase/operations/touch.rb +0 -140
- data/lib/couchbase/operations/unlock.rb +0 -209
- data/lib/couchbase/operations/utils.rb +0 -68
- data/lib/couchbase/query.rb +0 -76
- data/lib/couchbase/result.rb +0 -60
- data/lib/couchbase/transcoder.rb +0 -81
- data/lib/couchbase/utils.rb +0 -62
- data/lib/couchbase/view_row.rb +0 -227
- data/lib/jars/commons-codec-1.5.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2-javadoc.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2-sources.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2.jar +0 -0
- data/lib/jars/httpcore-4.3.1.jar +0 -0
- data/lib/jars/httpcore-nio-4.3.1.jar +0 -0
- data/lib/jars/jettison-1.1.jar +0 -0
- data/lib/jars/netty-3.5.5.Final.jar +0 -0
- data/lib/jars/spymemcached-2.10.5-javadoc.jar +0 -0
- data/lib/jars/spymemcached-2.10.5-sources.jar +0 -0
- data/lib/jars/spymemcached-2.10.5.jar +0 -0
- data/tasks/benchmark.rake +0 -6
- data/tasks/test.rake +0 -36
- data/tasks/util.rake +0 -21
- data/test/mock.rb +0 -85
- data/test/profile/.gitignore +0 -1
- data/test/profile/.jrubyrc +0 -722
- data/test/profile/Gemfile +0 -7
- data/test/profile/benchmark.rb +0 -177
- data/test/profile/profile.rb +0 -59
- data/test/setup.rb +0 -74
- data/test/test_arithmetic.rb +0 -155
- data/test/test_async.rb +0 -24
- data/test/test_couchbase_rails_cache_store.rb +0 -341
- data/test/test_delete.rb +0 -139
- data/test/test_design_docs.rb +0 -67
- data/test/test_errors.rb +0 -74
- data/test/test_fetch.rb +0 -71
- data/test/test_format.rb +0 -142
- data/test/test_get.rb +0 -363
- data/test/test_query.rb +0 -23
- data/test/test_result.rb +0 -15
- data/test/test_stats.rb +0 -44
- data/test/test_store.rb +0 -203
- data/test/test_touch.rb +0 -90
- data/test/test_unlock.rb +0 -89
- data/test/test_utils.rb +0 -67
- data/test/test_version.rb +0 -28
- data/test/test_view_row.rb +0 -74
@@ -1,209 +0,0 @@
|
|
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 Unlock
|
20
|
-
|
21
|
-
# Unlock key
|
22
|
-
#
|
23
|
-
# @since 1.2.0
|
24
|
-
#
|
25
|
-
# The +unlock+ method allow you to unlock key once locked by {Bucket#get}
|
26
|
-
# with +:lock+ option.
|
27
|
-
#
|
28
|
-
# @overload unlock(key, options = {})
|
29
|
-
# @param key [String, Symbol] Key used to reference the value.
|
30
|
-
# @param options [Hash] Options for operation.
|
31
|
-
# @option options [Fixnum] :cas The CAS value must match the current one
|
32
|
-
# from the storage.
|
33
|
-
# @option options [true, false] :quiet (self.quiet) If set to +true+, the
|
34
|
-
# operation won't raise error for missing key, it will return +nil+.
|
35
|
-
#
|
36
|
-
# @return [true, false] +true+ if the operation was successful and +false+
|
37
|
-
# otherwise.
|
38
|
-
#
|
39
|
-
# @raise [Couchbase::Error::Connect] if connection closed (see {Bucket#reconnect})
|
40
|
-
#
|
41
|
-
# @raise [ArgumentError] when passing the block in synchronous mode
|
42
|
-
#
|
43
|
-
# @raise [Couchbase::Error::NotFound] if key(s) not found in the storage
|
44
|
-
#
|
45
|
-
# @raise [Couchbase::Error::TemporaryFail] if either the key wasn't
|
46
|
-
# locked or given CAS value doesn't match to actual in the storage
|
47
|
-
#
|
48
|
-
# @example Unlock the single key
|
49
|
-
# val, _, cas = c.get("foo", :lock => true, :extended => true)
|
50
|
-
# c.unlock("foo", :cas => cas)
|
51
|
-
#
|
52
|
-
# @overload unlock(keys)
|
53
|
-
# @param keys [Hash] The Hash where keys represent the keys in the
|
54
|
-
# database, values -- the CAS for corresponding key.
|
55
|
-
#
|
56
|
-
# @yieldparam ret [Result] the result of operation for each key in
|
57
|
-
# asynchronous mode (valid attributes: +error+, +operation+, +key+).
|
58
|
-
#
|
59
|
-
# @return [Hash] Mapping keys to result of unlock operation (+true+ if the
|
60
|
-
# operation was successful and +false+ otherwise)
|
61
|
-
#
|
62
|
-
# @example Unlock several keys
|
63
|
-
# c.unlock("foo" => cas1, :bar => cas2) #=> {"foo" => true, "bar" => true}
|
64
|
-
#
|
65
|
-
# @example Unlock several values in async mode
|
66
|
-
# c.run do
|
67
|
-
# c.unlock("foo" => 10, :bar => 20) do |ret|
|
68
|
-
# ret.operation #=> :unlock
|
69
|
-
# ret.success? #=> true
|
70
|
-
# ret.key #=> "foo" and "bar" in separate calls
|
71
|
-
# end
|
72
|
-
# end
|
73
|
-
#
|
74
|
-
|
75
|
-
def unlock(key, options = {})
|
76
|
-
cas = options.respond_to?(:to_hash) ? options[:cas] : options
|
77
|
-
if client.unlock(key.to_s, cas)
|
78
|
-
true
|
79
|
-
else
|
80
|
-
raise Couchbase::Error::TemporaryFail.new
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def async_unlock(key, options = {})
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
__END__
|
92
|
-
|
93
|
-
/*
|
94
|
-
* Unlock key
|
95
|
-
*
|
96
|
-
* @since 1.2.0
|
97
|
-
*
|
98
|
-
* The +unlock+ method allow you to unlock key once locked by {Bucket#get}
|
99
|
-
* with +:lock+ option.
|
100
|
-
*
|
101
|
-
* @overload unlock(key, options = {})
|
102
|
-
* @param key [String, Symbol] Key used to reference the value.
|
103
|
-
* @param options [Hash] Options for operation.
|
104
|
-
* @option options [Fixnum] :cas The CAS value must match the current one
|
105
|
-
* from the storage.
|
106
|
-
* @option options [true, false] :quiet (self.quiet) If set to +true+, the
|
107
|
-
* operation won't raise error for missing key, it will return +nil+.
|
108
|
-
*
|
109
|
-
* @return [true, false] +true+ if the operation was successful and +false+
|
110
|
-
* otherwise.
|
111
|
-
*
|
112
|
-
* @raise [Couchbase::Error::Connect] if connection closed (see {Bucket#reconnect})
|
113
|
-
*
|
114
|
-
* @raise [ArgumentError] when passing the block in synchronous mode
|
115
|
-
*
|
116
|
-
* @raise [Couchbase::Error::NotFound] if key(s) not found in the storage
|
117
|
-
*
|
118
|
-
* @raise [Couchbase::Error::TemporaryFail] if either the key wasn't
|
119
|
-
* locked or given CAS value doesn't match to actual in the storage
|
120
|
-
*
|
121
|
-
* @example Unlock the single key
|
122
|
-
* val, _, cas = c.get("foo", :lock => true, :extended => true)
|
123
|
-
* c.unlock("foo", :cas => cas)
|
124
|
-
*
|
125
|
-
* @overload unlock(keys)
|
126
|
-
* @param keys [Hash] The Hash where keys represent the keys in the
|
127
|
-
* database, values -- the CAS for corresponding key.
|
128
|
-
*
|
129
|
-
* @yieldparam ret [Result] the result of operation for each key in
|
130
|
-
* asynchronous mode (valid attributes: +error+, +operation+, +key+).
|
131
|
-
*
|
132
|
-
* @return [Hash] Mapping keys to result of unlock operation (+true+ if the
|
133
|
-
* operation was successful and +false+ otherwise)
|
134
|
-
*
|
135
|
-
* @example Unlock several keys
|
136
|
-
* c.unlock("foo" => cas1, :bar => cas2) #=> {"foo" => true, "bar" => true}
|
137
|
-
*
|
138
|
-
* @example Unlock several values in async mode
|
139
|
-
* c.run do
|
140
|
-
* c.unlock("foo" => 10, :bar => 20) do |ret|
|
141
|
-
* ret.operation #=> :unlock
|
142
|
-
* ret.success? #=> true
|
143
|
-
* ret.key #=> "foo" and "bar" in separate calls
|
144
|
-
* end
|
145
|
-
* end
|
146
|
-
*
|
147
|
-
*/
|
148
|
-
VALUE
|
149
|
-
cb_bucket_unlock(int argc, VALUE *argv, VALUE self)
|
150
|
-
{
|
151
|
-
struct cb_bucket_st *bucket = DATA_PTR(self);
|
152
|
-
struct cb_context_st *ctx;
|
153
|
-
VALUE rv, proc, exc;
|
154
|
-
lcb_error_t err;
|
155
|
-
struct cb_params_st params;
|
156
|
-
|
157
|
-
if (!cb_bucket_connected_bang(bucket, cb_sym_unlock)) {
|
158
|
-
return Qnil;
|
159
|
-
}
|
160
|
-
|
161
|
-
memset(¶ms, 0, sizeof(struct cb_params_st));
|
162
|
-
rb_scan_args(argc, argv, "0*&", ¶ms.args, &proc);
|
163
|
-
if (!bucket->async && proc != Qnil) {
|
164
|
-
rb_raise(rb_eArgError, "synchronous mode doesn't support callbacks");
|
165
|
-
}
|
166
|
-
rb_funcall(params.args, cb_id_flatten_bang, 0);
|
167
|
-
params.type = cb_cmd_unlock;
|
168
|
-
params.bucket = bucket;
|
169
|
-
cb_params_build(¶ms);
|
170
|
-
ctx = cb_context_alloc_common(bucket, proc, params.cmd.unlock.num);
|
171
|
-
ctx->quiet = params.cmd.unlock.quiet;
|
172
|
-
err = lcb_unlock(bucket->handle, (const void *)ctx,
|
173
|
-
params.cmd.unlock.num, params.cmd.unlock.ptr);
|
174
|
-
cb_params_destroy(¶ms);
|
175
|
-
exc = cb_check_error(err, "failed to schedule unlock request", Qnil);
|
176
|
-
if (exc != Qnil) {
|
177
|
-
cb_context_free(ctx);
|
178
|
-
rb_exc_raise(exc);
|
179
|
-
}
|
180
|
-
bucket->nbytes += params.npayload;
|
181
|
-
if (bucket->async) {
|
182
|
-
cb_maybe_do_loop(bucket);
|
183
|
-
return Qnil;
|
184
|
-
} else {
|
185
|
-
if (ctx->nqueries > 0) {
|
186
|
-
/* we have some operations pending */
|
187
|
-
lcb_wait(bucket->handle);
|
188
|
-
}
|
189
|
-
exc = ctx->exception;
|
190
|
-
rv = ctx->rv;
|
191
|
-
cb_context_free(ctx);
|
192
|
-
if (exc != Qnil) {
|
193
|
-
rb_exc_raise(exc);
|
194
|
-
}
|
195
|
-
exc = bucket->exception;
|
196
|
-
if (exc != Qnil) {
|
197
|
-
bucket->exception = Qnil;
|
198
|
-
rb_exc_raise(exc);
|
199
|
-
}
|
200
|
-
if (params.cmd.unlock.num > 1) {
|
201
|
-
return rv; /* return as a hash {key => true, ...} */
|
202
|
-
} else {
|
203
|
-
VALUE vv = Qnil;
|
204
|
-
rb_hash_foreach(rv, cb_first_value_i, (VALUE)&vv);
|
205
|
-
return vv;
|
206
|
-
}
|
207
|
-
}
|
208
|
-
}
|
209
|
-
|
@@ -1,68 +0,0 @@
|
|
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 Utils
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def validate_key(key)
|
24
|
-
raise ArgumentError, "key cannot be blank" if !key || key.length == 0
|
25
|
-
key = key_with_prefix(key)
|
26
|
-
|
27
|
-
if key.length > 250
|
28
|
-
max_length = key_prefix ? 212 - key_prefix.size : 212
|
29
|
-
key = "#{key[0, max_length]}:md5:#{Digest::MD5.hexdigest(key)}"
|
30
|
-
end
|
31
|
-
return key
|
32
|
-
end
|
33
|
-
|
34
|
-
def key_with_prefix(key)
|
35
|
-
(prefix = key_prefix) ? "#{prefix}:#{key}" : key
|
36
|
-
end
|
37
|
-
|
38
|
-
def key_without_prefix(key)
|
39
|
-
(prefix = key_prefix) ? key.sub(%r(\A#{prefix}:), '') : key
|
40
|
-
end
|
41
|
-
|
42
|
-
def extract_options_hash(args)
|
43
|
-
if args.size > 1 && args.last.respond_to?(:to_hash)
|
44
|
-
args.pop
|
45
|
-
else
|
46
|
-
{}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def not_found_error(error, options = {})
|
51
|
-
if error
|
52
|
-
if options.key?(:quiet)
|
53
|
-
raise Couchbase::Error::NotFound.new if !options[:quiet]
|
54
|
-
elsif !quiet?
|
55
|
-
raise Couchbase::Error::NotFound.new
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def future_cas(future)
|
61
|
-
future.get && future.cas
|
62
|
-
rescue Java::JavaLang::UnsupportedOperationException
|
63
|
-
# TODO: don't return fake cas
|
64
|
-
1
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
data/lib/couchbase/query.rb
DELETED
@@ -1,76 +0,0 @@
|
|
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
|
-
|
19
|
-
module Couchbase
|
20
|
-
class Query
|
21
|
-
|
22
|
-
java_import com.couchbase.client.protocol.views.Stale
|
23
|
-
|
24
|
-
METHOD_MAPPING = {
|
25
|
-
:include_docs => :setIncludeDocs,
|
26
|
-
:descending => :setDescending,
|
27
|
-
:key => :setKey,
|
28
|
-
:keys => :setKeys,
|
29
|
-
:start_key => :setRangeStart,
|
30
|
-
:startkey => :setRangeStart,
|
31
|
-
:startkey_docid => :setStartkeyDocID,
|
32
|
-
:endkey => :setRangeEnd,
|
33
|
-
:endkey_docid => :setEndkeyDocID,
|
34
|
-
:inclusive_end => :setInclusiveEnd,
|
35
|
-
:limit => :setLimit,
|
36
|
-
:skip => :setSkip,
|
37
|
-
:reduce => :setReduce,
|
38
|
-
:group => :setGroup,
|
39
|
-
:group_level => :setGroupLevel,
|
40
|
-
:connection_timeout => nil
|
41
|
-
}.freeze
|
42
|
-
|
43
|
-
def initialize(params)
|
44
|
-
@params = params
|
45
|
-
end
|
46
|
-
|
47
|
-
def generate
|
48
|
-
query = Java::ComCouchbaseClientProtocolViews::Query.new
|
49
|
-
|
50
|
-
stale = @params.delete(:stale)
|
51
|
-
if !stale.nil?
|
52
|
-
case stale
|
53
|
-
when :after_update
|
54
|
-
query.setStale(Stale::UPDATE_AFTER)
|
55
|
-
when :ok
|
56
|
-
query.setStale(Stale::OK)
|
57
|
-
when false
|
58
|
-
query.setStale(Stale::FALSE)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
@params.each_pair do |meth, val|
|
63
|
-
if METHOD_MAPPING.key?(meth)
|
64
|
-
if java_meth = METHOD_MAPPING[meth]
|
65
|
-
query.send(java_meth, val)
|
66
|
-
end
|
67
|
-
else
|
68
|
-
fail ArgumentError, "Query does not support #{meth}"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
query
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
data/lib/couchbase/result.rb
DELETED
@@ -1,60 +0,0 @@
|
|
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
|
19
|
-
class Result
|
20
|
-
|
21
|
-
attr_accessor :error
|
22
|
-
|
23
|
-
def initialize(attrs = {})
|
24
|
-
@bucket = attrs[:bucket]
|
25
|
-
@key = attrs[:key]
|
26
|
-
@operation = attrs[:op]
|
27
|
-
@future = attrs[:future]
|
28
|
-
end
|
29
|
-
|
30
|
-
def operation
|
31
|
-
@operation
|
32
|
-
end
|
33
|
-
|
34
|
-
def success?
|
35
|
-
@future.get
|
36
|
-
end
|
37
|
-
|
38
|
-
def error
|
39
|
-
@error
|
40
|
-
end
|
41
|
-
|
42
|
-
def key
|
43
|
-
@key || @future.getKey
|
44
|
-
end
|
45
|
-
|
46
|
-
def value
|
47
|
-
@future.get
|
48
|
-
rescue MultiJson::LoadError
|
49
|
-
nil
|
50
|
-
end
|
51
|
-
|
52
|
-
def cas
|
53
|
-
@future.getCas if @future.respond_to?(:getCas)
|
54
|
-
end
|
55
|
-
|
56
|
-
def node
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/couchbase/transcoder.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# Author:: Couchbase <info@couchbase.com>
|
2
|
-
# Copyright:: 2013 Couchbase, Inc.
|
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
|
-
require 'multi_json'
|
19
|
-
|
20
|
-
module Couchbase
|
21
|
-
|
22
|
-
module Transcoder
|
23
|
-
|
24
|
-
class Base < Java::NetSpyMemcachedTranscoders::SerializingTranscoder
|
25
|
-
end
|
26
|
-
|
27
|
-
class Document < Base
|
28
|
-
|
29
|
-
def decode(d)
|
30
|
-
decoded = super
|
31
|
-
data = if decoded.respond_to?(:to_str)
|
32
|
-
decoded
|
33
|
-
else
|
34
|
-
decoded.getData.to_s
|
35
|
-
end
|
36
|
-
|
37
|
-
MultiJson.load(data)
|
38
|
-
rescue MultiJson::LoadError
|
39
|
-
begin
|
40
|
-
::Marshal.load(data)
|
41
|
-
rescue TypeError
|
42
|
-
data
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def encode(o)
|
47
|
-
super MultiJson.dump(o)
|
48
|
-
rescue ArgumentError => e
|
49
|
-
ex = Couchbase::Error::ValueFormat.new
|
50
|
-
ex.inner_exception = e
|
51
|
-
fail ex
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Marshal < Base
|
56
|
-
|
57
|
-
def decode(d)
|
58
|
-
::Marshal.load super.getData.to_s
|
59
|
-
end
|
60
|
-
|
61
|
-
def encode(o)
|
62
|
-
super ::Marshal.dump(o)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class Plain < Base
|
67
|
-
|
68
|
-
def decode(d)
|
69
|
-
super
|
70
|
-
end
|
71
|
-
|
72
|
-
def encode(o)
|
73
|
-
super(o.to_str)
|
74
|
-
rescue NoMethodError
|
75
|
-
raise Couchbase::Error::ValueFormat
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
data/lib/couchbase/utils.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# Author:: Couchbase <info@couchbase.com>
|
2
|
-
# Copyright:: 2011-2012 Couchbase, Inc.
|
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
|
19
|
-
|
20
|
-
class Utils
|
21
|
-
|
22
|
-
def self.encode_params(params)
|
23
|
-
params.map do |k, v|
|
24
|
-
next if !v && k.to_s == "group"
|
25
|
-
if %w{key keys startkey endkey start_key end_key}.include?(k.to_s)
|
26
|
-
v = MultiJson.dump(v)
|
27
|
-
end
|
28
|
-
if v.class == Array
|
29
|
-
build_query(v.map { |x| [k, x] })
|
30
|
-
else
|
31
|
-
"#{escape(k)}=#{escape(v)}"
|
32
|
-
end
|
33
|
-
end.compact.join("&")
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.build_query(uri, params = nil)
|
37
|
-
uri = uri.dup
|
38
|
-
return uri if params.nil? || params.empty?
|
39
|
-
uri << "?" << encode_params(params)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.escape(s)
|
43
|
-
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/nu) {
|
44
|
-
'%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
|
45
|
-
}.tr(' ', '+')
|
46
|
-
end
|
47
|
-
|
48
|
-
# Return the bytesize of String; uses String#size under Ruby 1.8 and
|
49
|
-
# String#bytesize under 1.9.
|
50
|
-
if ''.respond_to?(:bytesize)
|
51
|
-
def self.bytesize(string)
|
52
|
-
string.bytesize
|
53
|
-
end
|
54
|
-
else
|
55
|
-
def self.bytesize(string)
|
56
|
-
string.size
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|