Package com.couchbase.client.java.kv
Class ScanResult
- java.lang.Object
-
- com.couchbase.client.java.kv.ScanResult
-
-
Constructor Summary
Constructors Constructor Description ScanResult(boolean idOnly, String id, byte[] content, int flags, long cas, Optional<Instant> expiry, Transcoder transcoder)Creates a newGetResult.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcas()Returns the CAS value of document at the time of loading.<T> TcontentAs(TypeRef<T> target)Decodes the content of the document into an instance of the target type.<T> TcontentAs(Class<T> target)Decodes the content of the document into an instance of the target class.JsonArraycontentAsArray()Decodes the content of the document into aJsonArray.byte[]contentAsBytes()Returns the raw bytes of the document content.JsonObjectcontentAsObject()Decodes the content of the document into aJsonObject.booleanequals(Object o)Optional<Instant>expiryTime()If the document has an expiry, returns the point in time when the loaded document expires.inthashCode()Stringid()Returns the ID of the document.booleanidOnly()Returns true if this result came from a scan whereScanOptions.idsOnly(boolean)was set to true.StringtoString()
-
-
-
Method Detail
-
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 whereScanOptions.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 whereScanOptions.idsOnly(boolean)was set to true. SeeidOnly().
-
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 whereScanOptions.idsOnly(boolean)was set to true. SeeidOnly().
-
contentAsObject
public JsonObject contentAsObject()
Decodes the content of the document into aJsonObject.- Throws:
NoSuchElementException- if this result came from a scan whereScanOptions.idsOnly(boolean)was set to true. SeeidOnly().
-
contentAsArray
public JsonArray contentAsArray()
Decodes the content of the document into aJsonArray.- Throws:
NoSuchElementException- if this result came from a scan whereScanOptions.idsOnly(boolean)was set to true. SeeidOnly().
-
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 whereScanOptions.idsOnly(boolean)was set to true. SeeidOnly().
-
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 whereScanOptions.idsOnly(boolean)was set to true. SeeidOnly().
-
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 whereScanOptions.idsOnly(boolean)was set to true. SeeidOnly().
-
-