Interface Sync<DocumentT>
-
- Type Parameters:
DocumentT
- the type of document we are syncing on
- All Known Implementing Classes:
SyncImpl
public interface Sync<DocumentT>
A set of synchronization related operations for a collection.
-
-
Method Summary
Modifier and Type Method Description SyncAggregateIterable<DocumentT>
aggregate(List<? extends Bson> pipeline)
Aggregates documents that have been synchronized with the remote according to the specified aggregation pipeline.<ResultT> SyncAggregateIterable<ResultT>
aggregate(List<? extends Bson> pipeline, Class<ResultT> resultClass)
Aggregates documents that have been synchronized with the remote according to the specified aggregation pipeline.Task<Void>
configure(ConflictHandler<DocumentT> conflictHandler, ChangeEventListener<DocumentT> changeEventListener, ExceptionListener exceptionListener)
Deprecated.configure(SyncConfiguration syncConfig)Task<Void>
configure(ConflictHandler<DocumentT> conflictHandler, ChangeEventListener<DocumentT> changeEventListener, ExceptionListener exceptionListener, SyncFrequency syncFrequency)
Deprecated.configure(SyncConfiguration syncConfig)Task<Void>
configure(SyncConfiguration syncConfiguration)
Set the conflict handler and and change event listener on this collection.Task<Long>
count()
Counts the number of documents in the collection that have been synchronized with the remote.Task<Long>
count(Bson filter)
Counts the number of documents in the collection that have been synchronized with the remote according to the given options.Task<Long>
count(Bson filter, SyncCountOptions options)
Counts the number of documents in the collection that have been synchronized with the remote according to the given options.Task<SyncDeleteResult>
deleteMany(Bson filter)
Removes all documents from the collection that have been synchronized with the remote that match the given query filter.Task<SyncDeleteResult>
deleteOne(Bson filter)
Removes at most one document that has been synchronized with the remote from the collection that matches the given filter.Task<Void>
desyncMany(BsonValue... ids)
Stops synchronizing the given document _ids.Task<Void>
desyncOne(BsonValue id)
Stops synchronizing the given document _id.SyncFindIterable<DocumentT>
find()
Finds all documents in the collection that have been synchronized with the remote.<ResultT> SyncFindIterable<ResultT>
find(Class<ResultT> resultClass)
Finds all documents in the collection that have been synchronized with the remote.SyncFindIterable<DocumentT>
find(Bson filter)
Finds all documents in the collection that have been synchronized with the remote.<ResultT> SyncFindIterable<ResultT>
find(Bson filter, Class<ResultT> resultClass)
Finds all documents in the collection that have been synchronized with the remote.Task<Set<BsonValue>>
getPausedDocumentIds()
Return the set of synchronized document _ids in a namespace that have been paused due to an irrecoverable error.Task<Set<BsonValue>>
getSyncedIds()
Returns the set of synchronized document ids in a namespace.Task<SyncInsertManyResult>
insertMany(List<DocumentT> documents)
Inserts one or more documents.Task<SyncInsertOneResult>
insertOne(DocumentT document)
Inserts the provided document.Task<Boolean>
resumeSyncForDocument(BsonValue documentId)
A document that is paused no longer has remote updates applied to it.Task<Void>
syncMany(BsonValue... ids)
Requests that the given document _ids be synchronized.Task<Void>
syncOne(BsonValue id)
Requests that the given document _id be synchronized.Task<SyncUpdateResult>
updateMany(Bson filter, Bson update)
Update all documents that have been synchronized with the remote in the collection according to the specified arguments.Task<SyncUpdateResult>
updateMany(Bson filter, Bson update, SyncUpdateOptions updateOptions)
Update all documents that have been synchronized with the remote in the collection according to the specified arguments.Task<SyncUpdateResult>
updateOne(Bson filter, Bson update)
Update a single document that has been synchronized with the remote in the collection according to the specified arguments.Task<SyncUpdateResult>
updateOne(Bson filter, Bson update, SyncUpdateOptions updateOptions)
Update a single document that has been synchronized with the remote in the collection according to the specified arguments.Task<Void>
updateSyncFrequency(SyncFrequency syncFrequency)
Sets the SyncFrequency on this collection.
-
-
-
Method Detail
-
configure
@Deprecated @CheckReturnValue Task<Void> configure(@NonNull ConflictHandler<DocumentT> conflictHandler, @Nullable ChangeEventListener<DocumentT> changeEventListener, @Nullable ExceptionListener exceptionListener)
Deprecated.configure(SyncConfiguration syncConfig)Set the conflict handler and and change event listener on this collection. This will start a background sync thread, and should be called before any CRUD operations are attempted.- Parameters:
conflictHandler
- the conflict resolver to invoke when a conflict happens between local and remote events.changeEventListener
- the event listener to invoke when a change event happens for the document.exceptionListener
- the error listener to invoke when an irrecoverable error occurs- Returns:
- A Task that completes when Mobile Sync is configured, and the background sync thread has started.
-
configure
@Deprecated @CheckReturnValue Task<Void> configure(@NonNull ConflictHandler<DocumentT> conflictHandler, @Nullable ChangeEventListener<DocumentT> changeEventListener, @Nullable ExceptionListener exceptionListener, @Nullable SyncFrequency syncFrequency)
Deprecated.configure(SyncConfiguration syncConfig)Set the conflict handler and and change event listener on this collection. This will start a background sync thread, and should be called before any CRUD operations are attempted.- Parameters:
conflictHandler
- the conflict resolver to invoke when a conflict happens between local and remote events.changeEventListener
- the event listener to invoke when a change event happens for the document.exceptionListener
- the error listener to invoke when an irrecoverable error occurssyncFrequency
- the syncFrequency at which to perform synchronization passes- Returns:
- A Task that completes when Mobile Sync is configured, and the background sync thread has started.
-
configure
@CheckReturnValue Task<Void> configure(@NonNull SyncConfiguration syncConfiguration)
Set the conflict handler and and change event listener on this collection. This will start a background sync thread, and should be called before any CRUD operations are attempted.- Parameters:
syncConfiguration
- the SyncConfiguration that contains all the desired options- Returns:
- A Task that completes when Mobile Sync is configured, and the background sync thread has started.
-
updateSyncFrequency
@CheckReturnValue Task<Void> updateSyncFrequency(@NonNull SyncFrequency syncFrequency)
Sets the SyncFrequency on this collection.- Parameters:
syncFrequency
- the SyncFrequency that contains all the desired options- Returns:
- A Task that completes when the SyncFrequency has been updated
-
syncOne
@CheckReturnValue Task<Void> syncOne(BsonValue id)
Requests that the given document _id be synchronized.- Parameters:
id
- the document _id to synchronize.- Returns:
- a Task that completes when the specified document ID is configured as synced. The actual document may not be in sync with the remote collection until the next sync pass.
-
syncMany
@CheckReturnValue Task<Void> syncMany(BsonValue... ids)
Requests that the given document _ids be synchronized.- Parameters:
ids
- the document _ids to synchronize.- Returns:
- a Task that completes when the specified document IDs are configured as synced. The actual documents may not be in sync with the remote collection until the next sync pass.
-
desyncOne
@CheckReturnValue Task<Void> desyncOne(BsonValue id)
Stops synchronizing the given document _id. Any uncommitted writes will be lost.- Parameters:
id
- the _id of the document to desynchronize.- Returns:
- a Task that completes when the specified document ID is no longer configured as synced. The document will be removed from the local collection, but it will not be necessarily deleted from the remote collection.
-
desyncMany
@CheckReturnValue Task<Void> desyncMany(BsonValue... ids)
Stops synchronizing the given document _ids. Any uncommitted writes will be lost.- Parameters:
ids
- the _ids of the documents to desynchronize.- Returns:
- a Task that completes when the specified document ID is no longer configured as synced. The documents will be removed from the local collection, but they are not necessarily deleted from the remote collection.
-
getSyncedIds
@CheckReturnValue Task<Set<BsonValue>> getSyncedIds()
Returns the set of synchronized document ids in a namespace.- Returns:
- the set of synchronized document ids in a namespace.
-
getPausedDocumentIds
@CheckReturnValue Task<Set<BsonValue>> getPausedDocumentIds()
Return the set of synchronized document _ids in a namespace that have been paused due to an irrecoverable error.- Returns:
- the set of paused document _ids in a namespace
-
resumeSyncForDocument
@CheckReturnValue Task<Boolean> resumeSyncForDocument(@NonNull BsonValue documentId)
A document that is paused no longer has remote updates applied to it. Any local updates to this document cause it to be resumed. An example of pausing a document is when a conflict is being resolved for that document and the handler throws an exception.- Parameters:
documentId
- the id of the document to resume syncing- Returns:
- true if successfully resumed, false if the document could not be found or there was an error resuming
-
count
@CheckReturnValue Task<Long> count()
Counts the number of documents in the collection that have been synchronized with the remote.- Returns:
- the number of documents in the collection
-
count
@CheckReturnValue Task<Long> count(Bson filter)
Counts the number of documents in the collection that have been synchronized with the remote according to the given options.- Parameters:
filter
- the query filter- Returns:
- the number of documents in the collection
-
count
@CheckReturnValue Task<Long> count(Bson filter, SyncCountOptions options)
Counts the number of documents in the collection that have been synchronized with the remote according to the given options.- Parameters:
filter
- the query filteroptions
- the options describing the count- Returns:
- the number of documents in the collection
-
find
SyncFindIterable<DocumentT> find()
Finds all documents in the collection that have been synchronized with the remote.- Returns:
- the find iterable interface
-
find
<ResultT> SyncFindIterable<ResultT> find(Class<ResultT> resultClass)
Finds all documents in the collection that have been synchronized with the remote.- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
resultClass
- the class to decode each document into- Returns:
- the find iterable interface
-
find
SyncFindIterable<DocumentT> find(Bson filter)
Finds all documents in the collection that have been synchronized with the remote.- Parameters:
filter
- the query filter- Returns:
- the find iterable interface
-
find
<ResultT> SyncFindIterable<ResultT> find(Bson filter, Class<ResultT> resultClass)
Finds all documents in the collection that have been synchronized with the remote.- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
filter
- the query filterresultClass
- the class to decode each document into- Returns:
- the find iterable interface
-
aggregate
SyncAggregateIterable<DocumentT> aggregate(List<? extends Bson> pipeline)
Aggregates documents that have been synchronized with the remote according to the specified aggregation pipeline.- Parameters:
pipeline
- the aggregation pipeline- Returns:
- an iterable containing the result of the aggregation operation
-
aggregate
<ResultT> SyncAggregateIterable<ResultT> aggregate(List<? extends Bson> pipeline, Class<ResultT> resultClass)
Aggregates documents that have been synchronized with the remote according to the specified aggregation pipeline.- Type Parameters:
ResultT
- the target document type of the iterable.- Parameters:
pipeline
- the aggregation pipelineresultClass
- the class to decode each document into- Returns:
- an iterable containing the result of the aggregation operation
-
insertOne
@CheckReturnValue Task<SyncInsertOneResult> insertOne(DocumentT document)
Inserts the provided document. If the document is missing an identifier, one will be generated. Begin synchronizating on the document's id.- Parameters:
document
- the document to insert- Returns:
- the result of the insert one operation
-
insertMany
@CheckReturnValue Task<SyncInsertManyResult> insertMany(List<DocumentT> documents)
Inserts one or more documents. If the documents are missing an identifier, they will be generated. Begin synchronizing on the documents' ids.- Parameters:
documents
- the documents to insert- Returns:
- the result of the insert many operation
-
deleteOne
@CheckReturnValue Task<SyncDeleteResult> deleteOne(Bson filter)
Removes at most one document that has been synchronized with the remote from the collection that matches the given filter. If no documents match, the collection is not modified.- Parameters:
filter
- the query filter to apply the the delete operation- Returns:
- the result of the remove one operation
-
deleteMany
@CheckReturnValue Task<SyncDeleteResult> deleteMany(Bson filter)
Removes all documents from the collection that have been synchronized with the remote that match the given query filter. If no documents match, the collection is not modified.- Parameters:
filter
- the query filter to apply the the delete operation- Returns:
- the result of the remove many operation
-
updateOne
@CheckReturnValue Task<SyncUpdateResult> updateOne(Bson filter, Bson update)
Update a single document that has been synchronized with the remote in the collection according to the specified arguments. If the update results in an upsert, the newly upserted document will automatically become synchronized.- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.- Returns:
- the result of the update one operation
-
updateOne
@CheckReturnValue Task<SyncUpdateResult> updateOne(Bson filter, Bson update, SyncUpdateOptions updateOptions)
Update a single document that has been synchronized with the remote in the collection according to the specified arguments. If the update results in an upsert, the newly upserted document will automatically become synchronized.- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the options to apply to the update operation- Returns:
- the result of the update one operation
-
updateMany
@CheckReturnValue Task<SyncUpdateResult> updateMany(Bson filter, Bson update)
Update all documents that have been synchronized with the remote in the collection according to the specified arguments. If the update results in an upsert, the newly upserted document will automatically become synchronized.- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.- Returns:
- the result of the update many operation
-
updateMany
@CheckReturnValue Task<SyncUpdateResult> updateMany(Bson filter, Bson update, SyncUpdateOptions updateOptions)
Update all documents that have been synchronized with the remote in the collection according to the specified arguments. If the update results in an upsert, the newly upserted document will automatically become synchronized.- Parameters:
filter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the options to apply to the update operation- Returns:
- the result of the update many operation
-
-