Class DittoStore
java.lang.Object
com.ditto.java.DittoStore
-
Method Summary
Modifier and TypeMethodDescription@NonNull CompletionStage<DittoQueryResult> Executes a DQL query and returns items as a query result.@NonNull CompletionStage<DittoQueryResult> execute(@NonNull String query, @NonNull DittoCborSerializable.Dictionary arguments) Executes a DQL query with arguments and returns items as a query result.@NonNull CompletionStage<DittoAttachmentFetchResult> fetchAttachment(@NonNull DittoAttachmentToken token) Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.@NonNull CompletionStage<DittoAttachmentFetchResult> fetchAttachment(@NonNull DittoAttachmentToken token, @Nullable DittoAttachmentFetchProgressHandler fetchProgressHandler) Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.@NonNull CompletionStage<DittoAttachmentFetchResult> fetchAttachment(@NonNull Map<String, Object> tokenMap) Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.@NonNull CompletionStage<DittoAttachmentFetchResult> fetchAttachment(@NonNull Map<String, Object> tokenMap, @Nullable DittoAttachmentFetchProgressHandler fetchProgressHandler) Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.@NonNull Set<? extends DittoAttachmentFetcher> All currently active attachment fetchers.@NonNull Set<? extends DittoStoreObserver> Returns all currently active store observers.@NonNull CompletionStage<DittoAttachment> newAttachment(@NonNull InputStream inputStream) Creates a new attachment, which can then be inserted into a document.@NonNull CompletionStage<DittoAttachment> newAttachment(@NonNull InputStream inputStream, @NonNull DittoCborSerializable.Dictionary metadata) Creates a new attachment, which can then be inserted into a document.@NonNull CompletionStage<DittoAttachment> newAttachment(@NonNull String path) Creates a new attachment, which can then be inserted into a document.@NonNull CompletionStage<DittoAttachment> newAttachment(@NonNull String path, @NonNull DittoCborSerializable.Dictionary metadata) Creates a new attachment, which can then be inserted into a document.@NonNull DittoAttachmentnewAttachmentBlocking(@NonNull InputStream inputStream) A blocking alternative tonewAttachment(InputStream).@NonNull DittoAttachmentnewAttachmentBlocking(@NonNull InputStream inputStream, @NonNull DittoCborSerializable.Dictionary metadata) A blocking alternative tonewAttachment(InputStream, DittoCborSerializable.Dictionary).@NonNull DittoAttachmentnewAttachmentBlocking(@NonNull String path) A blocking alternative tonewAttachment(String).@NonNull DittoAttachmentnewAttachmentBlocking(@NonNull String path, @NonNull DittoCborSerializable.Dictionary metadata) A blocking alternative tonewAttachment(String, DittoCborSerializable.Dictionary).<@NonNull T>
@NonNull Flow.Publisher<T> observe(@NonNull String query, @Nullable DittoCborSerializable.Dictionary arguments, @NonNull Function<@NonNull DittoQueryResult, @NonNull CompletionStage<@NonNull T>> transform) Returns a Flow Publisher that emits transformed query results whenever the local store changes.<@NonNull T>
@NonNull Flow.Publisher<T> observe(@NonNull String query, @NonNull Function<@NonNull DittoQueryResult, @NonNull CompletionStage<@NonNull T>> transform) Returns a Flow Publisher that emits transformed query results whenever the local store changes.@NonNull DittoStoreObserverregisterObserver(@NonNull String query, @NonNull DittoChangeListener listener) Convenience method that registers an observer wheresignalNextis called automatically after thechangeHandlerfinishes.@NonNull DittoStoreObserverregisterObserver(@NonNull String query, @NonNull DittoChangeListenerWithNextSignal listener) Installs and returns a store observer for a query, configuring Ditto to trigger the passed in change handler whenever documents in the local store change such that the result of the matching query changes.@NonNull DittoStoreObserverregisterObserver(@NonNull String query, @Nullable DittoCborSerializable.Dictionary arguments, @NonNull DittoChangeListener listener) Convenience method that registers an observer wheresignalNextis called automatically after thechangeHandlerfinishes.@NonNull DittoStoreObserverregisterObserver(@NonNull String query, @Nullable DittoCborSerializable.Dictionary arguments, @NonNull DittoChangeListenerWithNextSignal listener) Installs and returns a store observer for a query, configuring Ditto to trigger the passed in change handler whenever documents in the local store change such that the result of the matching query changes.<T> @NonNull CompletionStage<DittoTransaction.Result<T>> transaction(boolean isReadOnly, @NonNull DittoTransactionFunction<T> transactionBlock) Executes multiple DQL queries within a single atomic transaction.<T> @NonNull CompletionStage<DittoTransaction.Result<T>> transaction(@NonNull DittoTransactionFunction<T> transactionBlock) Executes multiple DQL queries within a single atomic transaction.<T> @NonNull CompletionStage<DittoTransaction.Result<T>> transaction(String hint, boolean isReadOnly, @NonNull DittoTransactionFunction<T> transactionBlock) Executes multiple DQL queries within a single atomic transaction.<T> @NonNull CompletionStage<DittoTransaction.Result<T>> transaction(String hint, @NonNull DittoTransactionFunction<T> transactionBlock) Executes multiple DQL queries within a single atomic transaction.
-
Method Details
-
getObservers
Returns all currently active store observers.- Returns:
- a
Setof activeDittoStoreObserverinstances.
-
execute
Executes a DQL query and returns items as a query result. This method only returns results from the local store without waiting for anyDittoSyncSubscriptions to have caught up with the latest changes. Only use this method if your program must proceed with immediate results. Use aDittoStoreObserverto receive updates to query results as soon as they have been synced to this peer.- Specified by:
executein interfaceDittoQueryExecuting- Parameters:
query- a string containing a valid query expressed in DQL.- Returns:
- a
CompletionStagethat completes with aDittoQueryResultcontaining aDittoQueryResultItemfor each match. - See Also:
-
execute
public @NonNull CompletionStage<DittoQueryResult> execute(@NonNull String query, @NonNull DittoCborSerializable.Dictionary arguments) Executes a DQL query with arguments and returns items as a query result. This method only returns results from the local store without waiting for anyDittoSyncSubscriptions to have caught up with the latest changes. Only use this method if your program must proceed with immediate results. Use aDittoStoreObserverto receive updates to query results as soon as they have been synced to this peer.- Specified by:
executein interfaceDittoQueryExecuting- Parameters:
query- a string containing a valid query expressed in DQL.arguments- a dictionary of values keyed by the placeholder name without the leading:. Example:["mileage": 123].- Returns:
- a
CompletionStagethat completes with aDittoQueryResultcontaining aDittoQueryResultItemfor each match. - See Also:
-
observe
public <@NonNull T> @NonNull Flow.Publisher<T> observe(@NonNull String query, @NonNull Function<@NonNull DittoQueryResult, @NonNull CompletionStage<@NonNull T>> transform) Returns a Flow Publisher that emits transformed query results whenever the local store changes.- Type Parameters:
T- the type of values emitted by the returned Publisher.- Parameters:
query- a string containing a valid query expressed in DQL.transform- a function that transformsDittoQueryResultinto a value of type T.- Returns:
- a
Flow.Publisherthat emits values of type T. - See Also:
-
observe
public <@NonNull T> @NonNull Flow.Publisher<T> observe(@NonNull String query, @Nullable DittoCborSerializable.Dictionary arguments, @NonNull Function<@NonNull DittoQueryResult, @NonNull CompletionStage<@NonNull T>> transform) Returns a Flow Publisher that emits transformed query results whenever the local store changes.- Type Parameters:
T- the type of values emitted by the returned Publisher.- Parameters:
query- a string containing a valid query expressed in DQL.arguments- a dictionary of values keyed by the placeholder name without the leading:. Example:["mileage": 123].transform- a function that transformsDittoQueryResultinto a value of type T.- Returns:
- a
Flow.Publisherthat emits values of type T. - See Also:
-
registerObserver
public @NonNull DittoStoreObserver registerObserver(@NonNull String query, @NonNull DittoChangeListener listener) throws DittoException Convenience method that registers an observer wheresignalNextis called automatically after thechangeHandlerfinishes.- Parameters:
query- a string containing a valid query expressed in DQL.listener- aDittoChangeListenerinstance which will be invoked with the results as changes occur.- Returns:
- an active
DittoStoreObserverfor the given query. - Throws:
DittoException- if there is a problem creating or registering the observer.- See Also:
-
registerObserver
public @NonNull DittoStoreObserver registerObserver(@NonNull String query, @Nullable DittoCborSerializable.Dictionary arguments, @NonNull DittoChangeListener listener) throws DittoException Convenience method that registers an observer wheresignalNextis called automatically after thechangeHandlerfinishes.- Parameters:
query- a string containing a valid query expressed in DQL.arguments- a dictionary of values keyed by the placeholder name without the leading:. Example:["mileage": 123].listener- aDittoChangeListenerinstance which will be invoked with the results as changes occur.- Returns:
- an active
DittoStoreObserverfor the given query and arguments. - Throws:
DittoException- if there is a problem creating or registering the observer.- See Also:
-
registerObserver
public @NonNull DittoStoreObserver registerObserver(@NonNull String query, @NonNull DittoChangeListenerWithNextSignal listener) throws DittoException Installs and returns a store observer for a query, configuring Ditto to trigger the passed in change handler whenever documents in the local store change such that the result of the matching query changes. The passed in query must be aSELECTquery, otherwise aDittoException.StoreExceptionwithDittoException.StoreExceptionReason.QueryNotSupportedreason is thrown.- Parameters:
query- A string containing a valid query expressed in DQL.listener- ADittoChangeListenerWithNextSignalinstance which will be invoked with the results as changes occur.- Returns:
- An active
DittoStoreObserverfor the given query and arguments. You'll have to keep it to be able to cancel the observation byclose()-ing it. Otherwise, it will remain active until the owningDittoinstance goes out of scope. - Throws:
DittoException.StoreException- When the provided query is not aSELECTquery.DittoException
-
registerObserver
public @NonNull DittoStoreObserver registerObserver(@NonNull String query, @Nullable DittoCborSerializable.Dictionary arguments, @NonNull DittoChangeListenerWithNextSignal listener) throws DittoException Installs and returns a store observer for a query, configuring Ditto to trigger the passed in change handler whenever documents in the local store change such that the result of the matching query changes. The passed in query must be aSELECTquery, otherwise aDittoException.StoreExceptionwithDittoException.StoreExceptionReason.QueryNotSupportedreason is thrown.- Parameters:
query- A string containing a valid query expressed in DQL.arguments- AMapof values keyed by the placeholder name without the leading:. Example:["mileage": 123].listener- ADittoChangeListenerWithNextSignalinstance which will be invoked with the results as changes occur.- Returns:
- An active
DittoStoreObserverfor the given query and arguments. You'll have to keep it to be able to cancel the observation byclose()-ing it. Otherwise, it will remain active until the owningDittoinstance goes out of scope. - Throws:
DittoException.StoreException- When the provided query is not aSELECTquery.DittoException
-
transaction
public <T> @NonNull CompletionStage<DittoTransaction.Result<T>> transaction(@NonNull DittoTransactionFunction<T> transactionBlock) Executes multiple DQL queries within a single atomic transaction. This ensures that either all statements are executed successfully, or none are executed at all, providing strong consistency guarantees. Certain mesh configurations may impose limitations on these guarantees. For more details, refer to the Ditto documentation. Transactions are initiated as read-write transactions by default, and only a single read-write transaction is executed at any given time. Any other read-write transaction started concurrently will wait until the current transaction has been committed or rolled back. Therefore, it is crucial to ensure a transaction finishes as early as possible so that other read-write transactions aren’t blocked for a long time. A transaction can also be configured to be read-only using theisReadonlyparameter. Multiple read-only transactions can be executed concurrently. However, executing a mutating DQL statement in a read-only transaction will throw an error. If errors occur in anexecute()call within the transaction block and the error is caught and handled within the block, the transaction will continue to run and will not be rolled back. However, if an error is thrown at any point inside the transaction block or while committing the transaction, the transaction is implicitly rolled back, and the error is propagated up to the caller. When a Ditto instance is explicitly closed or garbage collected, it will drive all pending transactions to completion before shutting down. Warning:* Callingditto.store.execute()or creating a nested transaction within a transaction may lead to a deadlock. For a complete guide on transactions, refer to the Ditto documentation.- Parameters:
transactionBlock- A lambda that provides access to aDittoTransactionobject, allowing DQL queries to be executed.- Returns:
- A CompletionStage<DittoTransaction.Result
> containing either the transaction action that was taken (DittoTransaction.Result.CommitorDittoTransaction.Result.Rollback), or an instance ofDittoException. ADittoException.StoreExceptionwithDittoException.StoreExceptionReason.TransactionReadOnlyreason will be propagated if the transaction is read-only, but a mutating query was executed. - See Also:
-
transaction
public <T> @NonNull CompletionStage<DittoTransaction.Result<T>> transaction(boolean isReadOnly, @NonNull DittoTransactionFunction<T> transactionBlock) Executes multiple DQL queries within a single atomic transaction. This ensures that either all statements are executed successfully, or none are executed at all, providing strong consistency guarantees. Certain mesh configurations may impose limitations on these guarantees. For more details, refer to the Ditto documentation. Transactions are initiated as read-write transactions by default, and only a single read-write transaction is executed at any given time. Any other read-write transaction started concurrently will wait until the current transaction has been committed or rolled back. Therefore, it is crucial to ensure a transaction finishes as early as possible so that other read-write transactions aren’t blocked for a long time. A transaction can also be configured to be read-only using theisReadonlyparameter. Multiple read-only transactions can be executed concurrently. However, executing a mutating DQL statement in a read-only transaction will throw an error. If errors occur in anexecute()call within the transaction block and the error is caught and handled within the block, the transaction will continue to run and will not be rolled back. However, if an error is thrown at any point inside the transaction block or while committing the transaction, the transaction is implicitly rolled back, and the error is propagated up to the caller. When a Ditto instance is explicitly closed or garbage collected, it will drive all pending transactions to completion before shutting down. Warning:* Callingditto.store.execute()or creating a nested transaction within a transaction may lead to a deadlock. For a complete guide on transactions, refer to the Ditto documentation.- Parameters:
isReadOnly- A flag indicating whether the transaction is read-only.transactionBlock- A lambda that provides access to aDittoTransactionobject, allowing DQL queries to be executed.- Returns:
- A CompletionStage<DittoTransaction.Result
> containing either the transaction action that was taken (DittoTransaction.Result.CommitorDittoTransaction.Result.Rollback), or an instance ofDittoException. ADittoException.StoreExceptionwithDittoException.StoreExceptionReason.TransactionReadOnlyreason will be propagated if the transaction is read-only, but a mutating query was executed. - See Also:
-
transaction
public <T> @NonNull CompletionStage<DittoTransaction.Result<T>> transaction(String hint, @NonNull DittoTransactionFunction<T> transactionBlock) Executes multiple DQL queries within a single atomic transaction. This ensures that either all statements are executed successfully, or none are executed at all, providing strong consistency guarantees. Certain mesh configurations may impose limitations on these guarantees. For more details, refer to the Ditto documentation. Transactions are initiated as read-write transactions by default, and only a single read-write transaction is executed at any given time. Any other read-write transaction started concurrently will wait until the current transaction has been committed or rolled back. Therefore, it is crucial to ensure a transaction finishes as early as possible so that other read-write transactions aren’t blocked for a long time. A transaction can also be configured to be read-only using theisReadonlyparameter. Multiple read-only transactions can be executed concurrently. However, executing a mutating DQL statement in a read-only transaction will throw an error. If errors occur in anexecute()call within the transaction block and the error is caught and handled within the block, the transaction will continue to run and will not be rolled back. However, if an error is thrown at any point inside the transaction block or while committing the transaction, the transaction is implicitly rolled back, and the error is propagated up to the caller. When a Ditto instance is explicitly closed or garbage collected, it will drive all pending transactions to completion before shutting down. Warning:* Callingditto.store.execute()or creating a nested transaction within a transaction may lead to a deadlock. For a complete guide on transactions, refer to the Ditto documentation.- Parameters:
hint- A hint for the transaction, which is logged. Mostly useful for debugging and testing.transactionBlock- A lambda that provides access to aDittoTransactionobject, allowing DQL queries to be executed.- Returns:
- A CompletionStage<DittoTransaction.Result
> containing either the transaction action that was taken (DittoTransaction.Result.CommitorDittoTransaction.Result.Rollback), or an instance ofDittoException. ADittoException.StoreExceptionwithDittoException.StoreExceptionReason.TransactionReadOnlyreason will be propagated if the transaction is read-only, but a mutating query was executed. - See Also:
-
transaction
public <T> @NonNull CompletionStage<DittoTransaction.Result<T>> transaction(String hint, boolean isReadOnly, @NonNull DittoTransactionFunction<T> transactionBlock) Executes multiple DQL queries within a single atomic transaction. This ensures that either all statements are executed successfully, or none are executed at all, providing strong consistency guarantees. Certain mesh configurations may impose limitations on these guarantees. For more details, refer to the Ditto documentation. Transactions are initiated as read-write transactions by default, and only a single read-write transaction is executed at any given time. Any other read-write transaction started concurrently will wait until the current transaction has been committed or rolled back. Therefore, it is crucial to ensure a transaction finishes as early as possible so that other read-write transactions aren’t blocked for a long time. A transaction can also be configured to be read-only using theisReadonlyparameter. Multiple read-only transactions can be executed concurrently. However, executing a mutating DQL statement in a read-only transaction will throw an error. If errors occur in anexecute()call within the transaction block and the error is caught and handled within the block, the transaction will continue to run and will not be rolled back. However, if an error is thrown at any point inside the transaction block or while committing the transaction, the transaction is implicitly rolled back, and the error is propagated up to the caller. When a Ditto instance is explicitly closed or garbage collected, it will drive all pending transactions to completion before shutting down. Warning:* Callingditto.store.execute()or creating a nested transaction within a transaction may lead to a deadlock. For a complete guide on transactions, refer to the Ditto documentation.- Parameters:
hint- A hint for the transaction, which is logged. Mostly useful for debugging and testing.isReadOnly- A flag indicating whether the transaction is read-only.transactionBlock- A lambda that provides access to aDittoTransactionobject, allowing DQL queries to be executed.- Returns:
- A CompletionStage<DittoTransaction.Result
> containing either the transaction action that was taken (DittoTransaction.Result.CommitorDittoTransaction.Result.Rollback), or an instance ofDittoException. ADittoException.StoreExceptionwithDittoException.StoreExceptionReason.TransactionReadOnlyreason will be propagated if the transaction is read-only, but a mutating query was executed. - See Also:
-
newAttachment
Creates a new attachment, which can then be inserted into a document. The file residing at the provided path will be copied into the Ditto's store. TheDittoAttachmentobject that is returned is what you can then use to insert an attachment into a document. You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment. Below is a snippet to show how you can use thenewAttachmentfunctionality to insert an attachment into a document.- Parameters:
path- the path to the file that you want to create an attachment with.- Returns:
- A CompletionStage
instance, which can be used to insert the attachment into a document.
-
newAttachment
public @NonNull CompletionStage<DittoAttachment> newAttachment(@NonNull String path, @NonNull DittoCborSerializable.Dictionary metadata) Creates a new attachment, which can then be inserted into a document. The file residing at the provided path will be copied into the Ditto's store. TheDittoAttachmentobject that is returned is what you can then use to insert an attachment into a document. You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment.- Parameters:
path- The path to the file that you want to create an attachment with.metadata- Metadata relating to the attachment.- Returns:
- A CompletionStage
instance, which can be used to insert the attachment into a document.
-
newAttachment
Creates a new attachment, which can then be inserted into a document. The file that the input stream relates to will be copied into Ditto's store. TheDittoAttachmentobject that is returned is what you can then use to insert an attachment into a document. You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment. Note that the input stream provided will be closed once it has been read from.- Parameters:
inputStream- an input stream for the file that you want to create an attachment with.- Returns:
- a CompletionStage
instance, which can be used to insert the attachment into a document.
-
newAttachment
public @NonNull CompletionStage<DittoAttachment> newAttachment(@NonNull InputStream inputStream, @NonNull DittoCborSerializable.Dictionary metadata) Creates a new attachment, which can then be inserted into a document. The file that the input stream relates to will be copied into Ditto's store. TheDittoAttachmentobject that is returned is what you can then use to insert an attachment into a document. You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment. Note that the input stream provided will be closed once it has been read from.- Parameters:
inputStream- an input stream for the file that you want to create an attachment with.metadata- metadata relating to the attachment.- Returns:
- a CompletionStage
instance, which can be used to insert the attachment into a document.
-
newAttachmentBlocking
A blocking alternative tonewAttachment(String).- Throws:
DittoException- See Also:
-
newAttachmentBlocking
public @NonNull DittoAttachment newAttachmentBlocking(@NonNull String path, @NonNull DittoCborSerializable.Dictionary metadata) throws DittoException A blocking alternative tonewAttachment(String, DittoCborSerializable.Dictionary).- Throws:
DittoException- See Also:
-
newAttachmentBlocking
public @NonNull DittoAttachment newAttachmentBlocking(@NonNull InputStream inputStream) throws DittoException A blocking alternative tonewAttachment(InputStream).- Throws:
DittoException- See Also:
-
newAttachmentBlocking
public @NonNull DittoAttachment newAttachmentBlocking(@NonNull InputStream inputStream, @NonNull DittoCborSerializable.Dictionary metadata) throws DittoException A blocking alternative tonewAttachment(InputStream, DittoCborSerializable.Dictionary).- Throws:
DittoException- See Also:
-
getAttachmentFetchers
All currently active attachment fetchers. -
fetchAttachment
public @NonNull CompletionStage<DittoAttachmentFetchResult> fetchAttachment(@NonNull DittoAttachmentToken token) throws DittoException Trigger an attachment to be downloaded locally to the device and observe its progress as it does so. When you encounter a document that contains an attachment the attachment will not automatically be downloaded along with the document. You trigger an attachment to be downloaded locally to a device by calling this method. It will report changes to the status of the fetch attempt as it tries to download it. Assuming it succeeds in downloading the attachment it will call theonFetchEventblock with a completed event object, which will hold a reference to the attachment.- Parameters:
token- theDittoAttachmentTokenrelevant to the attachment that you wish to download and observe.- Returns:
- a CompletionStage
, which can be used to cancel the fetching, or await the result. Otherwise, the fetch will remain active until it either completes, the attachment is deleted, or the owning Dittoobject is closed. - Throws:
DittoException
-
fetchAttachment
public @NonNull CompletionStage<DittoAttachmentFetchResult> fetchAttachment(@NonNull DittoAttachmentToken token, @Nullable DittoAttachmentFetchProgressHandler fetchProgressHandler) Trigger an attachment to be downloaded locally to the device and observe its progress as it does so. When you encounter a document that contains an attachment the attachment will not automatically be downloaded along with the document. You trigger an attachment to be downloaded locally to a device by calling this method. It will report changes to the status of the fetch attempt as it tries to download it. Assuming it succeeds in downloading the attachment it will call theonFetchEventblock with a completed event object, which will hold a reference to the attachment.- Parameters:
token- theDittoAttachmentTokenrelevant to the attachment that you wish to download and observe.fetchProgressHandler- aDittoAttachmentFetchProgressHandlerinstance that will be called when there is an update relating to the attachment fetch progress.- Returns:
- a CompletionStage
, which can be used to cancel the fetching, or await the result. Otherwise, the fetch will remain active until it either completes, the attachment is deleted, or the owning Dittoobject is closed.
-
fetchAttachment
public @NonNull CompletionStage<DittoAttachmentFetchResult> fetchAttachment(@NonNull Map<String, Object> tokenMap) Trigger an attachment to be downloaded locally to the device and observe its progress as it does so. When you encounter a document that contains an attachment the attachment will not automatically be downloaded along with the document. You trigger an attachment to be downloaded locally to a device by calling this method. It will report changes to the status of the fetch attempt as it tries to download it. Assuming it succeeds in downloading the attachment it will call theonFetchEventblock with a completed event object, which will hold a reference to the attachment.- Parameters:
tokenMap- a Map representation ofDittoAttachmentTokenrelevant to the attachment that you wish to download and observe.- Returns:
- a CompletionStage
, which can be used to cancel the fetching, or await the result. Otherwise, the fetch will remain active until it either completes, the attachment is deleted, or the owning Dittoobject is closed.
-
fetchAttachment
public @NonNull CompletionStage<DittoAttachmentFetchResult> fetchAttachment(@NonNull Map<String, Object> tokenMap, @Nullable DittoAttachmentFetchProgressHandler fetchProgressHandler) Trigger an attachment to be downloaded locally to the device and observe its progress as it does so. When you encounter a document that contains an attachment the attachment will not automatically be downloaded along with the document. You trigger an attachment to be downloaded locally to a device by calling this method. It will report changes to the status of the fetch attempt as it tries to download it. Assuming it succeeds in downloading the attachment it will call theonFetchEventblock with a completed event object, which will hold a reference to the attachment.- Parameters:
tokenMap- a Map representation ofDittoAttachmentTokenrelevant to the attachment that you wish to download and observe.fetchProgressHandler- aDittoAttachmentFetchProgressHandlerinstance that will be called when there is an update relating to the attachment fetch progress.- Returns:
- a CompletionStage
, which can be used to cancel the fetching, or await the result. Otherwise, the fetch will remain active until it either completes, the attachment is deleted, or the owning Dittoobject is closed.
-