Skip to content
Browse files

Merge pull request #2 from jzinedine/master

Add view querying method close to Ruby API, update the referenced jar files, bump the gem version
  • Loading branch information...
2 parents 37ad1e4 + fd0a906 commit a76941e19bd0b7fa5ed4218f08c7e503113b99ec @jeremy-brenner committed May 24, 2013
Showing with 151 additions and 85 deletions.
  1. +37 −1 README.md
  2. +21 −21 jcouchbase.gemspec
  3. BIN lib/jcouchbase/jars/asm-4.1.jar
  4. BIN lib/jcouchbase/jars/cglib-2.2.2.jar
  5. BIN lib/jcouchbase/jars/commons-codec-1.5.jar
  6. BIN lib/jcouchbase/jars/commons-codec-1.6.jar
  7. BIN lib/jcouchbase/jars/commons-codec-1.7.jar
  8. BIN lib/jcouchbase/jars/commons-logging-1.1.1.jar
  9. BIN lib/jcouchbase/jars/commons-logging-1.1.2.jar
  10. BIN lib/jcouchbase/jars/couchbase-client-1.1-dp2-javadocs.jar
  11. BIN lib/jcouchbase/jars/couchbase-client-1.1-dp2.jar
  12. BIN lib/jcouchbase/jars/couchbase-client-1.1.4-sources.jar
  13. BIN lib/jcouchbase/jars/couchbase-client-1.1.4.jar
  14. BIN lib/jcouchbase/jars/fluent-hc-4.2.1.jar
  15. BIN lib/jcouchbase/jars/fluent-hc-4.2.3.jar
  16. BIN lib/jcouchbase/jars/{httpclient-4.2.1.jar → httpclient-4.2.3.jar}
  17. BIN lib/jcouchbase/jars/{httpclient-cache-4.2.1.jar → httpclient-cache-4.2.3.jar}
  18. BIN lib/jcouchbase/jars/httpcore-4.1.1.jar
  19. BIN lib/jcouchbase/jars/{httpcore-4.2.1.jar → httpcore-4.2.4.jar}
  20. BIN lib/jcouchbase/jars/httpcore-ab-4.2.1.jar
  21. BIN lib/jcouchbase/jars/httpcore-nio-4.1.1.jar
  22. BIN lib/jcouchbase/jars/{httpcore-nio-4.2.1.jar → httpcore-nio-4.2.4.jar}
  23. BIN lib/jcouchbase/jars/{httpmime-4.2.1.jar → httpmime-4.2.3.jar}
  24. BIN lib/jcouchbase/jars/jettison-1.1.jar
  25. BIN lib/jcouchbase/jars/jettison-1.3.3.jar
  26. BIN lib/jcouchbase/jars/log4j-1.2.17.jar
  27. BIN lib/jcouchbase/jars/netty-3.2.0.Final.jar
  28. BIN lib/jcouchbase/jars/netty-3.6.3.Final.jar
  29. BIN lib/jcouchbase/jars/spymemcached-2.8.12-javadocs.jar
  30. BIN lib/jcouchbase/jars/spymemcached-2.8.12-sources.jar
  31. BIN lib/jcouchbase/jars/spymemcached-2.8.12.jar
  32. BIN lib/jcouchbase/jars/spymemcached-2.8.4-javadocs.jar
  33. BIN lib/jcouchbase/jars/spymemcached-2.8.4.jar
  34. +92 −62 lib/jcouchbase/jcouchbase.rb
  35. +1 −1 lib/jcouchbase/version.rb
View
38 README.md
@@ -12,7 +12,7 @@ gem install jcouchbase
usage
=====
-
+```ruby
require 'jcouchbase'
c = Couchbase.new('http://xocouch01.localcloud:8091/pools', 'default', 'secretpassword' )
@@ -21,7 +21,43 @@ c.set( 'mykey', 0, { 'blah' => 'blarg', 'blip' => [ 'bloop', 'blorp', 'blop' ] }
p c['mykey']
+c.get_view('sample_design_doc', 'sample_view', 'sample_key')
+c.get_view('sample_design_doc', 'sample_view', ['sample_key1','sample_key2'])
+
+#query view using a single or multiple keys
+key = {:id=> "1", :name=> "reza"}
+c.get_view('sample_design_doc', 'sample_view', key)
+
+keys = [{:id=> "1", :name=> "ali"}, {:id=> "2", :name=>"sali"}]
+c.get_view('sample_design_doc', 'sample_view', keys)
+
+
+# remember that the order of keys inside argument must be the same as defined in the view
+# for example the next expression return nothing even if the corresponding record is available
+wrong_key= {:name=>"reza", :id=> "1"}
+c.get_view('sample_design_doc', 'sample_view', wrong_key)
+
c.shutdown
+```
+
+use log4j
+=====
+```ruby
+def setup_log4j
+ java::lang.System.setProperty("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.Log4JLogger")
+
+ fa = Java::OrgApacheLog4j::FileAppender.new();
+ fa.setName("FileLogger");
+
+ fa.setFile("./log/#{Rails.env}.log");
+ fa.setLayout(Java::OrgApacheLog4j::PatternLayout.new("%d %-5p [%c{1}] %m%n"));
+ fa.setThreshold(Java::OrgApacheLog4j::Level::INFO);
+ fa.setAppend(true);
+ fa.activateOptions();
+ Java::OrgApacheLog4j::Logger.getRootLogger().addAppender(fa)
+end
+setup_log4j
+```
links
=====
View
42 jcouchbase.gemspec
@@ -1,8 +1,8 @@
Gem::Specification.new do |s|
s.name = 'jcouchbase'
- s.version = '0.1.4'
- s.date = '2012-08-29'
- s.platform = Gem::Platform::RUBY
+ s.version = '0.1.5'
+ s.date = '2013-04-11'
+ s.platform = Gem::Platform::JAVA
s.authors = ["Jeremy J Brenner"]
s.email = ["jeremyjbrenner@gmail.com"]
s.summary = "Thin ruby wrapper around Couchbase Java Driver; for JRuby only"
@@ -16,24 +16,24 @@ Gem::Specification.new do |s|
Rakefile
jcouchbase.gemspec
lib/jcouchbase.rb
- lib/jcouchbase/jars/commons-codec-1.5.jar
- lib/jcouchbase/jars/commons-codec-1.6.jar
- lib/jcouchbase/jars/commons-logging-1.1.1.jar
- lib/jcouchbase/jars/couchbase-client-1.1-dp2-javadocs.jar
- lib/jcouchbase/jars/couchbase-client-1.1-dp2.jar
- lib/jcouchbase/jars/fluent-hc-4.2.1.jar
- lib/jcouchbase/jars/httpclient-4.2.1.jar
- lib/jcouchbase/jars/httpclient-cache-4.2.1.jar
- lib/jcouchbase/jars/httpcore-4.1.1.jar
- lib/jcouchbase/jars/httpcore-4.2.1.jar
- lib/jcouchbase/jars/httpcore-ab-4.2.1.jar
- lib/jcouchbase/jars/httpcore-nio-4.1.1.jar
- lib/jcouchbase/jars/httpcore-nio-4.2.1.jar
- lib/jcouchbase/jars/httpmime-4.2.1.jar
- lib/jcouchbase/jars/jettison-1.1.jar
- lib/jcouchbase/jars/netty-3.2.0.Final.jar
- lib/jcouchbase/jars/spymemcached-2.8.4-javadocs.jar
- lib/jcouchbase/jars/spymemcached-2.8.4.jar
+ lib/jcouchbase/jars/asm-4.1.jar
+ lib/jcouchbase/jars/cglib-2.2.2.jar
+ lib/jcouchbase/jars/commons-codec-1.7.jar
+ lib/jcouchbase/jars/commons-logging-1.1.2.jar
+ lib/jcouchbase/jars/couchbase-client-1.1.4-sources.jar
+ lib/jcouchbase/jars/couchbase-client-1.1.4.jar
+ lib/jcouchbase/jars/fluent-hc-4.2.3.jar
+ lib/jcouchbase/jars/httpclient-4.2.3.jar
+ lib/jcouchbase/jars/httpclient-cache-4.2.3.jar
+ lib/jcouchbase/jars/httpcore-4.2.4.jar
+ lib/jcouchbase/jars/httpcore-nio-4.2.4.jar
+ lib/jcouchbase/jars/httpmime-4.2.3.jar
+ lib/jcouchbase/jars/jettison-1.3.3.jar
+ lib/jcouchbase/jars/log4j-1.2.17.jar
+ lib/jcouchbase/jars/netty-3.6.3.Final.jar
+ lib/jcouchbase/jars/spymemcached-2.8.12-javadocs.jar
+ lib/jcouchbase/jars/spymemcached-2.8.12-sources.jar
+ lib/jcouchbase/jars/spymemcached-2.8.12.jar
lib/jcouchbase/jcouchbase.rb
lib/jcouchbase/version.rb
]
View
BIN lib/jcouchbase/jars/asm-4.1.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/cglib-2.2.2.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/commons-codec-1.5.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/commons-codec-1.6.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/commons-codec-1.7.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/commons-logging-1.1.1.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/commons-logging-1.1.2.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/couchbase-client-1.1-dp2-javadocs.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/couchbase-client-1.1-dp2.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/couchbase-client-1.1.4-sources.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/couchbase-client-1.1.4.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/fluent-hc-4.2.1.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/fluent-hc-4.2.3.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/httpclient-4.2.1.jar → lib/jcouchbase/jars/httpclient-4.2.3.jar 100644 → 100755
Binary file not shown.
View
BIN ...couchbase/jars/httpclient-cache-4.2.1.jar → ...couchbase/jars/httpclient-cache-4.2.3.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/httpcore-4.1.1.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/httpcore-4.2.1.jar → lib/jcouchbase/jars/httpcore-4.2.4.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/httpcore-ab-4.2.1.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/httpcore-nio-4.1.1.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/httpcore-nio-4.2.1.jar → lib/jcouchbase/jars/httpcore-nio-4.2.4.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/httpmime-4.2.1.jar → lib/jcouchbase/jars/httpmime-4.2.3.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/jettison-1.1.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/jettison-1.3.3.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/log4j-1.2.17.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/netty-3.2.0.Final.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/netty-3.6.3.Final.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/spymemcached-2.8.12-javadocs.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/spymemcached-2.8.12-sources.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/spymemcached-2.8.12.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/spymemcached-2.8.4-javadocs.jar
Binary file not shown.
View
BIN lib/jcouchbase/jars/spymemcached-2.8.4.jar
Binary file not shown.
View
154 lib/jcouchbase/jcouchbase.rb 100644 → 100755
@@ -1,7 +1,7 @@
# Copyright (C) 2012 Jeremy Brenner
#
# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in coSmpliance with the License.
+# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@@ -11,102 +11,132 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+include Java
class Couchbase
- include_class java.io.IOException
- include_class java.net.SocketAddress
- include_class java.net.URI
- include_class java.net.URISyntaxException
- include_class java.util.ArrayList
- include_class java.util.LinkedList
- include_class java.util.List
- include_class java.util.concurrent.Future
- include_class java.util.concurrent.TimeUnit
-
- include_class javax.naming.ConfigurationException
-
- include_class Java::net.spy.memcached.CASMutation
- include_class Java::net.spy.memcached.CASMutator
- include_class Java::net.spy.memcached.CASResponse
- include_class Java::net.spy.memcached.CASValue
- include_class Java::net.spy.memcached.CachedData
- include_class Java::net.spy.memcached.ConnectionObserver
- include_class Java::net.spy.memcached.transcoders.SerializingTranscoder
- include_class Java::net.spy.memcached.transcoders.Transcoder
-
- include_class Java::org.apache.http.HttpEntity
- include_class Java::org.apache.http.HttpEntityEnclosingRequest
- include_class Java::org.apache.http.HttpHost
- include_class Java::org.apache.http.HttpRequest
- include_class Java::org.apache.http.HttpResponse
- include_class Java::org.apache.http.HttpStatus
- include_class Java::org.apache.http.ProtocolVersion
- include_class Java::org.apache.http.client.ClientProtocolException
- include_class Java::org.apache.http.client.HttpClient
- include_class Java::org.apache.http.entity.ByteArrayEntity
- include_class Java::org.apache.http.impl.cookie.DateUtils
- include_class Java::org.apache.http.message.BasicHttpEntityEnclosingRequest
- include_class Java::org.apache.http.message.BasicHttpRequest
- include_class Java::org.apache.http.message.BasicHttpResponse
- include_class Java::org.apache.http.protocol.HttpContext
-
- include_class com.couchbase.client.CouchbaseClient
- include_class com.couchbase.client.CouchbaseConnectionFactory
+ import java.io.IOException
+ import java.net.SocketAddress
+ import java.net.URI
+ import java.net.URISyntaxException
+ import java.util.ArrayList
+ import java.util.LinkedList
+ import java.util.List
+ import java.util.concurrent.Future
+ import java.util.concurrent.TimeUnit
+
+ import javax.naming.ConfigurationException
+
+ import Java::net.spy.memcached.CASMutation
+ import Java::net.spy.memcached.CASMutator
+ import Java::net.spy.memcached.CASResponse
+ import Java::net.spy.memcached.CASValue
+ import Java::net.spy.memcached.CachedData
+ import Java::net.spy.memcached.ConnectionObserver
+ import Java::net.spy.memcached.transcoders.SerializingTranscoder
+ import Java::net.spy.memcached.transcoders.Transcoder
+
+ import Java::org.apache.http.HttpEntity
+ import Java::org.apache.http.HttpEntityEnclosingRequest
+ import Java::org.apache.http.HttpHost
+ import Java::org.apache.http.HttpRequest
+ import Java::org.apache.http.HttpResponse
+ import Java::org.apache.http.HttpStatus
+ import Java::org.apache.http.ProtocolVersion
+ import Java::org.apache.http.client.ClientProtocolException
+ import Java::org.apache.http.client.HttpClient
+ import Java::org.apache.http.entity.ByteArrayEntity
+ import Java::org.apache.http.impl.cookie.DateUtils
+ import Java::org.apache.http.message.BasicHttpEntityEnclosingRequest
+ import Java::org.apache.http.message.BasicHttpRequest
+ import Java::org.apache.http.message.BasicHttpResponse
+ import Java::org.apache.http.protocol.HttpContext
+
+ import com.couchbase.client.CouchbaseClient
+ import com.couchbase.client.CouchbaseConnectionFactory
+
+ import com.couchbase.client.protocol.views.Query
+
Observer = java.util.Observer
def initialize(pool_uris, bucket, password='')
@urilist = ArrayList.new
- pool_uris = [ pool_uris ] if pool_uris.is_a? String
+ pool_uris = [pool_uris] if pool_uris.is_a? String
pool_uris.each { |uri| @urilist << URI.new(uri) }
@bucket = bucket
@password = password
self.connect
end
def connect
- @connection_factory = CouchbaseConnectionFactory.new( @urilist, @bucket.to_java_string, @password.to_java_string )
+ @connection_factory = CouchbaseConnectionFactory.new(@urilist, @bucket.to_java_string, @password.to_java_string)
@client = CouchbaseClient.new(@connection_factory)
self
end
+ #based on https://gist.github.com/erdeszt/4154011 by
+ def get_view(design, view, keys = nil, include_docs = true)
+ query = Query.new
+ query.setIncludeDocs(include_docs)
+ view = @client.getView(design, view)
+ if keys.is_a? Array
+ query.setKeys("[#{keys.map{|e| "[#{e.to_json}]"}.join(',')}]")
+ else
+ query.setKey("[#{keys.to_json}]")
+ end
+ @client.asyncQuery(view, query).get.iterator.map do |row|
+ {
+ :id => row.getId,
+ :document => to_hash(row.getDocument),
+ :view_key => row.getKey,
+ :view_value => row.getValue,
+ }
+ end
+ end
+
def javify(o)
- if( o.is_a? Hash )
- o.each { |k,v| o[k] = self.javify(v) }
- return java.util.HashMap.new( o )
+ if o.is_a? Hash
+ o.each { |k, v| o[k] = self.javify(v) }
+ return java.util.HashMap.new(o)
end
- if( o.is_a? Array )
- o.each_index { |i| o[i] = self.javify( o[i] ) }
- return java.util.ArrayList.new( o )
+ if o.is_a? Array
+ o.each_index { |i| o[i] = self.javify(o[i]) }
+ return java.util.ArrayList.new(o)
end
- return o
+ o
end
def rubify(o)
- if( o.is_a? Java::JavaUtil::HashMap )
+ if o.is_a? Java::JavaUtil::HashMap
h = {}
- o.each { |k,v| h[k] = self.rubify(v) }
+ o.each { |k, v| h[k] = self.rubify(v) }
return h
end
- if( o.is_a? Java::JavaUtil::ArrayList )
- a = []
- o.each { |v| a << self.rubify(v) }
- return a
+ if o.is_a? Java::JavaUtil::ArrayList
+ a = []
+ o.each { |v| a << self.rubify(v) }
+ return a
end
- return o
+ o
end
- %w( shutdown add append delete asyncCAS asyncDecr asyncGetAndTouch asyncGet asyncGetBulk asyncGet asyncGets asyncIncr cas decr delete getAndTouch getBulk get gets getStats incr prepend replace set touch ).each do |meth|
+ %w( shutdown add append delete asyncCAS asyncDecr asyncGetAndTouch asyncGet asyncGetBulk asyncGet asyncGets asyncIncr cas decr delete getAndTouch getBulk get gets getStats getView incr prepend replace set touch ).each do |meth|
define_method(meth) do |*args|
- self.rubify( @client.send( meth.to_sym, *args.map { |a| self.javify(a) } ) )
+ self.rubify(@client.send(meth.to_sym, *args.map { |a| self.javify(a) }))
end
end
- def []= ( key, value )
- self.set( key, 0, value )
+ def []= (key, value)
+ self.set(key, 0, value)
end
- def [] ( key )
- self.get( key )
+ def [](key)
+ to_hash(self.get(key))
end
+
+ private
+ def to_hash(value)
+ Hash[JSON.parse(value).map { |key, value| [key.to_sym, value] }]
+ end
+
end
View
2 lib/jcouchbase/version.rb
@@ -1,3 +1,3 @@
class Couchbase
- VERSION = '0.1.4'
+ VERSION = '0.1.5'
end

0 comments on commit a76941e

Please sign in to comment.
Something went wrong with that request. Please try again.