Class DocumentFragment<OPERATION>

java.lang.Object
com.couchbase.client.java.subdoc.DocumentFragment<OPERATION>
Type Parameters:
OPERATION - the broad type of subdocument operation, either Lookup or Mutation.

@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()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • id

      public String 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

      public MutationToken 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

      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).
      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

      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).
      Parameters:
      path - the path to look for.
      Returns:
      the content if one could be retrieved and no error occurred.
    • content

      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).
      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

      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).
      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 adequate SubDocumentException 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

      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).
      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

      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.
      Parameters:
      path - the path of the desired operation.
      Returns:
      the status of the operation.
    • status

      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.
      Parameters:
      index - the 0-based index of the desired operation.
      Returns:
      the status of the operation.
    • exists

      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.
      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

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object