@InterfaceStability.Experimental @InterfaceAudience.Public public class MutateInBuilder extends Object
A builder for subdocument mutations. In order to perform the final set of operations, use the doMutate()
method. Operations are performed synchronously (see AsyncMutateInBuilder
for an asynchronous version).
Instances of this builder should be obtained through Bucket.mutateIn(String)
rather than directly constructed.
Constructor and Description |
---|
MutateInBuilder(AsyncMutateInBuilder asyncBuilder,
long defaultTimeout,
TimeUnit defaultTimeUnit)
Instances of this builder should be obtained through
Bucket.mutateIn(String) rather than directly constructed. |
Modifier and Type | Method and Description |
---|---|
<T> MutateInBuilder |
addUnique(String path,
T value,
boolean createParents)
Insert a value in an existing array only if the value isn’t already contained in the array (by way of string comparison).
|
<T> MutateInBuilder |
arrayInsert(String path,
T value)
Insert into an existing array at a specific position (denoted in the path, eg.
|
MutateInBuilder |
counter(String path,
long delta,
boolean createParents)
Increment/decrement a numerical fragment in a JSON document.
|
DocumentFragment<Mutation> |
doMutate()
Perform several
mutation operations inside a single existing JSON document , with the default key/value timeout. |
DocumentFragment<Mutation> |
doMutate(long timeout,
TimeUnit timeUnit)
Perform several
mutation operations inside a single existing JSON document , with a specific timeout. |
<T> MutateInBuilder |
insert(String path,
T fragment,
boolean createParents)
Insert a fragment provided the last element of the path doesn’t exists.
|
<T> MutateInBuilder |
pushBack(String path,
T value,
boolean createParents)
Push to the back of an existing array, appending the value.
|
<T> MutateInBuilder |
pushFront(String path,
T value,
boolean createParents)
Push to the front of an existing array, prepending the value.
|
<T> MutateInBuilder |
remove(String path)
Remove an entry in a JSON document (scalar, array element, dictionary entry, whole array or dictionary, depending on the path).
|
<T> MutateInBuilder |
replace(String path,
T fragment)
Replace an existing value by the given fragment.
|
String |
toString() |
<T> MutateInBuilder |
upsert(String path,
T fragment,
boolean createParents)
Insert a fragment, replacing the old value if the path exists.
|
MutateInBuilder |
withCas(long cas)
Apply the whole mutation using optimistic locking, checking against the provided CAS value.
|
MutateInBuilder |
withDurability(PersistTo persistTo)
Set a persistence durability constraint for the whole mutation.
|
MutateInBuilder |
withDurability(PersistTo persistTo,
ReplicateTo replicateTo)
Set both a persistence and replication durability constraints for the whole mutation.
|
MutateInBuilder |
withDurability(ReplicateTo replicateTo)
Set a replication durability constraint for the whole mutation.
|
MutateInBuilder |
withExpiry(int expiry)
Change the expiry of the enclosing document as part of the mutation.
|
@InterfaceAudience.Private public MutateInBuilder(AsyncMutateInBuilder asyncBuilder, long defaultTimeout, TimeUnit defaultTimeUnit)
Instances of this builder should be obtained through Bucket.mutateIn(String)
rather than directly constructed.
public DocumentFragment<Mutation> doMutate()
Perform several mutation
operations inside a single existing JSON document
, with the default key/value timeout. The list of mutations and paths to mutate in the JSON is added through builder methods like arrayInsert(String, Object)
.
Multi-mutations are applied as a whole, atomically at the document level. That means that if one of the mutations fails, none of the mutations are applied. Otherwise, all mutations can be considered successful and the whole operation will receive a DocumentFragment
with the updated cas (and optionally MutationToken
).
The subdocument API has the benefit of only transmitting the fragment of the document you want to mutate on the wire, instead of the whole document.
This operation throws under the following notable error conditions:
DocumentDoesNotExistException
DocumentNotJsonException
IllegalArgumentException
TranscodingException
MultiMutationException
DurabilityException
CASMismatchException
When receiving a MultiMutationException
, one can inspect the exception to find the zero-based index and error status code
of the first failing Mutation
. Subsequent mutations may have also failed had they been attempted, but a single spec failing causes the whole operation to be cancelled.
Other top-level error conditions are similar to those encountered during a document-level Bucket.replace(Document)
.
DocumentFragment
(if successful) containing updated cas metadata. Note that some individual results could also bear a value, like counter operations.public DocumentFragment<Mutation> doMutate(long timeout, TimeUnit timeUnit)
Perform several mutation
operations inside a single existing JSON document
, with a specific timeout. The list of mutations and paths to mutate in the JSON is added through builder methods like arrayInsert(String, Object)
.
Multi-mutations are applied as a whole, atomically at the document level. That means that if one of the mutations fails, none of the mutations are applied. Otherwise, all mutations can be considered successful and the whole operation will receive a DocumentFragment
with the updated cas (and optionally MutationToken
).
The subdocument API has the benefit of only transmitting the fragment of the document you want to mutate on the wire, instead of the whole document.
This operation throws under the following most notable error conditions:
DocumentDoesNotExistException
DocumentNotJsonException
IllegalArgumentException
TranscodingException
MultiMutationException
DurabilityException
CASMismatchException
//TODO list all subdoc level errors hereWhen receiving a MultiMutationException
, one can inspect the exception to find the zero-based index and error status code
of the first failing Mutation
. Subsequent mutations may have also failed had they been attempted, but a single spec failing causes the whole operation to be cancelled.
Other top-level error conditions are similar to those encountered during a document-level Bucket.replace(Document)
.
timeout
- the specific timeout to apply for the operation.timeUnit
- the time unit for the timeout.DocumentFragment
(if successful) containing updated cas metadata. Note that some individual results could also bear a value, like counter operations.public MutateInBuilder withExpiry(int expiry)
Change the expiry of the enclosing document as part of the mutation.
expiry
- the new expiry to apply (or 0 to avoid changing the expiry)public MutateInBuilder withCas(long cas)
Apply the whole mutation using optimistic locking, checking against the provided CAS value.
cas
- the CAS to compare the enclosing document to.public MutateInBuilder withDurability(PersistTo persistTo)
Set a persistence durability constraint for the whole mutation.
persistTo
- the persistence durability constraint to observe.public MutateInBuilder withDurability(ReplicateTo replicateTo)
Set a replication durability constraint for the whole mutation.
replicateTo
- the replication durability constraint to observe.public MutateInBuilder withDurability(PersistTo persistTo, ReplicateTo replicateTo)
Set both a persistence and replication durability constraints for the whole mutation.
persistTo
- the persistence durability constraint to observe.replicateTo
- the replication durability constraint to observe.public <T> MutateInBuilder replace(String path, T fragment)
Replace an existing value by the given fragment.
path
- the path where the value to replace is.fragment
- the new value.public <T> MutateInBuilder insert(String path, T fragment, boolean createParents)
Insert a fragment provided the last element of the path doesn’t exists.
path
- the path where to insert a new dictionary value.fragment
- the new dictionary value to insert.createParents
- true to create missing intermediary nodes.public <T> MutateInBuilder upsert(String path, T fragment, boolean createParents)
Insert a fragment, replacing the old value if the path exists.
path
- the path where to insert (or replace) a dictionary value.fragment
- the new dictionary value to be applied.createParents
- true to create missing intermediary nodes.public <T> MutateInBuilder remove(String path)
Remove an entry in a JSON document (scalar, array element, dictionary entry, whole array or dictionary, depending on the path).
path
- the path to remove.public MutateInBuilder counter(String path, long delta, boolean createParents)
Increment/decrement a numerical fragment in a JSON document. If the value (last element of the path) doesn’t exist the counter is created and takes the value of the delta.
path
- the path to the counter (must be containing a number).delta
- the value to increment or decrement the counter by.createParents
- true to create missing intermediary nodes.public <T> MutateInBuilder pushFront(String path, T value, boolean createParents)
Push to the front of an existing array, prepending the value.
path
- the path of the array.value
- the value to insert at the front of the array.createParents
- true to create missing intermediary nodes.public <T> MutateInBuilder pushBack(String path, T value, boolean createParents)
Push to the back of an existing array, appending the value.
path
- the path of the array.value
- the value to insert at the back of the array.createParents
- true to create missing intermediary nodes.public <T> MutateInBuilder arrayInsert(String path, T value)
Insert into an existing array at a specific position (denoted in the path, eg. “sub.array[2]”).
path
- the path (including array position) where to insert the value.value
- the value to insert in the array.public <T> MutateInBuilder addUnique(String path, T value, boolean createParents)
Insert a value in an existing array only if the value isn’t already contained in the array (by way of string comparison).
path
- the path to mutate in the JSON.value
- the value to insert.createParents
- true to create missing intermediary nodes.Copyright © 2015 Couchbase, Inc.