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.
- 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
data/lib/couchbase.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
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
|
+
#
|
1
17
|
|
2
18
|
unless RUBY_PLATFORM =~ /java/
|
3
19
|
error "This gem is only compatible with a java-based ruby environment like JRuby."
|
@@ -14,7 +30,7 @@ require 'jars/spymemcached-2.10.0.jar'
|
|
14
30
|
require 'jars/httpcore-nio-4.1.1.jar'
|
15
31
|
require 'couchbase/version'
|
16
32
|
require 'uri'
|
17
|
-
require '
|
33
|
+
require 'thread_safe'
|
18
34
|
require 'couchbase/transcoder'
|
19
35
|
require 'couchbase/async'
|
20
36
|
require 'couchbase/operations'
|
@@ -26,10 +42,13 @@ require 'couchbase/view_row'
|
|
26
42
|
require 'couchbase/view'
|
27
43
|
require 'couchbase/result'
|
28
44
|
require 'couchbase/cluster'
|
45
|
+
require 'couchbase/design_doc'
|
46
|
+
require 'couchbase/view'
|
47
|
+
require 'couchbase/query'
|
29
48
|
|
30
49
|
include Java
|
31
50
|
|
32
|
-
|
51
|
+
java_import Java::com.couchbase.client.CouchbaseClient
|
33
52
|
|
34
53
|
at_exit do
|
35
54
|
Couchbase.disconnect
|
@@ -38,7 +57,7 @@ end
|
|
38
57
|
# Couchbase jruby client
|
39
58
|
module Couchbase
|
40
59
|
|
41
|
-
@@
|
60
|
+
@@buckets = ThreadSafe::Cache.new
|
42
61
|
|
43
62
|
class << self
|
44
63
|
|
@@ -65,9 +84,7 @@ module Couchbase
|
|
65
84
|
#
|
66
85
|
# @return [Bucket] connection instance
|
67
86
|
def connect(*options)
|
68
|
-
|
69
|
-
@@bucket.update { |bucket| bucket ||= Bucket.new(*(options.flatten)) }
|
70
|
-
@@bucket.value
|
87
|
+
Bucket.new(*(options.flatten))
|
71
88
|
end
|
72
89
|
alias :new :connect
|
73
90
|
|
@@ -80,67 +97,16 @@ module Couchbase
|
|
80
97
|
# Couchbase.bucket.name #=> "blog"
|
81
98
|
#
|
82
99
|
# @return [Hash, String]
|
83
|
-
|
84
|
-
|
85
|
-
# The connection instance for current thread
|
86
|
-
#
|
87
|
-
# @since 1.1.0
|
88
|
-
#
|
89
|
-
# @see Couchbase.connection_options
|
90
|
-
#
|
91
|
-
# @example
|
92
|
-
# Couchbase.bucket.set("foo", "bar")
|
93
|
-
#
|
94
|
-
# @return [Bucket]
|
95
|
-
def bucket
|
96
|
-
if !connected?
|
97
|
-
connect(connection_options)
|
98
|
-
end
|
99
|
-
@@bucket.value
|
100
|
-
end
|
101
|
-
|
102
|
-
# Set a connection instance for current thread
|
103
|
-
#
|
104
|
-
# @since 1.1.0
|
105
|
-
#
|
106
|
-
# @return [Bucket]
|
107
|
-
def bucket=(connection)
|
108
|
-
@@bucket.update { |bucket| bucket = connection }
|
109
|
-
end
|
110
|
-
|
111
|
-
def connected?
|
112
|
-
!!@@bucket.value
|
113
|
-
end
|
100
|
+
attr_reader :connection_options
|
114
101
|
|
115
|
-
def
|
116
|
-
|
117
|
-
@@bucket = Atomic.new(nil)
|
102
|
+
def connection_options=(options)
|
103
|
+
@connection_options = normalize_connection_options(options)
|
118
104
|
end
|
119
|
-
end
|
120
|
-
end
|
121
105
|
|
122
|
-
|
123
|
-
|
124
|
-
def self.connect(*options)
|
125
|
-
disconnect
|
126
|
-
Bucket.new(*(options.flatten))
|
106
|
+
def normalize_connection_options(options)
|
107
|
+
Hash[ options.map { |k, v| [k.to_sym, v] } ]
|
127
108
|
end
|
128
109
|
|
129
|
-
def self.new(*options)
|
130
|
-
connect(options)
|
131
|
-
end
|
132
|
-
|
133
|
-
# Default connection options
|
134
|
-
#
|
135
|
-
# @since 1.1.0
|
136
|
-
#
|
137
|
-
# @example Using {Couchbase#connection_options} to change the bucket
|
138
|
-
# Couchbase.connection_options = {:bucket => 'blog'}
|
139
|
-
# Couchbase.bucket.name #=> "blog"
|
140
|
-
#
|
141
|
-
# @return [Hash, String]
|
142
|
-
attr_accessor :connection_options
|
143
|
-
|
144
110
|
# The connection instance for current thread
|
145
111
|
#
|
146
112
|
# @since 1.1.0
|
@@ -150,9 +116,42 @@ __END__
|
|
150
116
|
# @example
|
151
117
|
# Couchbase.bucket.set("foo", "bar")
|
152
118
|
#
|
119
|
+
# @example Set connection options using Hash
|
120
|
+
# Couchbase.connection_options = {:node_list => ["example.com:8091"]}
|
121
|
+
# Couchbase.bucket("slot1").set("foo", "bar")
|
122
|
+
# Couchbase.bucket("slot1").bucket #=> "default"
|
123
|
+
# Couchbase.connection_options[:bucket] = "test"
|
124
|
+
# Couchbase.bucket("slot2").bucket #=> "test"
|
125
|
+
#
|
126
|
+
# @example Set connection options using URI
|
127
|
+
# Couchbase.connection_options = "http://example.com:8091/pools"
|
128
|
+
# Couchbase.bucket("slot1").set("foo", "bar")
|
129
|
+
# Couchbase.bucket("slot1").bucket #=> "default"
|
130
|
+
# Couchbase.connection_options = "http://example.com:8091/pools/buckets/test"
|
131
|
+
# Couchbase.bucket("slot2").bucket #=> "test"
|
132
|
+
#
|
133
|
+
# @example Use named slots to keep a connection
|
134
|
+
# Couchbase.connection_options = {
|
135
|
+
# :node_list => ["example.com", "example.org"],
|
136
|
+
# :bucket => "users"
|
137
|
+
# }
|
138
|
+
# Couchbase.bucket("users").set("john", {"balance" => 0})
|
139
|
+
# Couchbase.connection_options[:bucket] = "orders"
|
140
|
+
# Couchbase.bucket("other").set("john:1", {"products" => [42, 66]})
|
141
|
+
#
|
153
142
|
# @return [Bucket]
|
154
|
-
def
|
155
|
-
|
143
|
+
def bucket(name = nil)
|
144
|
+
name ||= case @connection_options
|
145
|
+
when Hash
|
146
|
+
@connection_options[:bucket]
|
147
|
+
when String
|
148
|
+
path = URI.parse(@connection_options).path
|
149
|
+
path[%r(^(/pools/([A-Za-z0-9_.-]+)(/buckets/([A-Za-z0-9_.-]+))?)?), 3] || "default"
|
150
|
+
else
|
151
|
+
'default'
|
152
|
+
end
|
153
|
+
|
154
|
+
@@buckets[name] ||= connect(connection_options)
|
156
155
|
end
|
157
156
|
|
158
157
|
# Set a connection instance for current thread
|
@@ -160,18 +159,21 @@ __END__
|
|
160
159
|
# @since 1.1.0
|
161
160
|
#
|
162
161
|
# @return [Bucket]
|
163
|
-
def
|
164
|
-
@bucket
|
162
|
+
def bucket=(connection)
|
163
|
+
name = @connection_options && @connection_options[:bucket] || "default"
|
164
|
+
@@buckets[name] = connection
|
165
165
|
end
|
166
166
|
|
167
|
-
def
|
168
|
-
|
167
|
+
def connected?
|
168
|
+
!!@@buckets.empty?
|
169
169
|
end
|
170
170
|
|
171
|
-
def
|
172
|
-
|
173
|
-
|
171
|
+
def disconnect
|
172
|
+
@@buckets.each_key do |name|
|
173
|
+
bucket = @@buckets.delete(name)
|
174
|
+
bucket.disconnect if connected?
|
175
|
+
end
|
174
176
|
end
|
175
|
-
|
177
|
+
end
|
176
178
|
end
|
177
179
|
|