Class GetResult

java.lang.Object
com.couchbase.client.java.kv.GetResult
Direct Known Subclasses:
GetReplicaResult

public class GetResult extends Object
Returned from all kinds of KeyValue Get operation to fetch a document or a subset of it.
Since:
3.0.0
  • Field Details

    • content

      protected final byte[] content
      The encoded content when loading the document.
    • flags

      protected final int flags
      The flags from the kv operation.
    • transcoder

      protected final Transcoder transcoder
      The default transcoder which should be used.
  • Constructor Details

  • Method Details

    • cas

      public long cas()
      Returns the CAS value of document at the time of loading.

      The CAS value is an opaque identifier which is associated with a specific state of the document on the server. It can be used during a subsequent mutation to make sure that the document has not been modified in the meantime.

      If document on the server has been modified in the meantime the SDK will raise a CasMismatchException. In this case the caller is expected to re-do the whole "fetch-modify-update" cycle again. Please refer to the SDK documentation for more information on CAS mismatches and subsequent retries.

    • expiry

      @Deprecated public Optional<Duration> expiry()
      Deprecated.
      If the document has an expiry, returns length of time between the start of the epoch and the point in time when the loaded document expires.

      In other words, the number of seconds in the returned duration is equal to the epoch second when the document expires.

      NOTE: This method always returns an empty Optional unless the Get request was made using GetOptions.withExpiry(boolean) set to true.

    • expiryTime

      public Optional<Instant> expiryTime()
      If the document has an expiry, returns the point in time when the loaded document expires.

      NOTE: This method always returns an empty Optional unless the Get request was made using GetOptions.withExpiry(boolean) set to true.

    • contentAsObject

      public JsonObject contentAsObject()
      Decodes the content of the document into a JsonObject.
    • contentAsArray

      public JsonArray contentAsArray()
      Decodes the content of the document into a JsonArray.
    • contentAs

      public <T> T contentAs(Class<T> target)
      Decodes the content of the document into an instance of the target class.
      Parameters:
      target - the target class to decode the encoded content into.
    • contentAs

      public <T> T contentAs(TypeRef<T> target)
      Decodes the content of the document into an instance of the target type. Example usage:
       List<String> strings = result.contentAs(new TypeRef<List<String>>(){});
       
      Parameters:
      target - the type to decode the encoded content into.
    • contentAsBytes

      @Uncommitted public byte[] contentAsBytes()
      Returns the raw bytes of the document content.
      Returns:
      the document content as a byte array
    • 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