@InterfaceStability.Committed @InterfaceAudience.Public public class DocumentFragment<OPERATION> extends Object
A fragment of a JSON Document
, that is to say one or several JSON values from the document (including String, JsonObject
, JsonArray
, etc…), as returned and used in the sub-document API.
Constructor and Description |
---|
DocumentFragment(String id,
long cas,
MutationToken mutationToken,
List<SubdocOperationResult<OPERATION>> resultList) |
Modifier and Type | Method and Description |
---|---|
long |
cas()
The CAS (Create-and-Set) is set by the SDK when mutating, reflecting the new CAS from the enclosing JSON document.
|
Object |
content(int index)
Attempt to get the value corresponding to the n-th operation, as an Object.
|
<T> T |
content(int index,
Class<T> targetClass)
Attempt to get the value corresponding to the n-th operation, casting it as a specific class.
|
Object |
content(String path)
Attempt to get the value corresponding to the first operation that targeted the given path, as an Object.
|
<T> T |
content(String path,
Class<T> targetClass)
Attempt to get the value corresponding to the first operation that targeted the given path, casted to a specific class.
|
boolean |
equals(Object o) |
boolean |
exists(int specIndex)
Checks whether the given index is part of this result set and the operation was executed successfully.
|
boolean |
exists(String path)
Checks whether the given path is part of this result set, eg.
|
int |
hashCode() |
String |
id() |
MutationToken |
mutationToken() |
byte[] |
rawContent(int index)
Attempt to get the serialized form of the value corresponding to the n-th operation, as a raw array of bytes.
|
byte[] |
rawContent(String path)
Attempt to get the serialized form of the value corresponding to the first operation that targeted the given path, as an array of bytes.
|
int |
size() |
ResponseStatus |
status(int index)
Get the operation status code corresponding to the n-th operation.
|
ResponseStatus |
status(String path)
Get the operation status code corresponding to the first operation that targeted the given path.
|
String |
toString() |
public DocumentFragment(String id, long cas, MutationToken mutationToken, List<SubdocOperationResult<OPERATION>> resultList)
public String id()
id
of the enclosing JSON document in which this fragment belongs.public long cas()
The CAS (Create-and-Set) is set by the SDK when mutating, reflecting the new CAS from the enclosing JSON document.
public MutationToken mutationToken()
MutationToken
related to the enclosing JSON document after a mutation.public int size()
public <T> T content(String path, Class<T> targetClass)
Attempt to get the value corresponding to the first operation that targeted the given path, casted to a specific class. If the operation was successful, the value will be returned. Otherwise the adequate SubDocumentException
will be thrown (mostly in the case of multiple lookups).
If multiple operations targeted the same path, this method only considers the first one (see content(int, Class)
to get a result by index).
path
- the path to look for.targetClass
- the expected type of the content, to use in a cast.public Object content(String path)
Attempt to get the value corresponding to the first operation that targeted the given path, as an Object. If the operation was successful, the value will be returned. Otherwise the adequate SubDocumentException
will be thrown (mostly in the case of multiple lookups).
If multiple operations targeted the same path, this method only considers the first one (see content(int)
to get a result by index).
path
- the path to look for.public <T> T content(int index, Class<T> targetClass)
Attempt to get the value corresponding to the n-th operation, casting it as a specific class. If the operation was successful, the value will be returned. Otherwise the adequate SubDocumentException
will be thrown (mostly in the case of multiple lookups).
index
- the 0-based index of the operation to look for.targetClass
- the expected type of the content, to use in a cast.public Object content(int index)
Attempt to get the value corresponding to the n-th operation, as an Object. If the operation was successful, the value will be returned. Otherwise the adequate SubDocumentException
will be thrown (mostly in the case of multiple lookups).
index
- the 0-based index of the operation to look for.public byte[] rawContent(int index)
Attempt to get the serialized form of the value corresponding to the n-th operation, as a raw array of bytes. If the operation was successful, the value will be returned. Otherwise the adequate SubDocumentException
will be thrown (mostly in the case of multiple lookups).
index
- the 0-based index of the operation to look for.public byte[] rawContent(String path)
Attempt to get the serialized form of the value corresponding to the first operation that targeted the given path, as an array of bytes.
If the operation was successful, the value will be returned. Otherwise the adequate SubDocumentException
will be thrown (mostly in the case of multiple lookups).
If multiple operations targeted the same path, this method only considers the first one (see rawContent(int)
to get a result by index).
path
- the path to look for.public ResponseStatus status(String path)
Get the operation status code corresponding to the first operation that targeted the given path.
This can be used in place of content(String)
in order to avoid an CouchbaseException
being thrown.
path
- the path of the desired operation.public ResponseStatus status(int index)
Get the operation status code corresponding to the n-th operation.
This can be used in place of content(int)
in order to avoid an CouchbaseException
being thrown.
index
- the 0-based index of the desired operation.public boolean exists(String path)
Checks whether the given path is part of this result set, eg. an operation targeted it, and the operation executed successfully.
public boolean exists(int specIndex)
Checks whether the given index is part of this result set and the operation was executed successfully.
Copyright © 2015 Couchbase, Inc.