Class SyncImpl<DocumentT>

  • All Implemented Interfaces:
    Sync<DocumentT>

    public class SyncImpl<DocumentT>
    extends Object
    implements Sync<DocumentT>
    • Method Detail

      • configure

        public Task<Void> configure​(@NonNull
                                    ConflictHandler<DocumentT> conflictHandler,
                                    @Nullable
                                    ChangeEventListener<DocumentT> changeEventListener,
                                    @Nullable
                                    ExceptionListener exceptionListener)
        Description copied from interface: Sync
        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.
        Specified by:
        configure in interface Sync<DocumentT>
        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

        public Task<Void> configure​(@NonNull
                                    ConflictHandler<DocumentT> conflictHandler,
                                    @Nullable
                                    ChangeEventListener<DocumentT> changeEventListener,
                                    @Nullable
                                    ExceptionListener exceptionListener,
                                    @Nullable
                                    SyncFrequency syncFrequency)
        Description copied from interface: Sync
        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.
        Specified by:
        configure in interface Sync<DocumentT>
        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
        syncFrequency - 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

        public Task<Void> configure​(@NonNull
                                    SyncConfiguration syncConfiguration)
        Description copied from interface: Sync
        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.
        Specified by:
        configure in interface Sync<DocumentT>
        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

        public Task<Void> updateSyncFrequency​(@NonNull
                                              SyncFrequency syncFrequency)
        Sets the SyncFrequency on this collection.
        Specified by:
        updateSyncFrequency in interface Sync<DocumentT>
        Parameters:
        syncFrequency - the SyncFrequency that contains all the desired options
        Returns:
        A Task that completes when the SyncFrequency has been updated
      • syncOne

        public Task<Void> syncOne​(BsonValue id)
        Description copied from interface: Sync
        Requests that the given document _id be synchronized.
        Specified by:
        syncOne in interface Sync<DocumentT>
        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

        public Task<Void> syncMany​(BsonValue... ids)
        Description copied from interface: Sync
        Requests that the given document _ids be synchronized.
        Specified by:
        syncMany in interface Sync<DocumentT>
        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

        public Task<Void> desyncOne​(BsonValue id)
        Description copied from interface: Sync
        Stops synchronizing the given document _id. Any uncommitted writes will be lost.
        Specified by:
        desyncOne in interface Sync<DocumentT>
        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

        public Task<Void> desyncMany​(BsonValue... ids)
        Description copied from interface: Sync
        Stops synchronizing the given document _ids. Any uncommitted writes will be lost.
        Specified by:
        desyncMany in interface Sync<DocumentT>
        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

        public Task<Set<BsonValue>> getSyncedIds()
        Description copied from interface: Sync
        Returns the set of synchronized document ids in a namespace.
        Specified by:
        getSyncedIds in interface Sync<DocumentT>
        Returns:
        the set of synchronized document ids in a namespace.
      • getPausedDocumentIds

        public Task<Set<BsonValue>> getPausedDocumentIds()
        Description copied from interface: Sync
        Return the set of synchronized document _ids in a namespace that have been paused due to an irrecoverable error.
        Specified by:
        getPausedDocumentIds in interface Sync<DocumentT>
        Returns:
        the set of paused document _ids in a namespace
      • resumeSyncForDocument

        public Task<Boolean> resumeSyncForDocument​(@NonNull
                                                   BsonValue documentId)
        Description copied from interface: Sync
        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.
        Specified by:
        resumeSyncForDocument in interface Sync<DocumentT>
        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

        public Task<Long> count()
        Description copied from interface: Sync
        Counts the number of documents in the collection that have been synchronized with the remote.
        Specified by:
        count in interface Sync<DocumentT>
        Returns:
        the number of documents in the collection
      • count

        public Task<Long> count​(Bson filter)
        Description copied from interface: Sync
        Counts the number of documents in the collection that have been synchronized with the remote according to the given options.
        Specified by:
        count in interface Sync<DocumentT>
        Parameters:
        filter - the query filter
        Returns:
        the number of documents in the collection
      • count

        public Task<Long> count​(Bson filter,
                                SyncCountOptions options)
        Description copied from interface: Sync
        Counts the number of documents in the collection that have been synchronized with the remote according to the given options.
        Specified by:
        count in interface Sync<DocumentT>
        Parameters:
        filter - the query filter
        options - the options describing the count
        Returns:
        the number of documents in the collection
      • aggregate

        public SyncAggregateIterable<DocumentT> aggregate​(List<? extends Bson> pipeline)
        Description copied from interface: Sync
        Aggregates documents that have been synchronized with the remote according to the specified aggregation pipeline.
        Specified by:
        aggregate in interface Sync<DocumentT>
        Parameters:
        pipeline - the aggregation pipeline
        Returns:
        an iterable containing the result of the aggregation operation
      • aggregate

        public <ResultT> SyncAggregateIterable<ResultT> aggregate​(List<? extends Bson> pipeline,
                                                                  Class<ResultT> resultClass)
        Description copied from interface: Sync
        Aggregates documents that have been synchronized with the remote according to the specified aggregation pipeline.
        Specified by:
        aggregate in interface Sync<DocumentT>
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        pipeline - the aggregation pipeline
        resultClass - the class to decode each document into
        Returns:
        an iterable containing the result of the aggregation operation
      • find

        public SyncFindIterable<DocumentT> find()
        Description copied from interface: Sync
        Finds all documents in the collection that have been synchronized with the remote.
        Specified by:
        find in interface Sync<DocumentT>
        Returns:
        the find iterable interface
      • find

        public SyncFindIterable<DocumentT> find​(Bson filter)
        Description copied from interface: Sync
        Finds all documents in the collection that have been synchronized with the remote.
        Specified by:
        find in interface Sync<DocumentT>
        Parameters:
        filter - the query filter
        Returns:
        the find iterable interface
      • find

        public <ResultT> SyncFindIterable<ResultT> find​(Class<ResultT> resultClass)
        Description copied from interface: Sync
        Finds all documents in the collection that have been synchronized with the remote.
        Specified by:
        find in interface Sync<DocumentT>
        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

        public <ResultT> SyncFindIterable<ResultT> find​(Bson filter,
                                                        Class<ResultT> resultClass)
        Description copied from interface: Sync
        Finds all documents in the collection that have been synchronized with the remote.
        Specified by:
        find in interface Sync<DocumentT>
        Type Parameters:
        ResultT - the target document type of the iterable.
        Parameters:
        filter - the query filter
        resultClass - the class to decode each document into
        Returns:
        the find iterable interface
      • insertOne

        public Task<SyncInsertOneResult> insertOne​(DocumentT document)
        Description copied from interface: Sync
        Inserts the provided document. If the document is missing an identifier, one will be generated. Begin synchronizating on the document's id.
        Specified by:
        insertOne in interface Sync<DocumentT>
        Parameters:
        document - the document to insert
        Returns:
        the result of the insert one operation
      • insertMany

        public Task<SyncInsertManyResult> insertMany​(List<DocumentT> documents)
        Description copied from interface: Sync
        Inserts one or more documents. If the documents are missing an identifier, they will be generated. Begin synchronizing on the documents' ids.
        Specified by:
        insertMany in interface Sync<DocumentT>
        Parameters:
        documents - the documents to insert
        Returns:
        the result of the insert many operation
      • updateOne

        public Task<SyncUpdateResult> updateOne​(Bson filter,
                                                Bson update)
        Description copied from interface: Sync
        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.
        Specified by:
        updateOne in interface Sync<DocumentT>
        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

        public Task<SyncUpdateResult> updateOne​(Bson filter,
                                                Bson update,
                                                SyncUpdateOptions updateOptions)
        Description copied from interface: Sync
        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.
        Specified by:
        updateOne in interface Sync<DocumentT>
        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

        public Task<SyncUpdateResult> updateMany​(Bson filter,
                                                 Bson update)
        Description copied from interface: Sync
        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.
        Specified by:
        updateMany in interface Sync<DocumentT>
        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

        public Task<SyncUpdateResult> updateMany​(Bson filter,
                                                 Bson update,
                                                 SyncUpdateOptions updateOptions)
        Description copied from interface: Sync
        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.
        Specified by:
        updateMany in interface Sync<DocumentT>
        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
      • deleteOne

        public Task<SyncDeleteResult> deleteOne​(Bson filter)
        Description copied from interface: Sync
        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.
        Specified by:
        deleteOne in interface Sync<DocumentT>
        Parameters:
        filter - the query filter to apply the the delete operation
        Returns:
        the result of the remove one operation
      • deleteMany

        public Task<SyncDeleteResult> deleteMany​(Bson filter)
        Description copied from interface: Sync
        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.
        Specified by:
        deleteMany in interface Sync<DocumentT>
        Parameters:
        filter - the query filter to apply the the delete operation
        Returns:
        the result of the remove many operation