Permalink
Browse files

Refactored and modified docstrings.

  • Loading branch information...
1 parent 03264d8 commit 8b5fee18cb80aa18d0566d98b3d3a7cbfc4ea159 @otabat committed Feb 20, 2014
View
487 src/couchbase_clj/client.clj
@@ -1,30 +1,21 @@
(ns couchbase-clj.client
(:import [java.net URI]
[java.util Collection]
- [java.util.concurrent TimeUnit]
- [java.util.concurrent Future]
+ [java.util.concurrent TimeUnit Future]
[net.spy.memcached CASValue]
- [net.spy.memcached.internal GetFuture]
- [net.spy.memcached.internal BulkGetFuture]
- [net.spy.memcached.internal OperationFuture]
+ [net.spy.memcached.internal GetFuture BulkGetFuture OperationFuture]
[net.spy.memcached.transcoders Transcoder]
- [net.spy.memcached PersistTo]
- [net.spy.memcached ReplicateTo]
- [com.couchbase.client CouchbaseClient]
- [com.couchbase.client CouchbaseConnectionFactory]
+ [net.spy.memcached PersistTo ReplicateTo]
+ [com.couchbase.client CouchbaseClient CouchbaseConnectionFactory]
[com.couchbase.client.internal HttpFuture]
- [com.couchbase.client.protocol.views Query]
- [com.couchbase.client.protocol.views View]
- [com.couchbase.client.protocol.views ViewRow]
- [couchbase_clj.client_builder.CouchbaseCljClientBuilder]
- [couchbase_clj.query.CouchbaseCljQuery])
+ [com.couchbase.client.protocol.views Query View ViewRow])
(:refer-clojure :exclude [get set replace flush inc dec replicate
future-cancel future-cancelled? future-done?])
- (:require [couchbase-clj.query :as cbq])
- (:use [couchbase-clj.client-builder]
- [couchbase-clj.config]
- [couchbase-clj.future]
- [couchbase-clj.util]))
+ (:require [couchbase-clj.query :as cb-query]
+ [couchbase-clj.config :as cb-config]
+ [couchbase-clj.client-builder :as cb-client-builder]
+ [couchbase-clj.future :as cb-future]
+ [couchbase-clj.util :as cb-util]))
(def ^:private persist-to-map {:master PersistTo/MASTER
:one PersistTo/ONE
@@ -46,25 +37,25 @@
TWO requires Persist to at least two nodes including the Master.
THREE requires Persist to at least three nodes including the Master.
FOUR requires Persist to at least four nodes including the Master."
- ([] (@default-persist persist-to-map))
+ ([] (@cb-config/default-persist persist-to-map))
([persist]
(or (and persist (persist persist-to-map))
- (@default-persist persist-to-map))))
+ (@cb-config/default-persist persist-to-map))))
(defn replicate-to
"Get the ReplicateTo object by specifying a corresponding keyword argument.
replicate can be :zero, :one, :two, :three
If other value or no argument is specified,
@couchbase-clj.config/default-replicate will be specified as the default value.
- ZERO implies no requirements for the data to be replicated to the replicas.
- ONE implies requirements for the data to be replicated with at least one replica.
- TWO implies requirements for the data to be replicated with at least two replicas.
- THREE implies requirements for the data to be replicated with at least three replicas."
- ([] (@default-replicate replicate-to-map))
+ ZERO requires no replication.
+ ONE requires the data to be replicated with at least one replica.
+ TWO requires the data to be replicated with at least two replicas.
+ THREE requires the data to be replicated with at least three replicas."
+ ([] (@cb-config/default-replicate replicate-to-map))
([replicate]
(or (and replicate (replicate replicate-to-map))
- (@default-replicate replicate-to-map))))
+ (@cb-config/default-replicate replicate-to-map))))
(defn cas-id
"Get the cas ID from the CASValue object."
@@ -82,7 +73,7 @@
"Get the JSON string value converted to Clojure data from the CASValue object.
nil is returned, if c is nil."
[^CASValue c]
- (read-json (.getValue c)))
+ (cb-util/read-json (.getValue c)))
(defn view-id
"Get the ID of query result from ViewRow object."
@@ -98,7 +89,7 @@
"Get the JSON string key of query result from ViewRow object,
converted to Clojure data."
[^ViewRow view]
- (read-json (.getKey view)))
+ (cb-util/read-json (.getKey view)))
(defn view-val
"Get the value of query result from ViewRow object."
@@ -109,7 +100,7 @@
"Get the JSON string value of query result from ViewRow object,
converted to Clojure data."
[^ViewRow view]
- (read-json (.getValue view)))
+ (cb-util/read-json (.getValue view)))
(defn view-doc
"Get the document of query result when include-docs is set to true."
@@ -120,15 +111,19 @@
"Get the JSON string document of query result converted to Clojure data
when include-docs is set to true."
[^ViewRow view]
- (read-json (.getDocument view)))
+ (cb-util/read-json (.getDocument view)))
(defprotocol ICouchbaseCljClient
(get-client [clj-client] "Get the CouchbaseClient object.")
(get-factory [clj-client] "Get the CouchbaseConnectionFactory object.")
- (get-available-servers [clj-client] "Get the addresses of available servers in a Vector.")
- (get-unavailable-servers [clj-client] "Get the addresses of unavailable servers in a Vector.")
- (get-node-locator [clj-client] "Get a read-only wrapper around the node locator wrapping this instance.")
- (get-versions [clj-client] "Get versions of all of the connected servers in a Map.")
+ (get-available-servers [clj-client]
+ "Get the addresses of available servers in a Vector.")
+ (get-unavailable-servers [clj-client]
+ "Get the addresses of unavailable servers in a Vector.")
+ (get-node-locator [clj-client]
+ "Get a read-only wrapper around the node locator wrapping this instance.")
+ (get-versions [clj-client]
+ "Get versions of all of the connected servers in a Map.")
(get-sasl-mechanisms [clj-client] "Get the list of sasl mechanisms in a Set.")
(get-client-status
[clj-client]
@@ -149,64 +144,77 @@
(get-op-queue-max-block-time [clj-client] "Get the op queue max block time.")
(get-op-timeout [clj-client]
"Get the operation timeout.
- This is used as a default timeout value for various sync and async client operations.")
+ This is used as a default timeout value for sync and async client operations.")
(get-read-buffer-size [clj-client] "Get the read buffer size.")
- (get-timeout-exception-threshold [clj-client] "Get the timeout exception threshold.")
+ (get-timeout-exception-threshold [clj-client]
+ "Get the timeout exception threshold.")
(get-transcoder [clj-client] "Get the default transcoder.")
(daemon? [clj-client]
- "Return true if IO thread should be a daemon thread, otherwise return false.")
+ "Return true if IO thread should be a daemon thread,
+ otherwise return false.")
(should-optimize? [clj-client]
- "Return if the performance should be optimized for the network, otherwise return false.")
+ "Return if the performance should be optimized for the network,
+ otherwise return false.")
(use-nagle-algorithm? [clj-client]
"Return true if the Nagle algorithm is specified, otherwise return false.")
(async-add
[clj-client k v]
[clj-client k v opts]
- "Asynchronously add a value with the specified key that does not already exist.
+ "Asynchronously add a value with the specified key
+ that does not already exist.
Return value is a CouchbaseCljOperationFuture object.
k is the key and can be a keyword, symbol or a string.
v is the value to be stored.
You can specify a optional key value map as the opts argument.
- Optional keywords are :expiry, :transcoder, and when :observe is set to true,
- persist, and :replicate can be set.
+ Optional keywords are :expiry, :transcoder, :observe, :persist,
+ and :replicate.
+ When :observe is set to true, persist, and :replicate can be set.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
SerializingTranscoder will be specified as the default transcoder.
observe is the Boolean flag to enable persist and replicate options.
- persist is the keyword to specify Persist requirements to Master and more servers.
+ persist is the keyword to specify Persist requirements
+ to Master and more servers.
Values can be :master, :one, :two, :three, :four.
If persist is not specified,
@couchbase-clj.config/default-persist will be specified as the default value.
- replicate is the keyword to specify Replication requirements to zero or more replicas.
+ replicate is the keyword to specify Replication requirements
+ to zero or more replicas.
Values can be :zero, :one, :two, :three.
If other value or no argument is specified,
@couchbase-clj.config/default-replicate will be specified as a default value.")
(add
[clj-client k v]
[clj-client k v opts]
- "Synchronously add a value with the specified key that does not already exist.
+ "Synchronously add a value with the specified key
+ that does not already exist.
If adding has succeeded then true is returned, otherwise false.
k is the key and can be a keyword, symbol or a string.
v is the value to be stored.
You can specify a optional key value map as the opts argument.
- Optional keywords are :expiry, :transcoder, :timeout, and when :observe is set to true,
- :persist, and :replicate can be set.
+ Optional keywords are :expiry, :transcoder, :timeout, :observe, :persist,
+ and :replicate.
+ When :observe is set to true, :persist, and :replicate can be set.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days)
+ are interpreted as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
@@ -219,12 +227,14 @@
observe is the Boolean flag to enable persist and replicate options.
- persist is the keyword to specify Persist requirements to Master and more servers.
+ persist is the keyword to specify Persist requirements
+ to Master and more servers.
Values can be :master, :one, :two, :three, :four.
If persist is not specified,
@couchbase-clj.config/default-persist will be specified as the default value.
- replicate is the keyword to specify Replication requirements to zero or more replicas.
+ replicate is the keyword to specify Replication requirements
+ to zero or more replicas.
Values can be :zero, :one, :two, :three.
If other value or no argument is specified,
@couchbase-clj.config/default-replicate will be specified as a default value.")
@@ -348,7 +358,8 @@
(get-json
[clj-client k]
[clj-client k opts]
- "Synchronously get the JSON string value converted to Clojure data of the specified key.
+ "Synchronously get the JSON string value converted
+ to a Clojure data of the specified key.
You can specify a optional transcoder keyword in a map.
Arguments are the same as get.")
(async-get-touch
@@ -360,10 +371,12 @@
Optional keywords are :expiry and :transcoder.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
@@ -377,10 +390,12 @@
Optional keywords are :expiry and :transcoder.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
@@ -410,7 +425,8 @@
(get-multi-json
[clj-client k]
[clj-client k opts]
- "Synchronously get multiple JSON string value converted to Clojure data of the specified key.
+ "Synchronously get multiple JSON string value converted
+ to a Clojure data of the specified key.
You can specify a optional transcoder keyword in a map.
Arguments are the same as get-multi.")
(async-get-lock
@@ -424,7 +440,8 @@
expiry is the integer expiry time for key in seconds.
If expiry is not specified,
- @couchbase-clj.config/default-lock-expiry will be specified as the default value.
+ @couchbase-clj.config/default-lock-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
@@ -440,7 +457,8 @@
expiry is the integer expiry time for key in seconds.
If expiry is not specified,
- @couchbase-clj.config/default-lock-expiry will be specified as the default value.
+ @couchbase-clj.config/default-lock-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
@@ -488,7 +506,8 @@
offset is the integer offset value to increment.
If offset is not specified,
- @couchbase-clj.config/default-inc-offset will be specified as the default value.")
+ @couchbase-clj.config/default-inc-offset will be specified
+ as the default value.")
(inc
[clj-client k]
[clj-client k opts]
@@ -499,15 +518,18 @@
offset is the integer offset value to increment.
If offset is not specified,
- @couchbase-clj.config/default-inc-offset will be specified as the default value.
+ @couchbase-clj.config/default-inc-offset will be specified
+ as the default value.
default is the default value to increment if key does not exist.
If default is not specified,
- @couchbase-clj.config/default-inc-default will be specified as the default value.
+ @couchbase-clj.config/default-inc-default will be specified
+ as the default value.
expiry is the integer expiry time for key in seconds.
If expiry is not specified,
- @couchbase-clj.config/default-lock-expiry will be specified as the default value.")
+ @couchbase-clj.config/default-lock-expiry will be specified
+ as the default value.")
(async-dec
[clj-client k]
[clj-client k opts]
@@ -518,7 +540,8 @@
offset is the integer offset value to decrement.
If offset is not specified,
- @couchbase-clj.config/default-dec-offset will be specified as the default value.")
+ @couchbase-clj.config/default-dec-offset will be specified
+ as the default value.")
(dec
[clj-client k]
[clj-client k opts]
@@ -529,15 +552,18 @@
offset is the integer offset value to increment.
If offset is not specified,
- @couchbase-clj.config/default-inc-offset will be specified as the default value.
+ @couchbase-clj.config/default-inc-offset will be specified
+ as the default value.
default is the default value to increment if key does not exist.
If default is not specified,
- @couchbase-clj.config/default-inc-default will be specified as the default value.
+ @couchbase-clj.config/default-inc-default will be specified
+ as the default value.
expiry is the integer expiry time for key in seconds.
If expiry is not specified,
- @couchbase-clj.config/default-lock-expiry will be specified as the default value.")
+ @couchbase-clj.config/default-lock-expiry will be specified
+ as the default value.")
(async-replace
[clj-client k v]
[clj-client k v opts]
@@ -546,27 +572,32 @@
k is the key and can be a keyword, symbol or a string.
v is the value to be stored.
You can specify a optional key value map as the opts argument.
- Optional keywords are :expiry, :transcoder, and when :observe is set to true,
- :persist, and :replicate can be set.
+ Optional keywords are :expiry, :transcoder, :observe, :persist,
+ and :replicate.
+ When :observe is set to true, :persist, and :replicate can be set.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
SerializingTranscoder will be specified as the default transcoder.
observe is the Boolean flag to enable persist and replicate options.
- persist is the keyword to specify Persist requirements to Master and more servers.
+ persist is the keyword to specify Persist requirements
+ to Master and more servers.
Values can be :master, :one, :two, :three, :four.
If persist is not specified,
@couchbase-clj.config/default-persist will be specified as the default value.
- replicate is the keyword to specify Replication requirements to zero or more replicas.
+ replicate is the keyword to specify Replication requirements
+ to zero or more replicas.
Values can be :zero, :one, :two, :three.
If other value or no argument is specified,
@couchbase-clj.config/default-replicate will be specified as a default value.")
@@ -578,14 +609,17 @@
k is the key and can be a keyword, symbol or a string.
v is the value to be stored.
You can specify a optional key value map as the opts argument.
- Optional keywords are :expiry, :transcoder, :timeout, and when :observe is set to true,
- :persist, and :replicate can be set.
+ Optional keywords are :expiry, :transcoder, :timeout, :observe :persist,
+ and :replicate.
+ When :observe is set to true, :persist, and :replicate can be set.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days)
+ are interpreted as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
@@ -598,12 +632,14 @@
observe is the Boolean flag to enable persist and replicate options.
- persist is the keyword to specify Persist requirements to Master and more servers.
+ persist is the keyword to specify Persist requirements
+ to Master and more servers.
Values can be :master, :one, :two, :three, :four.
If persist is not specified,
@couchbase-clj.config/default-persist will be specified as the default value.
- replicate is the keyword to specify Replication requirements to zero or more replicas.
+ replicate is the keyword to specify Replication requirements
+ to zero or more replicas.
Values can be :zero, :one, :two, :three.
If other value or no argument is specified,
@couchbase-clj.config/default-replicate will be specified as a default value.")
@@ -627,27 +663,32 @@
k is the key and can be a keyword, symbol or a string.
v is the value to be stored.
You can specify a optional key value map as the opts argument.
- Optional keywords are :expiry, :transcoder, and when :observe is set to true,
- :persist, and :replicate can be set.
+ Optional keywords are :expiry, :transcoder, :observe, :persist,
+ and :repliate.
+ When :observe is set to true, :persist, and :replicate can be set.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
SerializingTranscoder will be specified as the default transcoder.
observe is the Boolean flag to enable persist and replicate options.
- persist is the keyword to specify Persist requirements to Master and more servers.
+ persist is the keyword to specify Persist requirements
+ to Master and more servers.
Values can be :master, :one, :two, :three, :four.
If persist is not specified,
@couchbase-clj.config/default-persist will be specified as the default value.
- replicate is the keyword to specify Replication requirements to zero or more replicas.
+ replicate is the keyword to specify Replication requirements
+ to zero or more replicas.
Values can be :zero, :one, :two, :three.
If other value or no argument is specified,
@couchbase-clj.config/default-replicate will be specified as a default value.")
@@ -659,14 +700,17 @@
k is the key and can be a keyword, symbol or a string.
v is the value to be stored.
You can specify a optional key value map as the opts argument.
- Optional keywords are :expiry, :transcoder, :timeout, and when :observe is set to true,
- :persist, and :replicate can be set.
+ Optional keywords are :expiry, :transcoder, :timeout, :observe, :persist,
+ and :replicate.
+ When :observe is set to true, :persist, and :replicate can be set.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
@@ -679,12 +723,14 @@
observe is the Boolean flag to enable persist and replicate options.
- persist is the keyword to specify Persist requirements to Master and more servers.
+ persist is the keyword to specify Persist requirements
+ to Master and more servers.
Values can be :master, :one, :two, :three, :four.
If persist is not specified,
@couchbase-clj.config/default-persist will be specified as the default value.
- replicate is the keyword to specify Replication requirements to zero or more replicas.
+ replicate is the keyword to specify Replication requirements
+ to zero or more replicas.
Values can be :zero, :one, :two, :three.
If other value or no argument is specified,
@couchbase-clj.config/default-replicate will be specified as a default value.")
@@ -714,10 +760,12 @@
Optional keywords are :expiry and :transcoder.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
@@ -735,25 +783,29 @@
Optional keywords are :expiry and :transcoder.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
transcoder is the Transcoder object to be used to serialize the value.
If transcoder is not specified,
SerializingTranscoder will be specified as the default transcoder.")
(async-set-cas-json
[clj-client k v cas-id]
[clj-client k v cas-id opts]
- "Asynchronously compare the CAS ID and store a value that is converted to a JSON string
+ "Asynchronously compare the CAS ID and store a value that is
+ converted to a JSON string
using the specified key.
Return value is a CouchbaseCljOperationFuture object.
Arguments are the same as async-set-cas.")
(set-cas-json
[clj-client k v cas-id]
[clj-client k v cas-id opts]
- "Synchronously compare the CAS ID and store a value that is converted to a JSON string
+ "Synchronously compare the CAS ID and store a value that is
+ converted to a JSON string
using the specified key.
Keyword results that are originally defined in CASResponse
and mapped by cas-response function will be returned.
@@ -767,10 +819,12 @@
Optional keyword is :expiry.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.")
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.")
(touch
[clj-client k]
[clj-client k opts]
@@ -780,10 +834,12 @@
Optional keywords are :expiry and :timeout.
expiry is the integer expiry time for key in seconds.
- Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times from the epoch.
+ Values larger than 30*24*60*60 seconds (30 days) are interpreted
+ as absolute times from the epoch.
By specifying -1, expiry can be disabled.
If expiry is not specified,
- @couchbase-clj.config/default-data-expiry will be specified as the default value.
+ @couchbase-clj.config/default-data-expiry will be specified
+ as the default value.
timeout is the integer operation timeout value in milliseconds.
If timeout is not specified, the default value will be the value
@@ -865,7 +921,7 @@
num is an integer to specify the amount of documents to get in each iterations.
lazy-query can be used to query a large data lazily
- that it allows you to only get the amount of documents specified per iteration.
+ that it allows you to only get the amount of documents specified per iteration.
ex:
(doseq [res (lazy-query clj-client view q num)]
@@ -939,75 +995,81 @@
(get-op-queue-max-block-time [clj-client] (.getOpQueueMaxBlockTime cf))
(get-op-timeout [clj-client] (.getOperationTimeout cf))
(get-read-buffer-size [clj-client] (.getReadBufSize cf))
- (get-timeout-exception-threshold [clj-client] (.getTimeoutExceptionThreshold cf))
+ (get-timeout-exception-threshold [clj-client]
+ (.getTimeoutExceptionThreshold cf))
(get-transcoder [clj-client] (.getTranscoder cc))
(daemon? [clj-client] (.isDaemon cf))
(should-optimize? [clj-client] (.shouldOptimize cf))
(use-nagle-algorithm? [clj-client] (.useNagleAlgorithm cf))
(async-add [clj-client k v] (async-add clj-client k v {}))
- (async-add [clj-client k v {:keys [^int expiry ^Transcoder transcoder
+ (async-add [clj-client k v {:keys [expiry ^Transcoder transcoder
observe persist replicate]}]
(let [^String nk (name k)
^String sv (str v)
- ^int exp (or expiry ^int @default-data-expiry)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)
^PersistTo p (persist-to persist)
^ReplicateTo r (replicate-to replicate)
^OperationFuture fut (if transcoder
(.add cc nk exp v transcoder)
(if (true? observe)
(.add cc nk exp sv p r)
(.add cc nk exp v)))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(add [clj-client k v] (add clj-client k v {}))
(add [clj-client k v {:keys [^long timeout] :as opts}]
(let [^long to (or timeout (.getOperationTimeout cf))
- ^OperationFuture fut (get-future (async-add clj-client k v opts))]
+ ^OperationFuture fut (cb-future/get-future
+ (async-add clj-client k v opts))]
(.get fut to TimeUnit/MILLISECONDS)))
(async-add-json [clj-client k v] (async-add-json clj-client k v {}))
(async-add-json [clj-client k v opts]
- (let [jv (write-json v)]
+ (let [jv (cb-util/write-json v)]
(async-add clj-client k jv opts)))
(add-json [clj-client k v] (add-json clj-client k v {}))
(add-json [clj-client k v opts]
- (let [jv (write-json v)]
+ (let [jv (cb-util/write-json v)]
(add clj-client k jv opts)))
(async-append [clj-client k v cas-id] (async-append clj-client k v cas-id {}))
(async-append [clj-client k v cas-id {:keys [^Transcoder transcoder]}]
(let [^String nk (name k)
^OperationFuture fut (if transcoder
(.append cc ^long cas-id nk v transcoder)
(.append cc ^long cas-id nk v))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(append [clj-client k v cas-id] (append clj-client k v cas-id {}))
(append [clj-client k v cas-id {:keys [^long timeout] :as opts}]
(let [^long to (or timeout (.getOperationTimeout cf))
- ^OperationFuture fut (get-future (async-append clj-client k v cas-id opts))]
+ ^OperationFuture fut (cb-future/get-future
+ (async-append clj-client k v cas-id opts))]
(.get fut to TimeUnit/MILLISECONDS)))
- (async-prepend [clj-client k v cas-id] (async-prepend clj-client k v cas-id {}))
+ (async-prepend [clj-client k v cas-id]
+ (async-prepend clj-client k v cas-id {}))
(async-prepend [clj-client k v cas-id {:keys [^Transcoder transcoder]}]
(let [^String nk (name k)
^OperationFuture fut (if transcoder
(.prepend cc ^long cas-id nk v transcoder)
(.prepend cc ^long cas-id nk v))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(prepend [clj-client k v cas-id] (prepend clj-client k v cas-id {}))
(prepend [clj-client k v cas-id {:keys [^long timeout] :as opts}]
(let [^long to (or timeout (.getOperationTimeout cf))
- ^OperationFuture fut (get-future (async-prepend clj-client k v cas-id opts))]
+ ^OperationFuture fut (cb-future/get-future
+ (async-prepend clj-client k v cas-id opts))]
(.get fut to TimeUnit/MILLISECONDS)))
;; TODO: Currently delete command through observe is unavailable
;; due to a bug in the couchbase cilent sdk.
(async-delete [clj-client k]
(let [^String nk (name k)
^OperationFuture fut (.delete cc nk)]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(delete [clj-client k] (delete clj-client k {}))
;; TODO: Currently delete command through observe is unavailable
;; due to a bug in the couchbase-cilent.
(delete [clj-client k {:keys [^long timeout]}]
(let [^long to (or timeout (.getOperationTimeout cf))
- ^OperationFuture fut (get-future (async-delete clj-client k))]
+ ^OperationFuture fut (cb-future/get-future
+ (async-delete clj-client k))]
(.get fut to TimeUnit/MILLISECONDS)))
(async-get [clj-client k]
(async-get clj-client k {}))
@@ -1016,28 +1078,28 @@
^GetFuture fut (if transcoder
(.asyncGet cc nk transcoder)
(.asyncGet cc nk))]
- (->CouchbaseCljGetFuture cf fut)))
+ (cb-future/->CouchbaseCljGetFuture cf fut)))
(get [clj-client k] (get clj-client k {}))
(get [clj-client k {:keys [^Transcoder transcoder]}]
(let [^String nk (name k)]
(if transcoder
(.get cc nk transcoder)
(.get cc nk))))
(get-json [clj-client k] (get-json clj-client k {}))
- (get-json [clj-client k opts] (read-json (get clj-client k opts)))
+ (get-json [clj-client k opts] (cb-util/read-json (get clj-client k opts)))
(async-get-touch [clj-client k]
(async-get-touch clj-client k {}))
- (async-get-touch [clj-client k {:keys [^int expiry ^Transcoder transcoder]}]
+ (async-get-touch [clj-client k {:keys [expiry ^Transcoder transcoder]}]
(let [^String nk (name k)
- ^int exp (or expiry ^int @default-data-expiry)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)
^OperationFuture fut (if transcoder
(.asyncGetAndTouch cc nk exp transcoder)
(.asyncGetAndTouch cc nk exp))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(get-touch [clj-client k] (get-touch clj-client k {}))
- (get-touch [clj-client k {:keys [^int expiry ^Transcoder transcoder]}]
+ (get-touch [clj-client k {:keys [expiry ^Transcoder transcoder]}]
(let [^String nk (name k)
- ^int exp (or expiry ^int @default-data-expiry)]
+ exp (-> (or expiry @cb-config/default-data-expiry) int)]
(when-let [^CASValue c (if transcoder
(.getAndTouch cc nk exp transcoder)
(.getAndTouch cc nk exp))]
@@ -1049,7 +1111,7 @@
^BulkGetFuture fut (if transcoder
(.asyncGetBulk cc seq-ks transcoder)
(.asyncGetBulk cc seq-ks))]
- (->CouchbaseCljBulkGetFuture cf fut)))
+ (cb-future/->CouchbaseCljBulkGetFuture cf fut)))
(get-multi [clj-client ks] (get-multi clj-client ks {}))
(get-multi [clj-client ks {:keys [^Transcoder transcoder]}]
(let [^Collection seq-ks (map name ks)
@@ -1061,22 +1123,22 @@
(get-multi-json [clj-client k] (get-multi-json clj-client k {}))
(get-multi-json [clj-client k opts]
(reduce #(merge %1 {(key %2)
- (read-json (val %2))})
+ (cb-util/read-json (val %2))})
nil
(get-multi clj-client k opts)))
(async-get-lock [clj-client k]
(async-get-lock clj-client k {}))
- (async-get-lock [clj-client k {:keys [^int expiry ^Transcoder transcoder]}]
+ (async-get-lock [clj-client k {:keys [expiry ^Transcoder transcoder]}]
(let [^String nk (name k)
- ^int exp (or expiry ^int @default-lock-expiry)
+ exp (-> (or expiry @cb-config/default-lock-expiry) int)
^OperationFuture fut (if transcoder
(.asyncGetAndLock cc nk exp transcoder)
(.asyncGetAndLock cc nk exp))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(get-lock [clj-client k] (get-lock clj-client k {}))
- (get-lock [clj-client k {:keys [^int expiry ^Transcoder transcoder]}]
+ (get-lock [clj-client k {:keys [expiry ^Transcoder transcoder]}]
(let [^String nk (name k)
- ^int exp (or expiry ^int @default-lock-expiry)
+ exp (-> (or expiry @cb-config/default-lock-expiry) int)
^CASValue c (if transcoder
(.getAndLock cc nk exp transcoder)
(.getAndLock cc nk exp))]
@@ -1094,7 +1156,7 @@
^OperationFuture fut (if transcoder
(.asyncGets cc nk transcoder)
(.asyncGets cc nk))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(get-cas [clj-client k] (get-cas clj-client k {}))
(get-cas [clj-client k {:keys [^Transcoder transcoder]}]
(let [^String nk (name k)]
@@ -1111,120 +1173,124 @@
(async-inc clj-client k {}))
(async-inc [clj-client k {:keys [^long offset]}]
(let [^String nk (name k)
- ^long ofst (or offset ^long @default-inc-offset)
+ ^long ofst (or offset ^long @cb-config/default-inc-offset)
^OperationFuture fut (.asyncIncr cc nk ofst)]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(inc [clj-client k] (inc clj-client k {}))
- (inc [clj-client k {:keys [^long offset ^long default ^int expiry]}]
+ (inc [clj-client k {:keys [^long offset ^long default expiry]}]
(let [^String nk (name k)
- ^long ofst (or offset ^long @default-inc-offset)
- ^long dflt (or default ^long @default-inc-default)
- ^int exp (or expiry ^int @default-data-expiry)]
+ ^long ofst (or offset ^long @cb-config/default-inc-offset)
+ ^long dflt (or default ^long @cb-config/default-inc-default)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)]
(.incr cc nk ofst dflt exp)))
(async-dec [clj-client k]
(async-dec clj-client k {}))
(async-dec [clj-client k {:keys [^long offset]}]
(let [^String nk (name k)
- ^long ofst (or offset ^long @default-dec-offset)
+ ^long ofst (or offset ^long @cb-config/default-dec-offset)
^OperationFuture fut (.asyncDecr cc nk ofst)]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(dec [clj-client k] (dec clj-client k {}))
- (dec [clj-client k {:keys [^long offset ^long default ^int expiry]}]
+ (dec [clj-client k {:keys [^long offset ^long default expiry]}]
(let [^String nk (name k)
- ^long ofst (or offset ^long @default-dec-offset)
- ^long dflt (or default ^long @default-dec-default)
- ^int exp (or expiry ^int @default-data-expiry)]
+ ^long ofst (or offset ^long @cb-config/default-dec-offset)
+ ^long dflt (or default ^long @cb-config/default-dec-default)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)]
(.decr cc nk ofst dflt exp)))
(async-replace [clj-client k v]
(async-replace clj-client k v {}))
- (async-replace [clj-client k v {:keys [^int expiry ^Transcoder transcoder
+ (async-replace [clj-client k v {:keys [expiry ^Transcoder transcoder
observe persist replicate]}]
(let [^String nk (name k)
^String sv (str v)
- ^int exp (or expiry ^int @default-data-expiry)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)
^PersistTo p (persist-to persist)
^ReplicateTo r (replicate-to replicate)
^OperationFuture fut (if transcoder
(.replace cc nk exp v transcoder)
(if (true? observe)
(.replace cc nk exp sv p r)
(.replace cc nk exp v)))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(replace [clj-client k v] (replace clj-client k v {}))
(replace [clj-client k v {:keys [^long timeout] :as opts}]
(let [^long to (or timeout (.getOperationTimeout cf))
- ^OperationFuture fut (get-future (async-replace clj-client k v opts))]
+ ^OperationFuture fut (cb-future/get-future
+ (async-replace clj-client k v opts))]
(.get fut to TimeUnit/MILLISECONDS)))
(async-replace-json [clj-client k v] (async-replace-json clj-client k v {}))
(async-replace-json [clj-client k v opts]
- (let [jv (write-json v)]
+ (let [jv (cb-util/write-json v)]
(async-replace clj-client k jv opts)))
(replace-json [clj-client k v] (replace-json clj-client k v {}))
(replace-json [clj-client k v opts]
- (let [jv (write-json v)]
+ (let [jv (cb-util/write-json v)]
(replace clj-client k jv opts)))
(async-set [clj-client k v] (async-set clj-client k v {}))
- (async-set [clj-client k v {:keys [^int expiry ^Transcoder transcoder
+ (async-set [clj-client k v {:keys [expiry ^Transcoder transcoder
observe persist replicate]}]
(let [^String nk (name k)
^String sv (str v)
- ^int exp (or expiry ^int @default-data-expiry)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)
^PersistTo p (persist-to persist)
^ReplicateTo r (replicate-to replicate)
^OperationFuture fut (if transcoder
(.set cc nk exp v transcoder)
(if (true? observe)
(.set cc nk exp sv p r)
(.set cc nk exp v)))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(set [clj-client k v] (set clj-client k v {}))
(set [clj-client k v {:keys [^long timeout] :as opts}]
(let [^long to (or timeout (.getOperationTimeout cf))
- ^OperationFuture fut (get-future (async-set clj-client k v opts))]
+ ^OperationFuture fut (cb-future/get-future
+ (async-set clj-client k v opts))]
(.get fut to TimeUnit/MILLISECONDS)))
(async-set-json [clj-client k v] (async-set-json clj-client k v {}))
(async-set-json [clj-client k v opts]
- (let [jv (write-json v)]
+ (let [jv (cb-util/write-json v)]
(async-set clj-client k jv opts)))
(set-json [clj-client k v] (set-json clj-client k v {}))
(set-json [clj-client k v opts]
- (let [jv (write-json v)]
+ (let [jv (cb-util/write-json v)]
(set clj-client k jv opts)))
(async-set-cas [clj-client k v cas-id]
(async-set-cas clj-client k v cas-id {}))
- (async-set-cas [clj-client k v cas-id {:keys [^int expiry ^Transcoder transcoder]}]
+ (async-set-cas [clj-client k v cas-id
+ {:keys [expiry ^Transcoder transcoder]}]
(let [^String nk (name k)
- ^int exp (or expiry ^int @default-data-expiry)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)
^Transcoder tc (or transcoder (get-transcoder clj-client))
^OperationFuture fut (.asyncCAS cc nk ^long cas-id exp v tc)]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(set-cas [clj-client k v cas-id] (set-cas clj-client k v cas-id {}))
- (set-cas [clj-client k v cas-id {:keys [^int expiry ^Transcoder transcoder]}]
+ (set-cas [clj-client k v cas-id {:keys [expiry ^Transcoder transcoder]}]
(let [^String nk (name k)
- ^int exp (or expiry ^int @default-data-expiry)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)
^Transcoder tc (or transcoder (get-transcoder clj-client))]
- (cas-response (.cas cc nk ^long cas-id exp v tc))))
+ (cb-future/cas-response (.cas cc nk ^long cas-id exp v tc))))
(async-set-cas-json [clj-client k v cas-id]
(async-set-cas-json clj-client k v cas-id {}))
(async-set-cas-json [clj-client k v cas-id opts]
- (let [jv (write-json v)]
+ (let [jv (cb-util/write-json v)]
(async-set-cas clj-client k jv cas-id opts)))
(set-cas-json [clj-client k v cas-id]
(set-cas-json clj-client k v cas-id {}))
(set-cas-json [clj-client k v cas-id opts]
- (let [jv (write-json v)]
+ (let [jv (cb-util/write-json v)]
(set-cas clj-client k jv cas-id opts)))
(async-touch [clj-client k]
(async-touch clj-client k {}))
- (async-touch [clj-client k {:keys [^int expiry]}]
+ (async-touch [clj-client k {:keys [expiry]}]
(let [^String nk (name k)
- ^int exp (or expiry ^int @default-data-expiry)
+ exp (-> (or expiry @cb-config/default-data-expiry) int)
^OperationFuture fut (.touch cc nk exp)]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(touch [clj-client k] (touch clj-client k {}))
(touch [clj-client k {:keys [^long timeout] :as opts}]
(let [^long to (or timeout (.getOperationTimeout cf))
- ^OperationFuture fut (get-future (async-touch clj-client k opts))]
+ ^OperationFuture fut (cb-future/get-future
+ (async-touch clj-client k opts))]
(.get fut to TimeUnit/MILLISECONDS)))
(async-unlock [clj-client k cas-id]
(async-unlock clj-client k cas-id {}))
@@ -1233,7 +1299,7 @@
^OperationFuture fut (if transcoder
(.asyncUnlock cc nk ^long cas-id transcoder)
(.asyncUnlock cc nk ^long cas-id))]
- (->CouchbaseCljOperationFuture cf fut)))
+ (cb-future/->CouchbaseCljOperationFuture cf fut)))
(unlock [clj-client k cas-id] (unlock clj-client k cas-id {}))
(unlock [clj-client k cas-id {:keys [^Transcoder transcoder]}]
(let [^String nk (name k)]
@@ -1242,7 +1308,7 @@
(.unlock cc nk ^long cas-id))))
(async-get-view [clj-client design-doc view-name]
(let [^HttpFuture fut (.asyncGetView cc design-doc view-name)]
- (->CouchbaseCljHttpFuture cf fut)))
+ (cb-future/->CouchbaseCljHttpFuture cf fut)))
(get-view [clj-client design-doc view-name] (.getView cc design-doc view-name))
;; TODO: Currently not supported due to API change in the Couchbase Client.
@@ -1257,34 +1323,35 @@
(let [^couchbase_clj.query.CouchbaseCljQuery
new-q (if (instance? couchbase_clj.query.CouchbaseCljQuery q)
q
- (cbq/create-query q))
- ^HttpFuture fut (.asyncQuery cc view (cbq/get-query new-q))]
- (->CouchbaseCljHttpFuture cf fut)))
+ (cb-query/create-query q))
+ ^HttpFuture fut (.asyncQuery cc view (cb-query/get-query new-q))]
+ (cb-future/->CouchbaseCljHttpFuture cf fut)))
(async-query [clj-client design-doc view-name q]
(let [^View view (get-view clj-client design-doc view-name)]
(async-query clj-client view q)))
(query [clj-client view q]
(let [^couchbase_clj.query.CouchbaseCljQuery
new-q (if (instance? couchbase_clj.query.CouchbaseCljQuery q)
q
- (cbq/create-query q))]
- (seq (.query cc view (cbq/get-query new-q)))))
+ (cb-query/create-query q))]
+ (seq (.query cc view (cb-query/get-query new-q)))))
(query [clj-client design-doc view-name q]
(let [^View view (get-view clj-client design-doc view-name)]
(query clj-client view q)))
(lazy-query [clj-client view q num]
(let [^couchbase_clj.query.CouchbaseCljQuery
new-q (if (instance? couchbase_clj.query.CouchbaseCljQuery q)
q
- (cbq/create-query q))]
- (-> (.paginatedQuery cc view (cbq/get-query new-q) num)
+ (cb-query/create-query q))]
+ (-> (.paginatedQuery cc view (cb-query/get-query new-q) num)
iterator-seq
lazy-seq)))
(lazy-query [clj-client design-doc view-name q num]
(let [^View view (get-view clj-client design-doc view-name)]
(lazy-query clj-client view q num)))
(wait-queue [clj-client] (wait-queue clj-client (.getOperationTimeout cf)))
- (wait-queue [clj-client timeout] (.waitForQueues cc timeout TimeUnit/MILLISECONDS))
+ (wait-queue [clj-client timeout]
+ (.waitForQueues cc timeout TimeUnit/MILLISECONDS))
;; TODO: Currently not working
; (observe [clj-client k cas-id]
@@ -1297,29 +1364,36 @@
;; TODO: Currently not working
;(flush [clj-client] (flush clj-client -1))
- ;(flush [clj-client delay] (.isSuccess (.getStatus (.flush cc ^int delay))))
+ ;(flush [clj-client delay] (.isSuccess (.getStatus (.flush cc delay))))
(shutdown [clj-client] (shutdown clj-client -1))
(shutdown [clj-client timeout] (.shutdown cc timeout TimeUnit/MILLISECONDS)))
(defn create-client
"Create and return a Couchbase client.
- If no parameters are specified, client will be created from default values specified in
- couchbase-clj.config.
-
- You can specify keywords parameters: bucket, username, password, uris, client-builder, factory and other opts.
- bucket is the bucket name. Default value is defined as @default-bucket and is \"default\".
- username is the bucket username. Default value is defined as @default-username and is a empty string.
+ If no parameters are specified, client will be created
+ from default values specified in couchbase-clj.config.
+
+ You can specify keywords parameters: bucket, username, password, uris,
+ client-builder, factory and other opts.
+ bucket is the bucket name. Default value is defined
+ as @default-bucket and is \"default\".
+ username is the bucket username. Default value is defined
+ as @default-username and is a empty string.
Currently username is ignored.
- password is the bucket password. Default value is defined as @default-password and is a empty string.
+ password is the bucket password. Default value is defined
+ as @default-password and is a empty string.
uris is a Collection of string uris, ex: [\"http://127.0.0.1:8091/pools\"]
- Other options can be specified for CouchbaseConnectionFactoryBuilder object creation.
- Internally, :failure-mode and :hash-alg must have a value and those default values are
- :redistribute and :native-hash respectively.
- All options for CouchbaseConnectionFactoryBuilder can be looked at couchbase-clj.client-builder/method-map Var.
+ Other options can be specified for CouchbaseConnectionFactoryBuilder
+ object creation.
+ Internally, :failure-mode and :hash-alg must have a value and those
+ default values are :redistribute and :native-hash respectively.
+ All options for CouchbaseConnectionFactoryBuilder can be looked at
+ couchbase-clj.client-builder/method-map Var.
- You can specify the client-builder keyword with the value of CouchbaseCljClientBuilder object
- which is created by couchbase-clj.client-builder/create-client-builder function.
+ You can specify the client-builder keyword with the value of
+ CouchbaseCljClientBuilder object which is created by
+ couchbase-clj.client-builder/create-client-builder function.
When doing this, bucket, username, password keywords should be specified.
By using a factory keyword, you can pass a CouchbaseConnectionFactory object
@@ -1348,9 +1422,10 @@
:transcoder (SerializingTranscoder.)
:use-nagle-algorithm false})
- (create-client {:client-builder (create-client-builder {:hash-alg :native-hash
- :failure-mode :redistribute
- :max-reconnect-delay 30000})
+ (create-client {:client-builder (create-client-builder
+ {:hash-alg :native-hash
+ :failure-mode :redistribute
+ :max-reconnect-delay 30000})
:uris [(URI. \"http://127.0.0.1:8091/pools\")]
:bucket \"default\"
:username \"\"
@@ -1361,16 +1436,22 @@
([{:keys [client-builder factory] :as opts}]
(let [cf (cond
(and client-builder
- (instance? couchbase_clj.client_builder.CouchbaseCljClientBuilder
- client-builder))
- (create-factory (-> (assoc opts :factory-builder (get-factory-builder client-builder))
- (dissoc :client-builder)))
- (and factory (instance? CouchbaseConnectionFactory factory)) factory
- :else (build opts))]
+ (instance?
+ couchbase_clj.client_builder.CouchbaseCljClientBuilder
+ client-builder))
+ (cb-client-builder/create-factory
+ (-> (assoc opts
+ :factory-builder
+ (cb-client-builder/get-factory-builder client-builder))
+ (dissoc :client-builder)))
+ (and factory (instance? CouchbaseConnectionFactory factory))
+ factory
+ :else (cb-client-builder/build opts))]
(->CouchbaseCljClient (CouchbaseClient. cf) cf))))
(defmacro defclient
- "A macro that defines a Var with Couchbase client specified by a name with or without options.
+ "A macro that defines a Var with Couchbase client specified by a name
+ with or without options.
See create-client function for detail."
([name]
`(def ~name (create-client)))
View
110 src/couchbase_clj/client_builder.clj
@@ -2,10 +2,9 @@
(:import [java.net URI]
[java.util Collection]
[java.util.concurrent TimeUnit]
- [net.spy.memcached FailureMode]
- [net.spy.memcached DefaultHashAlgorithm]
+ [net.spy.memcached FailureMode DefaultHashAlgorithm]
[com.couchbase.client CouchbaseConnectionFactoryBuilder])
- (:use [couchbase-clj.config]))
+ (:require [couchbase-clj.config :as cb-config]))
(defn- hash-alg
[k]
@@ -35,11 +34,13 @@
(str->uri [^String s] (URI. s)))
(defprotocol ICouchbaseCljClientBuilder
- (get-factory-builder [clj-client-builder] "Get the CouchbaseConnectionFactoryBuilder object.")
+ (get-factory-builder [clj-client-builder]
+ "Get the CouchbaseConnectionFactoryBuilder object.")
(set-auth-descriptor [clj-client-builder dsc]
"Set the auth descriptor to enable authentication on new connections.
dsc is an AuthDescriptor object.")
- (set-daemon [clj-client-builder b] "If true, the IO thread should be a daemon thread.")
+ (set-daemon [clj-client-builder b]
+ "If true, the IO thread should be a daemon thread.")
(set-failure-mode [clj-client-builder k]
"Set the failure mode as a keyword value.
Default values is :redistribute.
@@ -59,7 +60,8 @@
(set-max-reconnect-delay [clj-client-builder delay]
"Set maximum number of milliseconds to wait between reconnect attempts.
Default value is 30000.
- You can set this value lower when there is intermittent and frequent connection failures.")
+ You can set this value lower when there is intermittent
+ and frequent connection failures.")
;(set-min-reconnect-interval [clj-client-builder interval]
; "Set the default minimum reconnect interval in millisecs.
;Default values is 1100
@@ -70,32 +72,41 @@
(set-obs-poll-interval [clj-client-builder interval]
"Set the polling interval for Observe operations.
Default value is 100.
- Set this higher or lower depending on whether the polling needs to happen less or more frequently
- depending on the tolerance limits for the Observe operation as compared to other operations.")
+ Set this higher or lower depending on whether the polling needs
+ to happen less or more frequently depending on the tolerance limits
+ for the Observe operation as compared to other operations.")
(set-obs-poll-max [clj-client-builder poll]
- "Set the maximum times to poll the master and replica(s) to meet the desired durability requirements.
+ "Set the maximum times to poll the master and replica(s) to meet
+ the desired durability requirements.
Default value is 400.
- You could set this value higher if the Observe operations do not complete after the normal polling.")
+ You could set this value higher if the Observe operations do not complete
+ after the normal polling.")
(set-op-queue-max-block-time [clj-client-builder time]
- "Set the maximum time to block waiting for op queue operations to complete, in milliseconds.
+ "Set the maximum time to block waiting for op queue operations to complete,
+ in milliseconds.
Default value is 10000.
- The default has been set with the expectation that most requests are interactive and waiting
- for more than a few seconds is thus more undesirable than failing the request.
- However, this value could be lowered for operations not to block for this time.")
+ The default has been set with the expectation that most requests
+ are interactive and waiting for more than a few seconds is thus
+ more undesirable than failing the request.
+ However, this value could be lowered for operations
+ not to block for this time.")
(set-op-timeout [clj-client-builder timeout]
"Set the time for an operation to Timeout.
Default values is 2500.
- You can set this value higher when there is heavy network traffic and timeouts happen frequently.
+ You can set this value higher when there is heavy network traffic
+ and timeouts happen frequently.
This is used as a default timeout value for sync and async operations.
- For async operations, it is internally used as a default timeout value to get the result from Future objects.")
+ For async operations, it is internally used as a default timeout value to get
+ the result from Future objects.")
(set-read-buffer-size [clj-client-builder size]
"Set the read buffer size.
Default value is 16384.")
(set-should-optimize [clj-client-builder b]
"Set the optimize behavior for the network.
Default values is false.
- You can set this value to be true if the performance should be optimized for the network
- as in cases where there are some known issues with the network that may be causing adverse effects on applications.
+ You can set this value to be true if the performance should be optimized
+ for the network as in cases where there are some known issues with the network
+ that may be causing adverse effects on applications.
Currently it is ignored.")
(set-timeout-exception-threshold [clj-client-builder timeout]
"Set the maximum timeout exception threshold.
@@ -145,7 +156,8 @@
(.setUseNagleAlgorithm cfb b)))
(def
- ^{:doc "A key/value conversion map of client options to corresponding set functions."}
+ ^{:doc "A key/value conversion map of client options
+ to corresponding set functions."}
method-map
{:auth-descriptor set-auth-descriptor
:daemon set-daemon
@@ -180,48 +192,66 @@
"Create and return a CouchbaseCljClientBuilder object.
This will create a CouchbaseConnectionFactoryBuilder object internally.
opts is a map to specify options for CouchbaseConnectionFactoryBuilder object.
- Currenty :hash-alg and :failure-mode keywords must be specified,
- ex: (client-client-builder {:hash-alg :native-hash :failure-mode :redistribute}).
- After creating, you can set options, ex: (set-op-timeout clj-client-builder timeout).
+ Currenty :hash-alg and :failure-mode keywords must be specified.
+ ex:
+ (client-client-builder {:hash-alg :native-hash :failure-mode :redistribute})
+
+ After creating, you can set options.
+ ex: (set-op-timeout clj-client-builder timeout)
+
All options can be looked at method-map Var.
- You can get the internal CouchbaseConnectionFactoryBuilder and pass it to create-factory function to build client."
+ You can get the internal CouchbaseConnectionFactoryBuilder
+ and pass it to create-factory function to build client."
[opts]
- (let [builder (->CouchbaseCljClientBuilder (CouchbaseConnectionFactoryBuilder.))]
+ (let [builder (->CouchbaseCljClientBuilder
+ (CouchbaseConnectionFactoryBuilder.))]
(doseq [kv opts]
(dispatch builder kv))
builder))
(defn create-factory
"Create a CouchbaseConnectionFactory object.
- You must specify all keyword arguments: factory-builder, bucket, username, password, uris.
- factory-builder can be created from create-client-bulider with get-factory-builder function,
- :ex (get-factory-builder (create-client-builder opts)).
- uris must be a sequential collection of URI objects, :ex [(URI. \"http://127.0.0.1:8091/pools\")]"
+ You must specify all keyword arguments: factory-builder, bucket, username,
+ password, and uris.
+ factory-builder can be created from create-client-bulider
+ with get-factory-builder function.
+ :ex
+ (get-factory-builder (create-client-builder opts)).
+
+ uris must be a sequential collection of URI objects.
+ :ex
+ [(URI. \"http://127.0.0.1:8091/pools\")]"
[{:keys [^CouchbaseConnectionFactoryBuilder factory-builder
^String bucket ^String username ^String password uris]}]
- (.buildCouchbaseConnection
- ^CouchbaseConnectionFactoryBuilder factory-builder uris bucket username password))
+ (-> ^CouchbaseConnectionFactoryBuilder factory-builder
+ (.buildCouchbaseConnection uris bucket username password)))
(defn build
"Create CouchbaseConnectionFactory object from input.
- You can specify keywords arguments: bucket, username, password, uris, and other opts.
- bucket is the bucket name. Default value is defined as @default-bucket and is \"default\".
- username is the bucket username. Default value is defined as @default-username and is a empty string.
+ You can specify keywords arguments: bucket, username, password, uris,
+ and other opts.
+ bucket is the bucket name. Default value is defined
+ as @default-bucket and is \"default\".
+ username is the bucket username.
+ Default value is definedas @default-username and is a empty string.
Currently username is ignored.
- password is the bucket password. Default value is defined as @default-password and is a empty string.
+ password is the bucket password.
+ Default value is defined as @default-password and is a empty string.
uris is a Collection of string uris, ex: [\"http://127.0.0.1:8091/pools\"]
- Other options can be specified for CouchbaseConnectionFactoryBuilder object creation.
- Internally, :failure-mode and :hash-alg must have a value and those default values are
+ Other options can be specified for
+ CouchbaseConnectionFactoryBuilder object creation.
+ Internally, :failure-mode and :hash-alg must have a value
+ and those default values are
:redistribute and :native-hash respectively.
All options can be looked at method-map Var."
[{:keys [^String bucket ^String username ^String password
^Collection uris failure-mode hash-alg] :as opts}]
- (let [bkt (or bucket @default-bucket)
- user (or username @default-username)
- pass (or password @default-password)
+ (let [bkt (or bucket @cb-config/default-bucket)
+ user (or username @cb-config/default-username)
+ pass (or password @cb-config/default-password)
us (if uris
(map str->uri uris)
- (map str->uri @default-uris))
+ (map str->uri @cb-config/default-uris))
failure-mode (or failure-mode :redistribute)
hash-alg (or hash-alg :native-hash)
opts (-> (dissoc opts :bucket :username :password :uris)
View
14 src/couchbase_clj/config.clj
@@ -2,72 +2,60 @@
(def
^{:doc "Default bucket name.
- You can change the value by using swap! or reset!.
Default value is set to \"default\"."}
default-bucket (atom "default"))
(def
^{:doc "Default bucket username.
- You can change the value by using swap! or reset!.
Default value is set to \"\"."}
default-username (atom ""))
(def
^{:doc "Default bucket password.
- You can change the value by using swap! or reset!.
Default value is set to \"\"."}
default-password (atom ""))
(def
- ^{:doc "Default URI sequence collection of one or more servers from the cluster.
- You can change the value by using swap! or reset!.
+ ^{:doc "Default server URIs.
Default value is set to [\"http://127.0.0.1:8091/pools\"]."}
default-uris (atom ["http://127.0.0.1:8091/pools"]))
(def
^{:doc "Default expiry for the data (in seconds).
- You can change the value by using swap! or reset!.
Default value is set to -1."}
default-data-expiry (atom -1))
(def
^{:doc "Default expiry for locking the key (in seconds).
- You can change the value by using swap! or reset!.
Default value is set to 15."}
default-lock-expiry (atom 15))
(def
^{:doc "Default offset for incrementing the data.
- You can change the value by using swap! or reset!.
Default value is set to 1."}
default-inc-offset (atom 1))
(def default-inc-default
^{:doc "Default base value for incrementing the data.
- You can change the value by using swap! or reset!.
Default value is set to 0."}
(atom 0))
(def default-dec-offset
^{:doc "Default offset for Decrementing the data.
- You can change the value by using swap! or reset!.
Default value is set to 1."}
(atom 1))
(def default-dec-default
^{:doc "Default base value for Decrementing the data.
- You can change the value by using swap! or reset!.
Default value is set to 0."}
(atom 0))
(def default-persist
^{:doc "Default value for the persistent type.
- You can change the value by using swap! or reset!.
Default value is set to :master."}
(atom :master))
(def default-replicate
^{:doc "Default value for the replication type.
- You can change the value by using swap! or reset!.
Default value is set to :zero."}
(atom :zero))
View
55 src/couchbase_clj/future.clj
@@ -1,16 +1,11 @@
(ns couchbase-clj.future
- (:import [java.util.concurrent Future]
- [java.util.concurrent TimeUnit]
- [java.util.concurrent TimeoutException]
+ (:import [java.util.concurrent Future TimeUnit TimeoutException]
[net.spy.memcached CASResponse]
- [net.spy.memcached.internal BulkGetFuture]
- [net.spy.memcached.internal GetFuture]
- [net.spy.memcached.internal OperationFuture]
- [com.couchbase.client.internal HttpFuture]
- [com.couchbase.client CouchbaseConnectionFactory])
+ [net.spy.memcached.internal BulkGetFuture GetFuture OperationFuture]
+ [com.couchbase.client CouchbaseConnectionFactory]
+ [com.couchbase.client.internal HttpFuture])
(:refer-clojure :exclude [future-cancel future-cancelled? future-done?])
- (:use [couchbase-clj.config]
- [couchbase-clj.util]))
+ (:require [couchbase-clj.util :as cb-util]))
(defn cas-response
"Get the CASResponse values converted to a corresponding keyword.
@@ -35,23 +30,23 @@
[clj-future]
[clj-future timeout default]
"Deref a JSON string and return the converted Clojure data.
- With no arguments, the default operation timeout (specified when creating client)
- will be set, and if it has reached, the TimeoutException will be thrown.
+ With no arguments, the default operation timeout will be set,
+ and if it has reached, the TimeoutException will be thrown.
The variant taking a timeout will return default and continue processing,
if the timeout (in milliseconds) has reached and catched a TimeoutException.")
(future-get
[clj-future]
[clj-future timeout]
"Get the result data from the Future object.
- With no arguments, the default operation timeout (specified when creating client)
- will be set, and if has reached, the TimeoutException will be thrown.
+ With no arguments, the default operation timeout will be set,
+ and if has reached, the TimeoutException will be thrown.
You can pass a optional timeout argument in milliseconds.")
(future-get-json
[clj-future]
[clj-future timeout]
"Get the result data from the Future object that is a JSON string.
- With no arguments, the default operation timeout (specified when creating client)
- will be set, and if has reached, the OperationTimeoutException will be thrown.
+ With no arguments, the default operation timeout will be set,
+ and if has reached, the OperationTimeoutException will be thrown.
You can pass a optional timeout argument in milliseconds.")
(future-status [clj-future]
"Return the status of the Future object.
@@ -60,7 +55,8 @@
(future-cancelled? [clj-future] "Returns true if future is cancelled?")
(future-done? [clj-future] "Returns true if future is done."))
-(deftype CouchbaseCljBulkGetFuture [^CouchbaseConnectionFactory cf ^BulkGetFuture fut]
+(deftype CouchbaseCljBulkGetFuture
+ [^CouchbaseConnectionFactory cf ^BulkGetFuture fut]
clojure.lang.IDeref
(deref [clj-future]
(let [m (into {} (.get fut (.getOperationTimeout cf) TimeUnit/MILLISECONDS))]
@@ -83,11 +79,11 @@
(deref-json [clj-future]
(let [m (deref clj-future)]
(reduce #(merge %1 {(key %2)
- (read-json (val %2))}) nil m)))
+ (cb-util/read-json (val %2))}) nil m)))
(deref-json [clj-future timeout default]
(let [m (deref clj-future timeout default)]
(reduce #(merge %1 {(key %2)
- (read-json (val %2))}) nil m)))
+ (cb-util/read-json (val %2))}) nil m)))
(future-get [clj-future]
(future-get clj-future (.getOperationTimeout cf)))
(future-get [clj-future timeout]
@@ -98,12 +94,12 @@
(let [m (future-get clj-future)]
(when-not (empty? m)
(reduce #(merge %1 {(key %2)
- (read-json (val %2))}) nil m))))
+ (cb-util/read-json (val %2))}) nil m))))
(future-get-json [clj-future timeout]
(let [m (future-get clj-future timeout)]
(when-not (empty? m)
(reduce #(merge %1 {(key %2)
- (read-json (val %2))}) nil m))))
+ (cb-util/read-json (val %2))}) nil m))))
(future-status [clj-future] (.getStatus ^BulkGetFuture fut))
(future-cancel [clj-future] (.cancel fut true))
(future-cancelled? [clj-future] (.isCancelled fut))
@@ -125,18 +121,23 @@
ICouchbaseCljFuture
(get-future [clj-future] fut)
- (deref-json [clj-future] (read-json (deref clj-future)))
- (deref-json [clj-future timeout default] (read-json (deref clj-future timeout default)))
+ (deref-json [clj-future] (cb-util/read-json (deref clj-future)))
+ (deref-json [clj-future timeout default]
+ (cb-util/read-json (deref clj-future timeout default)))
(future-get [clj-future] (future-get clj-future (.getOperationTimeout cf)))
- (future-get [clj-future timeout] (.get fut ^long timeout TimeUnit/MILLISECONDS))
- (future-get-json [clj-future] (future-get-json clj-future (.getOperationTimeout cf)))
- (future-get-json [clj-future timeout] (read-json (future-get clj-future timeout)))
+ (future-get [clj-future timeout]
+ (.get fut ^long timeout TimeUnit/MILLISECONDS))
+ (future-get-json [clj-future]
+ (future-get-json clj-future (.getOperationTimeout cf)))
+ (future-get-json [clj-future timeout]
+ (cb-util/read-json (future-get clj-future timeout)))
(future-status [clj-future] (.getStatus ^GetFuture fut))
(future-cancel [clj-future] (.cancel fut true))
(future-cancelled? [clj-future] (.isCancelled fut))
(future-done? [clj-future] (.isDone fut)))
-(deftype CouchbaseCljOperationFuture [^CouchbaseConnectionFactory cf ^OperationFuture fut]
+(deftype CouchbaseCljOperationFuture
+ [^CouchbaseConnectionFactory cf ^OperationFuture fut]
clojure.lang.IDeref
(deref [clj-future]
(let [rs (.get fut (.getOperationTimeout cf) TimeUnit/MILLISECONDS)]
View
53 src/couchbase_clj/query.clj
@@ -1,8 +1,6 @@
(ns couchbase-clj.query
(:import [java.lang UnsupportedOperationException]
- [com.couchbase.client.protocol.views Query]
- [com.couchbase.client.protocol.views Stale]
- [com.couchbase.client.protocol.views OnError])
+ [com.couchbase.client.protocol.views Query Stale OnError])
(:refer-clojure :exclude [assoc assoc! get-method str])
(:require [couchbase-clj.config :as cb-config]
[couchbase-clj.util :as cb-util]))
@@ -22,52 +20,62 @@
(defn- on-error
[k]
- (if (= k :stop)
- OnError/STOP
- OnError/CONTINUE))
+ (if (= k :stop) OnError/STOP OnError/CONTINUE))
(defprotocol ICouchbaseCljQuery
(get-query [clj-query] "Get the Query object.")
(reduce? [clj-query] "Returns true if the reduce function will be used.")
- (include-docs? [clj-query] "Returns true if the original JSON docuemnt will be included.")
- (set-include-docs [clj-query b] "Set true to include the original JSON document.")
- (set-desc [clj-query b] "Set true to retrieve the results in descending order.")
+ (include-docs? [clj-query]
+ "Returns true if the original JSON docuemnt will be included.")
+ (set-include-docs [clj-query b]
+ "Set true to include the original JSON document.")
+ (set-desc [clj-query b]
+ "Set true to retrieve the results in descending order.")
(set-startkey-doc-id [clj-query doc-id]
"Set the document ID to start at. doc-id can be a keyword or a string.")
(set-endkey-doc-id [clj-query doc-id]
"Set the document ID to end at. doc-id can be a keyword or a string.")
(set-group [clj-query b] "Set true to reduce to a set of distinct keys.")
(set-group-level [clj-query group-level]
- "Set the group-level as an integer to specify how many items of the keys are used in grouping.")
- (set-inclusive-end [clj-query b] "Set true to include the endkey in the result.")
+ "Set the group-level as an integer to specify how many items of the keys
+ are used in grouping.")
+ (set-inclusive-end [clj-query b]
+ "Set true to include the endkey in the result.")
(set-key [clj-query x]
- "Set the key to fetch only the rows with the given keyword, which data will be converted to a JSON string value.
+ "Set the key to fetch only the rows with the given keyword, which data
+ will be converted to a JSON string value.
+
ex1: (set-key 1000)
ex2: (set-key :a)
ex3: (set-key \"a\")
ex4: (set-key [1 2])")
- (set-limit [clj-query limit] "Set the integer limit to specify the maximum number of rows to return.")
+ (set-limit [clj-query limit] "Set the integer limit to specify
+ the maximum number of rows to return.")
(set-range [clj-query coll]
"Set both startkey and endkey in a sequential collection.
Both start-key and end-key will be converted to a JSON string.
+
ex1: (set-range-start [1000 2000])
ex2: (set-range-start [:a :b])
ex3: (set-range-start [\"a\" \"b\"])
ex4: (set-range-start [[1 2] [3 4])")
(set-range-start [clj-query x]
"Set the start key, which the data will be converted to a JSON string value.
+
ex1: (set-range-start 1000)
ex2: (set-range-start :a)
ex3: (set-range-start \"a\")
ex4: (set-range-start [1 2])")
(set-range-end [clj-query x]
"Set the end key, which the data will be converted to a JSON string value.
+
ex1: (set-range-end 2000)
ex2: (set-range-end :b)
ex3: (set-range-end \"b\")
ex4: (set-range-end [3 4])")
(set-reduce [clj-query b] "Set true to use the reduce function of the view.")
- (set-skip [clj-query docs-to-skip] "Set the number of documents to skip as an integer.")
+ (set-skip [clj-query docs-to-skip] "Set the number of documents
+ to skip as an integer.")
(set-stale [clj-query stl]
"Set the stale option as a keyword.
When stale is equal to:
@@ -77,7 +85,7 @@
:false or boolean false then the stale will be false.
Index will be updated before the query is executed.
- :update-after or other value then the stale will be update_after. (default value)
+ :update-after or other value then the stale will be update_after.
Index will be updated after results are returned.")
(set-on-error [clj-query oe]
"Set the option to decide when an error occurs.
@@ -116,12 +124,16 @@
(set-group [clj-query b] (.setGroup q b))
(set-group-level [clj-query group-level] (.setGroupLevel q group-level))
(set-inclusive-end [clj-query b] (.setInclusiveEnd q b))
- (set-key [clj-query x] (.setKey q (cb-util/write-json x)))
+ (set-key [clj-query x] (.setKey q ^String (cb-util/write-json x)))
(set-limit [clj-query limit] (.setLimit q limit))
(set-range [clj-query coll]
- (.setRange q (cb-util/write-json (first coll)) (cb-util/write-json (second coll))))
- (set-range-start [clj-query x] (.setRangeStart q (cb-util/write-json x)))
- (set-range-end [clj-query x] (.setRangeEnd q (cb-util/write-json x)))
+ (.setRange q
+ ^String (cb-util/write-json (first coll))
+ ^String (cb-util/write-json (second coll))))
+ (set-range-start [clj-query x]
+ (.setRangeStart q ^String (cb-util/write-json x)))
+ (set-range-end [clj-query x]
+ (.setRangeEnd q ^String (cb-util/write-json x)))
(set-reduce [clj-query b] (.setReduce q b))
(set-skip [clj-query docs-to-skip] (.setSkip q docs-to-skip))
(set-stale [clj-query stl] (.setStale q (stale stl)))
@@ -134,7 +146,8 @@
(str [clj-query] (.toString q)))
(def
- ^{:doc "A key/value conversion map of query options to corresponding set functions."}
+ ^{:doc "A key/value conversion map of query options
+ to corresponding set functions."}
method-map
{:desc set-desc
:startkey-doc-id set-startkey-doc-id
View
5 src/couchbase_clj/util.clj
@@ -6,8 +6,7 @@
If data is nil, then nil is returned.
If data is a empty string, then empty string is returned."
[data]
- (when-not (nil? data)
- (json/read-json data true false "")))
+ (when-not (nil? data) (json/read-json data true false "")))
-(def ^{:doc "Wrapper of clojure.data.json/json-str.\n Just for convenience."}
+(def ^{:doc "Wrapper of clojure.data.json/json-str. Just for convenience."}
write-json json/json-str)

0 comments on commit 8b5fee1

Please sign in to comment.