Class AsyncCollection
AsyncCollection
provides basic asynchronous access to all collection APIs.
This type of API provides asynchronous support through the concurrency mechanisms
that ship with Java 8 and later, notably the async CompletableFuture
. It is the
async mechanism with the lowest overhead (best performance) but also comes with less
bells and whistles as the ReactiveCollection
for example.
Most of the time we recommend using the ReactiveCollection
unless you need the
last drop of performance or if you are implementing higher level primitives on top of this
one.
- Since:
- 3.0.0
-
Method Summary
Modifier and TypeMethodDescriptionbinary()
Provides access to the binary APIs, not used for JSON documents.Returns the name of the bucket associated with this collection.core()
Provides access to the underlyingCore
.Provides access to the underlyingClusterEnvironment
.Checks if the given document ID exists on the active partition with default options.exists
(String id, ExistsOptions options) Checks if the given document ID exists on the active partition with custom options.Fetches a full document (or a projection of it) from a collection with default options.get
(String id, GetOptions options) Fetches a full document (or a projection of it) from a collection with custom options.getAllReplicas
(String id) Reads from all available replicas and the active node and returns the results as a list of futures that might complete or fail.getAllReplicas
(String id, GetAllReplicasOptions options) Reads from replicas or the active node based on the options and returns the results as a list of futures that might complete or fail.getAndLock
(String id, Duration lockTime) Fetches a full document and write-locks it for the given duration with default options.getAndLock
(String id, Duration lockTime, GetAndLockOptions options) Fetches a full document and write-locks it for the given duration with custom options.getAndTouch
(String id, Duration expiry) Fetches a full document and resets its expiration time to the value provided with default options.getAndTouch
(String id, Duration expiry, GetAndTouchOptions options) Fetches a full document and resets its expiration time to the value provided with custom options.getAndTouch
(String id, Instant expiry) Fetches a full document and resets its expiration time to the value provided with default options.getAndTouch
(String id, Instant expiry, GetAndTouchOptions options) Fetches a full document and resets its expiration time to the value provided with custom options.getAnyReplica
(String id) Reads all available replicas, and returns the first found.getAnyReplica
(String id, GetAnyReplicaOptions options) Reads all available replicas, and returns the first found.Inserts a full document which does not exist yet with default options.insert
(String id, Object content, InsertOptions options) Inserts a full document which does not exist yet with custom options.lookupIn
(String id, List<LookupInSpec> specs) Performs lookups to document fragments with default options.lookupIn
(String id, List<LookupInSpec> specs, LookupInOptions options) Performs lookups to document fragments with custom options.lookupInAllReplicas
(String id, List<LookupInSpec> specs) Reads from replicas or the active node based on the options and returns the results as a list of futures that might complete or fail.lookupInAllReplicas
(String id, List<LookupInSpec> specs, LookupInAllReplicasOptions options) Reads from replicas or the active node based on the options and returns the results as a list of futures that might complete or fail.lookupInAnyReplica
(String id, List<LookupInSpec> specs) Reads all available replicas, and returns the first found.lookupInAnyReplica
(String id, List<LookupInSpec> specs, LookupInAnyReplicaOptions options) Reads all available replicas, and returns the first found.mutateIn
(String id, List<MutateInSpec> specs) Performs mutations to document fragments with default options.mutateIn
(String id, List<MutateInSpec> specs, MutateInOptions options) Performs mutations to document fragments with custom options.name()
The name of the collection in use.Removes a Document from a collection with default options.remove
(String id, RemoveOptions options) Removes a Document from a collection with custom options.Replaces a full document which already exists with default options.replace
(String id, Object content, ReplaceOptions options) Replaces a full document which already exists with custom options.Returns a stream ofScanResults
performing a Key-Value range scan with default options.scan
(ScanType scanType, ScanOptions options) Returns a stream ofScanResults
performing a Key-Value range scan with custom options.Returns the name of the scope associated with this collection.Updates the expiry of the document with the given id with default options.touch
(String id, Duration expiry, TouchOptions options) Updates the expiry of the document with the given id with custom options.Updates the expiry of the document with the given id with default options.touch
(String id, Instant expiry, TouchOptions options) Updates the expiry of the document with the given id with custom options.Unlocks a document if it has been locked previously, with default options.unlock
(String id, long cas, UnlockOptions options) Unlocks a document if it has been locked previously, with custom options.Upserts a full document which might or might not exist yet with default options.upsert
(String id, Object content, UpsertOptions options) Upserts a full document which might or might not exist yet with custom options.
-
Method Details
-
core
Provides access to the underlyingCore
. -
queryIndexes
-
environment
Provides access to the underlyingClusterEnvironment
. -
name
The name of the collection in use.- Returns:
- the name of the collection.
-
bucketName
Returns the name of the bucket associated with this collection. -
scopeName
Returns the name of the scope associated with this collection. -
binary
Provides access to the binary APIs, not used for JSON documents.- Returns:
- the
AsyncBinaryCollection
.
-
get
Fetches a full document (or a projection of it) from a collection with default options.- Parameters:
id
- the document id which is used to uniquely identify it.- Returns:
- a
CompletableFuture
indicating once loaded or failed.
-
get
Fetches a full document (or a projection of it) from a collection with custom options.- Parameters:
id
- the document id which is used to uniquely identify it.options
- custom options to change the default behavior.- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
getAndLock
Fetches a full document and write-locks it for the given duration with default options.Note that the client does not enforce an upper limit on the
Duration
lockTime. The maximum lock time by default on the server is 30 seconds. Any value larger than 30 seconds will be capped down by the server to the default lock time, which is 15 seconds unless modified on the server side.- Parameters:
id
- the document id which is used to uniquely identify it.lockTime
- how long to write-lock the document for (any duration > 30s will be capped to server default of 15s).- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
getAndLock
public CompletableFuture<GetResult> getAndLock(String id, Duration lockTime, GetAndLockOptions options) Fetches a full document and write-locks it for the given duration with custom options.Note that the client does not enforce an upper limit on the
Duration
lockTime. The maximum lock time by default on the server is 30 seconds. Any value larger than 30 seconds will be capped down by the server to the default lock time, which is 15 seconds unless modified on the server side.- Parameters:
id
- the document id which is used to uniquely identify it.lockTime
- how long to write-lock the document for (any duration > 30s will be capped to server default of 15s).options
- custom options to change the default behavior.- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
getAndTouch
Fetches a full document and resets its expiration time to the value provided with default options.- Parameters:
id
- the document id which is used to uniquely identify it.expiry
- the new expiration time for the document.- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
getAndTouch
public CompletableFuture<GetResult> getAndTouch(String id, Duration expiry, GetAndTouchOptions options) Fetches a full document and resets its expiration time to the value provided with custom options.- Parameters:
id
- the document id which is used to uniquely identify it.expiry
- the new expiration time for the document.options
- custom options to change the default behavior.- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
getAndTouch
Fetches a full document and resets its expiration time to the value provided with default options.- Parameters:
id
- the document id which is used to uniquely identify it.expiry
- the new expiration time for the document.- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
getAndTouch
public CompletableFuture<GetResult> getAndTouch(String id, Instant expiry, GetAndTouchOptions options) Fetches a full document and resets its expiration time to the value provided with custom options.- Parameters:
id
- the document id which is used to uniquely identify it.expiry
- the new expiration time for the document.options
- custom options to change the default behavior.- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
getAllReplicas
Reads from all available replicas and the active node and returns the results as a list of futures that might complete or fail.- Parameters:
id
- the document id.- Returns:
- a list of results from the active and the replica.
-
getAllReplicas
public CompletableFuture<List<CompletableFuture<GetReplicaResult>>> getAllReplicas(String id, GetAllReplicasOptions options) Reads from replicas or the active node based on the options and returns the results as a list of futures that might complete or fail.- Parameters:
id
- the document id.- Returns:
- a list of results from the active and the replica.
-
getAnyReplica
Reads all available replicas, and returns the first found.- Parameters:
id
- the document id.- Returns:
- a future containing the first available replica.
-
getAnyReplica
Reads all available replicas, and returns the first found.- Parameters:
id
- the document id.options
- the custom options.- Returns:
- a future containing the first available replica.
-
exists
Checks if the given document ID exists on the active partition with default options.- Parameters:
id
- the document ID- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
exists
Checks if the given document ID exists on the active partition with custom options.- Parameters:
id
- the document IDoptions
- to modify the default behavior- Returns:
- a
CompletableFuture
completing once loaded or failed.
-
remove
Removes a Document from a collection with default options.- Parameters:
id
- the id of the document to remove.- Returns:
- a
CompletableFuture
completing once removed or failed.
-
remove
Removes a Document from a collection with custom options.- Parameters:
id
- the id of the document to remove.options
- custom options to change the default behavior.- Returns:
- a
CompletableFuture
completing once removed or failed.
-
insert
Inserts a full document which does not exist yet with default options.- Parameters:
id
- the document id to insert.content
- the document content to insert.- Returns:
- a
CompletableFuture
completing once inserted or failed.
-
insert
Inserts a full document which does not exist yet with custom options.- Parameters:
id
- the document id to insert.content
- the document content to insert.options
- custom options to customize the insert behavior.- Returns:
- a
CompletableFuture
completing once inserted or failed.
-
upsert
Upserts a full document which might or might not exist yet with default options.- Parameters:
id
- the document id to upsert.content
- the document content to upsert.- Returns:
- a
CompletableFuture
completing once upserted or failed.
-
upsert
Upserts a full document which might or might not exist yet with custom options.- Parameters:
id
- the document id to upsert.content
- the document content to upsert.options
- custom options to customize the upsert behavior.- Returns:
- a
CompletableFuture
completing once upserted or failed.
-
replace
Replaces a full document which already exists with default options.- Parameters:
id
- the document id to replace.content
- the document content to replace.- Returns:
- a
CompletableFuture
completing once replaced or failed.
-
replace
Replaces a full document which already exists with custom options.- Parameters:
id
- the document id to replace.content
- the document content to replace.options
- custom options to customize the replace behavior.- Returns:
- a
CompletableFuture
completing once replaced or failed.
-
touch
Updates the expiry of the document with the given id with default options.- Parameters:
id
- the id of the document to update.expiry
- the new expiry for the document.- Returns:
- a
MutationResult
once the operation completes.
-
touch
Updates the expiry of the document with the given id with custom options.- Parameters:
id
- the id of the document to update.expiry
- the new expiry for the document.options
- the custom options.- Returns:
- a
MutationResult
once the operation completes.
-
touch
Updates the expiry of the document with the given id with default options.- Parameters:
id
- the id of the document to update.expiry
- the new expiry for the document.- Returns:
- a
MutationResult
once the operation completes.
-
touch
Updates the expiry of the document with the given id with custom options.- Parameters:
id
- the id of the document to update.expiry
- the new expiry for the document.options
- the custom options.- Returns:
- a
MutationResult
once the operation completes.
-
unlock
Unlocks a document if it has been locked previously, with default options.- Parameters:
id
- the id of the document.cas
- the CAS value which is needed to unlock it.- Returns:
- the future which completes once a response has been received.
-
unlock
Unlocks a document if it has been locked previously, with custom options.- Parameters:
id
- the id of the document.cas
- the CAS value which is needed to unlock it.options
- the options to customize.- Returns:
- the future which completes once a response has been received.
-
lookupIn
Performs lookups to document fragments with default options.- Parameters:
id
- the outer document ID.specs
- the spec which specifies the type of lookups to perform.- Returns:
- the
LookupInResult
once the lookup has been performed or failed.
-
lookupIn
public CompletableFuture<LookupInResult> lookupIn(String id, List<LookupInSpec> specs, LookupInOptions options) Performs lookups to document fragments with custom options.- Parameters:
id
- the outer document ID.specs
- the spec which specifies the type of lookups to perform.options
- custom options to modify the lookup options.- Returns:
- the
LookupInResult
once the lookup has been performed or failed.
-
lookupInAllReplicas
@SinceCouchbase("7.6") public CompletableFuture<List<CompletableFuture<LookupInReplicaResult>>> lookupInAllReplicas(String id, List<LookupInSpec> specs) Reads from replicas or the active node based on the options and returns the results as a list of futures that might complete or fail.- Parameters:
id
- the document id.specs
- the spec which specifies the type of lookups to perform.- Returns:
- a list of results from the active and the replica.
-
lookupInAllReplicas
@SinceCouchbase("7.6") public CompletableFuture<List<CompletableFuture<LookupInReplicaResult>>> lookupInAllReplicas(String id, List<LookupInSpec> specs, LookupInAllReplicasOptions options) Reads from replicas or the active node based on the options and returns the results as a list of futures that might complete or fail.- Parameters:
id
- the document id.specs
- the spec which specifies the type of lookups to perform.- Returns:
- a list of results from the active and the replica.
-
lookupInAnyReplica
@SinceCouchbase("7.6") public CompletableFuture<LookupInReplicaResult> lookupInAnyReplica(String id, List<LookupInSpec> specs) Reads all available replicas, and returns the first found.- Parameters:
id
- the document id.specs
- the spec which specifies the type of lookups to perform.- Returns:
- a future containing the first available replica.
-
lookupInAnyReplica
@SinceCouchbase("7.6") public CompletableFuture<LookupInReplicaResult> lookupInAnyReplica(String id, List<LookupInSpec> specs, LookupInAnyReplicaOptions options) Reads all available replicas, and returns the first found.- Parameters:
id
- the document id.specs
- the spec which specifies the type of lookups to perform.options
- the custom options.- Returns:
- a future containing the first available replica.
-
mutateIn
Performs mutations to document fragments with default options.- Parameters:
id
- the outer document ID.specs
- the spec which specifies the type of mutations to perform.- Returns:
- the
MutateInResult
once the mutation has been performed or failed.
-
mutateIn
public CompletableFuture<MutateInResult> mutateIn(String id, List<MutateInSpec> specs, MutateInOptions options) Performs mutations to document fragments with custom options.- Parameters:
id
- the outer document ID.specs
- the spec which specifies the type of mutations to perform.options
- custom options to modify the mutation options.- Returns:
- the
MutateInResult
once the mutation has been performed or failed.
-
scan
Returns a stream ofScanResults
performing a Key-Value range scan with default options.CAVEAT: This method is suitable for use cases that require relatively low concurrency and tolerate relatively high latency. If your application does many scans at once, or requires low latency results, we recommend using SQL++ (with a primary index on the collection) instead.
- Parameters:
scanType
- the type or range scan to perform.- Returns:
- a CompletableFuture of a list of
ScanResults
(potentially empty). - Throws:
TimeoutException
- if the operation times out before getting a result.CouchbaseException
- for all other error reasons (acts as a base type and catch-all).
-
scan
@SinceCouchbase("7.6") public CompletableFuture<List<ScanResult>> scan(ScanType scanType, ScanOptions options) Returns a stream ofScanResults
performing a Key-Value range scan with custom options.CAVEAT: This method is suitable for use cases that require relatively low concurrency and tolerate relatively high latency. If your application does many scans at once, or requires low latency results, we recommend using SQL++ (with a primary index on the collection) instead.
- Parameters:
scanType
- the type or range scan to perform.options
- aScanOptions
to customize the behavior of the scan operation.- Returns:
- a CompletableFuture of a list of
ScanResults
(potentially empty). - Throws:
TimeoutException
- if the operation times out before getting a result.CouchbaseException
- for all other error reasons (acts as a base type and catch-all).
-