Class ScanResult

java.lang.Object
com.couchbase.client.java.kv.ScanResult

@Volatile public class ScanResult extends Object
Returned for each found item in a KV Range Scan operation.
  • Constructor Details

    • ScanResult

      @Internal public ScanResult(boolean idOnly, String id, byte[] content, int flags, long cas, Optional<Instant> expiry, Transcoder transcoder)
      Creates a new GetResult.
      Parameters:
      cas - the cas from the doc.
      expiry - the expiry if fetched from the doc.
  • Method Details

    • id

      public String id()
      Returns the ID of the document.
      Returns:
      the ID of the document.
    • idOnly

      public boolean idOnly()
      Returns true if this result came from a scan where ScanOptions.idsOnly(boolean) was set to true.

      If true, attempting to access the document content or metadata will throw UnsupportedOperationException.

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

      Throws:
      NoSuchElementException - if this result came from a scan where ScanOptions.idsOnly(boolean) was set to true. See idOnly().
    • expiryTime

      public Optional<Instant> expiryTime()
      If the document has an expiry, returns the point in time when the loaded document expires.
      Throws:
      NoSuchElementException - if this result came from a scan where ScanOptions.idsOnly(boolean) was set to true. See idOnly().
    • contentAsObject

      public JsonObject contentAsObject()
      Decodes the content of the document into a JsonObject.
      Throws:
      NoSuchElementException - if this result came from a scan where ScanOptions.idsOnly(boolean) was set to true. See idOnly().
    • contentAsArray

      public JsonArray contentAsArray()
      Decodes the content of the document into a JsonArray.
      Throws:
      NoSuchElementException - if this result came from a scan where ScanOptions.idsOnly(boolean) was set to true. See idOnly().
    • 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.
      Throws:
      NoSuchElementException - if this result came from a scan where ScanOptions.idsOnly(boolean) was set to true. See idOnly().
    • 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.
      Throws:
      NoSuchElementException - if this result came from a scan where ScanOptions.idsOnly(boolean) was set to true. See idOnly().
    • contentAsBytes

      public byte[] contentAsBytes()
      Returns the raw bytes of the document content.
      Returns:
      the document content as a byte array
      Throws:
      NoSuchElementException - if this result came from a scan where ScanOptions.idsOnly(boolean) was set to true. See idOnly().
    • 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