Package com.couchbase.client.java.subdoc
Class DocumentFragment<OPERATION>
java.lang.Object
com.couchbase.client.java.subdoc.DocumentFragment<OPERATION>
@Committed @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.- Since:
- 2.2
- Author:
- Michael Nitschinger, Simon Baslé
-
Constructor Summary
Constructors Constructor Description DocumentFragment(String id, long cas, MutationToken mutationToken, List<SubdocOperationResult<OPERATION>> resultList)
-
Method Summary
Modifier and Type Method 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()
-
Constructor Details
-
DocumentFragment
public DocumentFragment(String id, long cas, MutationToken mutationToken, List<SubdocOperationResult<OPERATION>> resultList)
-
-
Method Details
-
id
- Returns:
- the
id
of the enclosing JSON document in which this fragment belongs.
-
cas
public long cas()The CAS (Create-and-Set) is set by the SDK when mutating, reflecting the new CAS from the enclosing JSON document.- Returns:
- the CAS value related to the enclosing JSON document.
-
mutationToken
- Returns:
- the updated
MutationToken
related to the enclosing JSON document after a mutation.
-
size
public int size()- Returns:
- the number of lookup or mutation specifications that were performed, which is also the number of results.
-
content
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 adequateSubDocumentException
will be thrown (mostly in the case of multiple lookups). If multiple operations targeted the same path, this method only considers the first one (seecontent(int, Class)
to get a result by index).- Parameters:
path
- the path to look for.targetClass
- the expected type of the content, to use in a cast.- Returns:
- the content if one could be retrieved and no error occurred.
-
content
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 adequateSubDocumentException
will be thrown (mostly in the case of multiple lookups). If multiple operations targeted the same path, this method only considers the first one (seecontent(int)
to get a result by index).- Parameters:
path
- the path to look for.- Returns:
- the content if one could be retrieved and no error occurred.
-
content
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 adequateSubDocumentException
will be thrown (mostly in the case of multiple lookups).- Parameters:
index
- the 0-based index of the operation to look for.targetClass
- the expected type of the content, to use in a cast.- Returns:
- the content if one could be retrieved and no error occurred.
-
content
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 adequateSubDocumentException
will be thrown (mostly in the case of multiple lookups).- Parameters:
index
- the 0-based index of the operation to look for.- Returns:
- the content if one could be retrieved and no error occurred.
-
rawContent
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 adequateSubDocumentException
will be thrown (mostly in the case of multiple lookups).- Parameters:
index
- the 0-based index of the operation to look for.- Returns:
- the raw byte array corresponding to the serialized content, if one could be retrieved and no error occurred.
-
rawContent
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 adequateSubDocumentException
will be thrown (mostly in the case of multiple lookups). If multiple operations targeted the same path, this method only considers the first one (seerawContent(int)
to get a result by index).- Parameters:
path
- the path to look for.- Returns:
- the raw byte array corresponding to the serialized content, if one could be retrieved and no error occurred.
-
status
Get the operation status code corresponding to the first operation that targeted the given path. This can be used in place ofcontent(String)
in order to avoid anCouchbaseException
being thrown.- Parameters:
path
- the path of the desired operation.- Returns:
- the status of the operation.
-
status
Get the operation status code corresponding to the n-th operation. This can be used in place ofcontent(int)
in order to avoid anCouchbaseException
being thrown.- Parameters:
index
- the 0-based index of the desired operation.- Returns:
- the status of the operation.
-
exists
Checks whether the given path is part of this result set, eg. an operation targeted it, and the operation executed successfully.- Returns:
- true if that path is part of the successful result set, false in any other case.
-
exists
public boolean exists(int specIndex)Checks whether the given index is part of this result set and the operation was executed successfully.- Returns:
- true if that path is part of the successful result set, false in any other case.
-
toString
-
equals
-
hashCode
public int hashCode()
-