Package com.couchbase.client.java
Class Collection
- java.lang.Object
-
- com.couchbase.client.java.Collection
-
public class Collection extends Object
TheCollection
provides blocking, synchronous access to all collection APIs.If asynchronous access is needed, we recommend looking at the
ReactiveCollection
and if the last drop of performance is needed theAsyncCollection
. This blocking API itself is just a small layer on top of theAsyncCollection
which blocks the current thread until the request completes with a response.- Since:
- 3.0.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncCollection
async()
Provides access to the underlyingAsyncCollection
.BinaryCollection
binary()
Provides access to the binary APIs, not used for JSON documents.String
bucketName()
Returns the name of the bucket associated with this collection.Core
core()
Provides access to the underlyingCore
.ClusterEnvironment
environment()
Provides access to the underlyingClusterEnvironment
.ExistsResult
exists(String id)
Checks if the given document ID exists on the active partition with default options.ExistsResult
exists(String id, ExistsOptions options)
Checks if the given document ID exists on the active partition with custom options.GetResult
get(String id)
Fetches a full Document from a collection with default options.GetResult
get(String id, GetOptions options)
Fetches a full Document from a collection with custom options.GetResult
getAndLock(String id)
Fetches a full document and write-locks it for the given duration with default options.GetResult
getAndLock(String id, GetAndLockOptions options)
Fetches a full document and write-locks it for the given duration with custom options.GetResult
getAndTouch(String id, Duration expiration)
Fetches a full document and resets its expiration time to the value provided with default options.GetResult
getAndTouch(String id, Duration expiration, GetAndTouchOptions options)
Fetches a full document and resets its expiration time to the value provided with custom options.Stream<GetResult>
getFromReplica(String id)
Reads from all available replicas and the active node and returns the results as a stream.Stream<GetResult>
getFromReplica(String id, GetFromReplicaOptions options)
Reads all available or one replica and returns the results as a stream.MutationResult
insert(String id, Object content)
Inserts a full document which does not exist yet with default options.MutationResult
insert(String id, Object content, InsertOptions options)
Inserts a full document which does not exist yet with custom options.LookupInResult
lookupIn(String id, List<LookupInSpec> specs)
Performs lookups to document fragments with default options.LookupInResult
lookupIn(String id, List<LookupInSpec> specs, LookupInOptions options)
Performs lookups to document fragments with custom options.MutateInResult
mutateIn(String id, List<MutateInSpec> specs)
Performs mutations to document fragments with default options.MutateInResult
mutateIn(String id, List<MutateInSpec> specs, MutateInOptions options)
Performs mutations to document fragments with custom options.String
name()
Returns the name of this collection.ReactiveCollection
reactive()
Provides access to the underlyingReactiveCollection
.MutationResult
remove(String id)
Removes a Document from a collection with default options.MutationResult
remove(String id, RemoveOptions options)
Removes a Document from a collection with custom options.MutationResult
replace(String id, Object content)
Replaces a full document which already exists with default options.MutationResult
replace(String id, Object content, ReplaceOptions options)
Replaces a full document which already exists with custom options.String
scopeName()
Returns the name of the scope associated with this collection.MutationResult
touch(String id, Duration expiry)
Updates the expiry of the document with the given id with default options.MutationResult
touch(String id, Duration expiry, TouchOptions options)
Updates the expiry of the document with the given id with custom options.void
unlock(String id, long cas)
Unlocks a document if it has been locked previously, with default options.void
unlock(String id, long cas, UnlockOptions options)
Unlocks a document if it has been locked previously, with custom options.MutationResult
upsert(String id, Object content)
Upserts a full document which might or might not exist yet with default options.MutationResult
upsert(String id, Object content, UpsertOptions options)
Upserts a full document which might or might not exist yet with custom options.
-
-
-
Method Detail
-
async
public AsyncCollection async()
Provides access to the underlyingAsyncCollection
.- Returns:
- returns the underlying
AsyncCollection
.
-
reactive
public ReactiveCollection reactive()
Provides access to the underlyingReactiveCollection
.- Returns:
- returns the underlying
ReactiveCollection
.
-
name
public String name()
Returns the name of this collection.
-
bucketName
public String bucketName()
Returns the name of the bucket associated with this collection.
-
scopeName
public String scopeName()
Returns the name of the scope associated with this collection.
-
environment
public ClusterEnvironment environment()
Provides access to the underlyingClusterEnvironment
.
-
binary
public BinaryCollection binary()
Provides access to the binary APIs, not used for JSON documents.- Returns:
- the
BinaryCollection
.
-
get
public GetResult get(String id)
Fetches a full Document from a collection with default options.- Parameters:
id
- the document id which is used to uniquely identify it.- Returns:
- a
GetResult
once the document has been loaded.
-
get
public GetResult get(String id, GetOptions options)
Fetches a full Document 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
GetResult
once the document has been loaded.
-
getAndLock
public GetResult getAndLock(String id)
Fetches a full document and write-locks it for the given duration with default options.- Parameters:
id
- the document id which is used to uniquely identify it.- Returns:
- a
GetResult
once the document has been loaded.
-
getAndLock
public GetResult getAndLock(String id, GetAndLockOptions options)
Fetches a full document and write-locks it for the given duration 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
GetResult
once the document has been loaded.
-
getAndTouch
public GetResult getAndTouch(String id, Duration expiration)
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.expiration
- the new expiration time for the document.- Returns:
- a
GetResult
completing once loaded or failed.
-
getAndTouch
public GetResult getAndTouch(String id, Duration expiration, 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.expiration
- the new expiration time for the document.options
- custom options to change the default behavior.- Returns:
- a
GetResult
completing once loaded or failed.
-
getFromReplica
public Stream<GetResult> getFromReplica(String id)
Reads from all available replicas and the active node and returns the results as a stream.Note that individual errors are ignored, so you can think of this API as a best effort approach which explicitly emphasises availability over consistency.
- Parameters:
id
- the document id.- Returns:
- a stream of results from the active and the replica.
-
getFromReplica
public Stream<GetResult> getFromReplica(String id, GetFromReplicaOptions options)
Reads all available or one replica and returns the results as a stream.By default all available replicas and the active node will be asked and returned as an async stream. If configured differently in the options
- Parameters:
id
- the document id.options
- the custom options.- Returns:
- a stream of results from the active and the replica depending on the options.
-
exists
public ExistsResult exists(String id)
Checks if the given document ID exists on the active partition with default options.- Parameters:
id
- the document ID- Returns:
- a
ExistsResult
completing once loaded or failed.
-
exists
public ExistsResult exists(String id, ExistsOptions options)
Checks if the given document ID exists on the active partition with custom options.- Parameters:
id
- the document ID- Returns:
- a
ExistsResult
completing once loaded or failed.
-
remove
public MutationResult remove(String id)
Removes a Document from a collection with default options.- Parameters:
id
- the id of the document to remove.- Returns:
- a
MutationResult
once removed.
-
remove
public MutationResult remove(String id, RemoveOptions options)
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
MutationResult
once removed.
-
insert
public MutationResult insert(String id, Object content)
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
MutationResult
once inserted.
-
insert
public MutationResult insert(String id, Object content, InsertOptions options)
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
MutationResult
once inserted.
-
upsert
public MutationResult upsert(String id, Object content)
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
MutationResult
once upserted.
-
upsert
public MutationResult upsert(String id, Object content, UpsertOptions options)
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
MutationResult
once upserted.
-
replace
public MutationResult replace(String id, Object content)
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
MutationResult
once replaced.
-
replace
public MutationResult replace(String id, Object content, ReplaceOptions options)
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
MutationResult
once replaced.
-
touch
public MutationResult touch(String id, Duration expiry)
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
public MutationResult touch(String id, Duration expiry, TouchOptions options)
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
public void unlock(String id, long cas)
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.
-
unlock
public void unlock(String id, long cas, UnlockOptions options)
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.
-
lookupIn
public LookupInResult lookupIn(String id, List<LookupInSpec> specs)
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 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.
-
mutateIn
public MutateInResult mutateIn(String id, List<MutateInSpec> specs)
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 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.
-
-