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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +103 -0
  3. data/.ruby-version +1 -1
  4. data/Rakefile +13 -2
  5. data/couchbase-jruby-client.gemspec +7 -6
  6. data/lib/couchbase/bucket.rb +11 -338
  7. data/lib/couchbase/cluster.rb +10 -88
  8. data/lib/couchbase/configuration.rb +39 -0
  9. data/lib/couchbase/design_doc.rb +18 -73
  10. data/lib/couchbase/document.rb +34 -0
  11. data/lib/couchbase/error.rb +0 -35
  12. data/lib/couchbase/operations.rb +60 -40
  13. data/lib/couchbase/version.rb +1 -1
  14. data/lib/couchbase/view.rb +55 -345
  15. data/lib/couchbase.rb +37 -141
  16. data/lib/jars/couchbase-core-io-1.1.4.jar +0 -0
  17. data/lib/jars/couchbase-java-client-2.1.4.jar +0 -0
  18. data/lib/jars/rxjava-1.0.8.jar +0 -0
  19. data/lib/jars/rxjruby-0.0.1.jar +0 -0
  20. data/test/{test_cas.rb → helper.rb} +15 -10
  21. data/test/test_bucket.rb +14 -228
  22. data/test/test_cluster.rb +1 -29
  23. data/test/test_configuration.rb +51 -0
  24. data/test/test_couchbase.rb +28 -28
  25. data/test/test_design_doc.rb +29 -0
  26. data/test/test_document.rb +51 -0
  27. data/test/test_operations.rb +49 -0
  28. data/test/test_view.rb +62 -116
  29. metadata +43 -125
  30. data/lib/couchbase/async/callback.rb +0 -38
  31. data/lib/couchbase/async/queue.rb +0 -26
  32. data/lib/couchbase/async.rb +0 -32
  33. data/lib/couchbase/constants.rb +0 -29
  34. data/lib/couchbase/operations/arithmetic.rb +0 -290
  35. data/lib/couchbase/operations/delete.rb +0 -115
  36. data/lib/couchbase/operations/design_docs.rb +0 -99
  37. data/lib/couchbase/operations/fetch.rb +0 -33
  38. data/lib/couchbase/operations/get.rb +0 -303
  39. data/lib/couchbase/operations/stats.rb +0 -42
  40. data/lib/couchbase/operations/store.rb +0 -463
  41. data/lib/couchbase/operations/touch.rb +0 -140
  42. data/lib/couchbase/operations/unlock.rb +0 -209
  43. data/lib/couchbase/operations/utils.rb +0 -68
  44. data/lib/couchbase/query.rb +0 -76
  45. data/lib/couchbase/result.rb +0 -60
  46. data/lib/couchbase/transcoder.rb +0 -81
  47. data/lib/couchbase/utils.rb +0 -62
  48. data/lib/couchbase/view_row.rb +0 -227
  49. data/lib/jars/commons-codec-1.5.jar +0 -0
  50. data/lib/jars/couchbase-client-1.3.2-javadoc.jar +0 -0
  51. data/lib/jars/couchbase-client-1.3.2-sources.jar +0 -0
  52. data/lib/jars/couchbase-client-1.3.2.jar +0 -0
  53. data/lib/jars/httpcore-4.3.1.jar +0 -0
  54. data/lib/jars/httpcore-nio-4.3.1.jar +0 -0
  55. data/lib/jars/jettison-1.1.jar +0 -0
  56. data/lib/jars/netty-3.5.5.Final.jar +0 -0
  57. data/lib/jars/spymemcached-2.10.5-javadoc.jar +0 -0
  58. data/lib/jars/spymemcached-2.10.5-sources.jar +0 -0
  59. data/lib/jars/spymemcached-2.10.5.jar +0 -0
  60. data/tasks/benchmark.rake +0 -6
  61. data/tasks/test.rake +0 -36
  62. data/tasks/util.rake +0 -21
  63. data/test/mock.rb +0 -85
  64. data/test/profile/.gitignore +0 -1
  65. data/test/profile/.jrubyrc +0 -722
  66. data/test/profile/Gemfile +0 -7
  67. data/test/profile/benchmark.rb +0 -177
  68. data/test/profile/profile.rb +0 -59
  69. data/test/setup.rb +0 -74
  70. data/test/test_arithmetic.rb +0 -155
  71. data/test/test_async.rb +0 -24
  72. data/test/test_couchbase_rails_cache_store.rb +0 -341
  73. data/test/test_delete.rb +0 -139
  74. data/test/test_design_docs.rb +0 -67
  75. data/test/test_errors.rb +0 -74
  76. data/test/test_fetch.rb +0 -71
  77. data/test/test_format.rb +0 -142
  78. data/test/test_get.rb +0 -363
  79. data/test/test_query.rb +0 -23
  80. data/test/test_result.rb +0 -15
  81. data/test/test_stats.rb +0 -44
  82. data/test/test_store.rb +0 -203
  83. data/test/test_touch.rb +0 -90
  84. data/test/test_unlock.rb +0 -89
  85. data/test/test_utils.rb +0 -67
  86. data/test/test_version.rb +0 -28
  87. data/test/test_view_row.rb +0 -74
@@ -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
- def initialize(bucket, doc)
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
- def method_missing(meth, *args)
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
- def respond_to_missing?(meth, *args)
45
- @all_views[meth.to_s] || super
46
- end
7
+ java_import com.couchbase.client.java.view.DesignDocument
8
+ java_import com.couchbase.client.java.view.DefaultView
47
9
 
48
- # The list of views defined or empty array
49
- #
50
- # @since 1.2.1
51
- #
52
- # @return [Array<View>]
53
- attr_accessor :views
54
-
55
- # The list of spatial views defined or empty array
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
- desc << ">"
79
- desc
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
@@ -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
@@ -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 self.included(klass)
33
- klass.send(:include, Store)
34
- klass.send(:include, Get)
35
- klass.send(:include, Fetch)
36
- klass.send(:include, Touch)
37
- klass.send(:include, Delete)
38
- klass.send(:include, Unlock)
39
- klass.send(:include, Arithmetic)
40
- klass.send(:include, Stats)
41
- klass.send(:include, DesignDocs)
42
- klass.send(:include, Utils)
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
-
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module Couchbase
19
- VERSION = '0.2.2'
19
+ VERSION = '1.0.4'
20
20
  end