Class DittoQueryResultItem
- All Implemented Interfaces:
Closeable,AutoCloseable
Represents a single match of a DQL query, similar to a "row" in SQL terms.
This is a reference type serving as a "cursor", allowing for efficient access of the underlying data in various formats (Dictionary, CBOR, or JSON).
The getValue() method lazily materializes the value and keeps it in memory
until the item goes out of scope or dematerialize() is called. To reduce memory
footprint, structure your code so items can be processed as a stream (one by one or in batches)
and dematerialize them immediately after use.
This class implements Closeable for resource management. Use try-with-resources
statements for automatic cleanup.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this query result item and releases associated resources.voidReleases the materialized value from memory.booleanbyte[]Returns the content of the item as raw CBOR data.@NonNull StringReturns the content of the item as a JSON string.@NonNull DittoCborSerializable.DictionarygetValue()Returns the content as a materialized dictionary.inthashCode()booleanReturns whether the value is currently materialized in memory.@Nullable DittoCborSerializable.DictionaryLoads and materializes the item's content into memory.
-
Method Details
-
getValue
Returns the content as a materialized dictionary.
The item's value is materialized on first access and subsequently on each access after calling
dematerialize(). Once materialized, the value is kept in memory until explicitly dematerialized or the item goes out of scope.- Returns:
- the item's content as a
DittoCborSerializable.Dictionary. - See Also:
-
isMaterialized
public boolean isMaterialized()Returns whether the value is currently materialized in memory.- Returns:
trueif the value is materialized,falseotherwise.- See Also:
-
materialize
Loads and materializes the item's content into memory.
This method loads the CBOR representation of the item's content and decodes it into a dictionary that can be accessed via
getValue(). The dictionary is kept in memory untildematerialize()is called. This is a no-op if the value is already materialized.- Returns:
- a
DittoCborSerializable.Dictionarycontaining the item's data, ornull. - Throws:
DittoException- if there is a problem retrieving or decoding the data.- See Also:
-
dematerialize
public void dematerialize()Releases the materialized value from memory.
Call this method to free memory after processing an item. This is a no-op if the item is not currently materialized.
- See Also:
-
getCborData
public byte[] getCborData()Returns the content of the item as raw CBOR data.
Important: The returned CBOR data is not cached. Call this method once and keep the result for as long as needed to avoid unnecessary recomputation.
- Returns:
- a byte array containing the CBOR-encoded data.
-
getJsonString
Returns the content of the item as a JSON string.
Important: The returned JSON string is not cached. Call this method once and keep the result for as long as needed to avoid unnecessary recomputation.
- Returns:
- a JSON string representation of the item's content.
-
close
Closes this query result item and releases associated resources.
This method should be called when the item is no longer needed to free resources. Use try-with-resources statements for automatic cleanup.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs during cleanup.
-
hashCode
-
equals
-