couchbase-jruby-client 0.2.2-java → 1.0.4-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/.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
data/lib/couchbase/design_doc.rb
CHANGED
@@ -1,83 +1,28 @@
|
|
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
1
|
module Couchbase
|
19
|
-
class DesignDoc < ViewRow
|
20
|
-
|
21
|
-
# It isn't allowed to change design document ID after
|
22
|
-
# initialization
|
23
|
-
undef id=
|
24
2
|
|
25
|
-
|
26
|
-
@all_views = {}
|
27
|
-
@bucket = bucket
|
28
|
-
@name = doc.name
|
29
|
-
@views = doc.views
|
30
|
-
@spatial = doc.spatial_views
|
31
|
-
@doc = {}
|
32
|
-
@views.each { |view| @all_views[view.name] = "#{@name}/_view/#{view.name}" }
|
33
|
-
@spatial.each { |view| @all_views[view.name] = "#{@name}/_spatial/#{view.name}" }
|
34
|
-
end
|
3
|
+
class DesignDocFormatError < Error::Base; end
|
35
4
|
|
36
|
-
|
37
|
-
if path = @all_views[meth.to_s]
|
38
|
-
View.new(@bucket, path, *args)
|
39
|
-
else
|
40
|
-
super
|
41
|
-
end
|
42
|
-
end
|
5
|
+
class DesignDoc
|
43
6
|
|
44
|
-
|
45
|
-
|
46
|
-
end
|
7
|
+
java_import com.couchbase.client.java.view.DesignDocument
|
8
|
+
java_import com.couchbase.client.java.view.DefaultView
|
47
9
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# @since 1.2.1
|
58
|
-
#
|
59
|
-
# @return [Array<View>]
|
60
|
-
attr_accessor :spatial
|
61
|
-
|
62
|
-
# Check if the document has views defines
|
63
|
-
#
|
64
|
-
# @since 1.2.1
|
65
|
-
#
|
66
|
-
# @see DesignDoc#views
|
67
|
-
#
|
68
|
-
# @return [true, false] +true+ if the document have views
|
69
|
-
def has_views?
|
70
|
-
!@views.empty?
|
71
|
-
end
|
72
|
-
|
73
|
-
def inspect
|
74
|
-
desc = "#<#{self.class.name}:#{self.object_id}"
|
75
|
-
[:@id, :@views, :@spatial].each do |iv|
|
76
|
-
desc << " #{iv}=#{instance_variable_get(iv).inspect}"
|
10
|
+
def initialize(name, design_doc)
|
11
|
+
@name = name
|
12
|
+
@views = java.util.ArrayList.new
|
13
|
+
design_doc.each_pair do |view_name, view|
|
14
|
+
if view.key?(:reduce)
|
15
|
+
@views.add DefaultView.create(view_name.to_s, view[:map], view[:reduce])
|
16
|
+
else
|
17
|
+
@views.add DefaultView.create(view_name.to_s, view[:map])
|
18
|
+
end
|
77
19
|
end
|
78
|
-
|
79
|
-
|
20
|
+
rescue => e
|
21
|
+
raise DesignDocFormatError, e
|
80
22
|
end
|
81
23
|
|
24
|
+
def create
|
25
|
+
DesignDocument.create(@name, @views)
|
26
|
+
end
|
82
27
|
end
|
83
28
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Couchbase
|
4
|
+
class Document
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_reader :id, :cas, :ttl, :content
|
8
|
+
|
9
|
+
def initialize(java_doc)
|
10
|
+
@id = java_doc.id
|
11
|
+
@cas = java_doc.cas
|
12
|
+
@ttl = java_doc.expiry
|
13
|
+
@content = java_doc.content
|
14
|
+
@data = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
@content
|
19
|
+
end
|
20
|
+
|
21
|
+
def data
|
22
|
+
@data ||= begin
|
23
|
+
MultiJson.load(@content)
|
24
|
+
rescue MultiJson::ParseError
|
25
|
+
# TODO: figure out what to do here...
|
26
|
+
end
|
27
|
+
end
|
28
|
+
alias_method :to_a, :data
|
29
|
+
alias_method :to_h, :data
|
30
|
+
alias_method :to_hash, :data
|
31
|
+
|
32
|
+
def_delegators :data, :[], :each, :each_pair, :keys, :values, :key?
|
33
|
+
end
|
34
|
+
end
|
data/lib/couchbase/error.rb
CHANGED
@@ -18,42 +18,7 @@
|
|
18
18
|
module Couchbase
|
19
19
|
module Error
|
20
20
|
class Base < Exception
|
21
|
-
attr_accessor :cas, :error, :inner_exception, :key, :operation, :status
|
22
21
|
|
23
|
-
def to_s
|
24
|
-
if inner_exception
|
25
|
-
inner_exception.to_s
|
26
|
-
else
|
27
|
-
super
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class Connect < Base
|
33
|
-
end
|
34
|
-
|
35
|
-
class Auth < Base
|
36
|
-
end
|
37
|
-
|
38
|
-
class Connect < Base
|
39
|
-
end
|
40
|
-
|
41
|
-
class NotFound < Base
|
42
|
-
end
|
43
|
-
|
44
|
-
class Invalid < Base
|
45
|
-
end
|
46
|
-
|
47
|
-
class KeyExists < Base
|
48
|
-
end
|
49
|
-
|
50
|
-
class ValueFormat < Base
|
51
|
-
end
|
52
|
-
|
53
|
-
class TemporaryFail < Base
|
54
|
-
end
|
55
|
-
|
56
|
-
class NotStored < Base
|
57
22
|
end
|
58
23
|
end
|
59
24
|
end
|
data/lib/couchbase/operations.rb
CHANGED
@@ -1,46 +1,66 @@
|
|
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
|
-
require 'couchbase/operations/touch'
|
19
|
-
require 'couchbase/operations/store'
|
20
|
-
require 'couchbase/operations/get'
|
21
|
-
require 'couchbase/operations/fetch'
|
22
|
-
require 'couchbase/operations/delete'
|
23
|
-
require 'couchbase/operations/unlock'
|
24
|
-
require 'couchbase/operations/arithmetic'
|
25
|
-
require 'couchbase/operations/stats'
|
26
|
-
require 'couchbase/operations/design_docs'
|
27
|
-
require 'couchbase/operations/utils'
|
28
|
-
|
29
1
|
module Couchbase
|
30
2
|
module Operations
|
3
|
+
java_import com.couchbase.client.java.PersistTo
|
4
|
+
java_import com.couchbase.client.java.document.RawJsonDocument
|
5
|
+
|
6
|
+
RAW_JSON_DOCUMENT_CLASS = RawJsonDocument.java_class
|
7
|
+
|
8
|
+
PERSIST_TO = {
|
9
|
+
:master => PersistTo::MASTER,
|
10
|
+
0 => PersistTo::NONE,
|
11
|
+
1 => PersistTo::ONE,
|
12
|
+
2 => PersistTo::TWO,
|
13
|
+
3 => PersistTo::THREE,
|
14
|
+
4 => PersistTo::FOUR
|
15
|
+
}
|
16
|
+
|
17
|
+
def set(id, value, options = {})
|
18
|
+
if options[:persist_to]
|
19
|
+
upsert_with_persistance(id, value, options)
|
20
|
+
else
|
21
|
+
upsert(id, value, options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def upsert(id, value, options = {})
|
26
|
+
doc = doc_with_ttl(id, value, options)
|
27
|
+
@bucket.upsert(doc)
|
28
|
+
end
|
29
|
+
|
30
|
+
def upsert_with_persistance(id, value, options = {})
|
31
|
+
doc = doc_with_ttl(id, value, options)
|
32
|
+
@bucket.upsert(doc, PERSIST_TO[options[:persist_to]])
|
33
|
+
end
|
34
|
+
|
35
|
+
def add(id, value, options = {})
|
36
|
+
insert(id, value, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def insert(id, value, options = {})
|
40
|
+
doc = doc_with_ttl(id, value, options)
|
41
|
+
@bucket.insert(doc)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get(id, options = {})
|
45
|
+
doc = @bucket.get(id, RAW_JSON_DOCUMENT_CLASS)
|
46
|
+
return nil if doc.nil?
|
47
|
+
Document.new(doc)
|
48
|
+
end
|
31
49
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
50
|
+
def remove(id)
|
51
|
+
@bucket.remove(id)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def doc_with_ttl(id, value, options)
|
57
|
+
value = MultiJson.dump(value) unless value.respond_to?(:to_str)
|
58
|
+
|
59
|
+
if options[:ttl]
|
60
|
+
RawJsonDocument.create(id, options[:ttl], value)
|
61
|
+
else
|
62
|
+
RawJsonDocument.create(id, value)
|
63
|
+
end
|
43
64
|
end
|
44
65
|
end
|
45
66
|
end
|
46
|
-
|
data/lib/couchbase/version.rb
CHANGED