Class GeodatabaseSyncTask

  • All Implemented Interfaces:
    ApiKeyResource, RemoteResource, Loadable

    public final class GeodatabaseSyncTask
    extends java.lang.Object
    implements Loadable, RemoteResource, ApiKeyResource
    A task that can be used to create, download, and synchronize a sync-enabled mobile geodatabase from a sync-enabled ArcGIS Feature service. The service could be hosted in the cloud on ArcGIS Online or on-premise with ArcGIS servers.

    Mobile geodatabases are designed for querying and viewing feature data when your app is offline. In addition, while offline your app can edit a geodatabase locally and later sync changes with the service (assuming that the associated service supports sync). While offline, the mobile geodatabase keeps track of local edits, when those edits are synchronized with the service, local edits can be sent to the service and changes made on the service in the meantime by other processes can also be received.

    You can create a mobile geodatabase on your device by downloading it from a sync-enabled ArcGIS feature service using generateGeodatabase(GenerateGeodatabaseParameters, String). If the geodatabase is sync-enabled, you can sync it with the sync-enabled service from which it was created using syncGeodatabase(SyncGeodatabaseParameters, Geodatabase).

    Another way to work with mobile geodatabases is to provision a pre-created copy of a sync-enabled mobile geodatabase onto your device by loading it onto your device's file system. Register this geodatabase with its associated service using the registerSyncEnabledGeodatabaseAsync(Geodatabase) operation so that it can be synced.

    The GeodatabaseSyncTask also allows you to unregister a geodatabase using the unregisterGeodatabaseAsync(Geodatabase), which permanently prevents sync of the mobile geodatabase with its associated service. Unregistered geodatabases cannot be re-registered.

    Since:
    100.0.0
    • Constructor Detail

      • GeodatabaseSyncTask

        public GeodatabaseSyncTask​(java.lang.String url)
        Constructs a GeodatabaseSyncTask for a feature service specified by its URL.
        Parameters:
        url - the URL of a feature service with sync capabilities
        Throws:
        java.lang.IllegalArgumentException - if url is null or empty
        Since:
        100.0.0
    • Method Detail

      • setCredential

        public void setCredential​(Credential credential)
        Sets the credential used to authenticate the user with this task.
        Specified by:
        setCredential in interface RemoteResource
        Parameters:
        credential - the credential used to authenticate the user with this task
        Since:
        100.0.0
      • getCredential

        public Credential getCredential()
        Gets the credential used to authenticate the user with this task.
        Specified by:
        getCredential in interface RemoteResource
        Returns:
        the credential, or null if there is none
        Since:
        100.0.0
      • setRequestConfiguration

        public void setRequestConfiguration​(RequestConfiguration requestConfiguration)
        Sets configuration parameters used for network requests sent using this task. The global RequestConfiguration is used if no RequestConfiguration is set.
        Specified by:
        setRequestConfiguration in interface RemoteResource
        Parameters:
        requestConfiguration - object containing the parameters to use
        Since:
        100.0.0
      • getUri

        public java.lang.String getUri()
        Gets the URL of the feature service associated with this task.
        Specified by:
        getUri in interface RemoteResource
        Returns:
        the URL of the feature service
        Since:
        100.0.0
      • getFeatureServiceInfo

        public ArcGISFeatureServiceInfo getFeatureServiceInfo()
        Gets service information for the feature service associated with this task.
        Returns:
        an ArcGISFeatureServiceInfo object for the feature service
        Since:
        100.0.0
      • createDefaultGenerateGeodatabaseParametersAsync

        public ListenableFuture<GenerateGeodatabaseParameters> createDefaultGenerateGeodatabaseParametersAsync​(Geometry extent)
        Executes an asynchronous operation to create a set of default parameters that can be used to generate a geodatabase from the service. The result is a GenerateGeodatabaseParameters object.

        This will populate the parameters with values matching what the service supports. For example if the service does not support SyncModel.PER_LAYER then SyncModel.PER_GEODATABASE will be used. All layers from the service will be included. The extent of the data to be included in the geodatabase will be the geometry that is passed into the method. The output spatial reference will be the spatial reference of the given extent. Attachments are included by default. Related records will not be included.

        Parameters:
        extent - the extent of the data to be included in the generated geodatabase.
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
        • IOException if the network request fails
        Since:
        100.0.0
        See Also:
        generateGeodatabase(GenerateGeodatabaseParameters, String)
      • createDefaultSyncGeodatabaseParametersAsync

        public ListenableFuture<SyncGeodatabaseParameters> createDefaultSyncGeodatabaseParametersAsync​(Geodatabase geodatabase)
        Executes an asynchronous operation to create a set of default parameters that can be used to synchronize a geodatabase with the service. The result is a SyncGeodatabaseParameters object.

        This will populate the parameters with values matching what the service and the geodatabase support. For a geodatabase with SyncModel.PER_LAYER, all geodatabase layers will be included. If the service is read-only then the sync direction will be SyncGeodatabaseParameters.SyncDirection.DOWNLOAD. Otherwise the sync direction will be SyncGeodatabaseParameters.SyncDirection.BIDIRECTIONAL.

        Parameters:
        geodatabase - the geodatabase to be synchronized
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
        • IOException if the network request fails
        Throws:
        java.lang.IllegalArgumentException - if geodatabase is null
        Since:
        100.0.0
        See Also:
        syncGeodatabase(SyncGeodatabaseParameters, Geodatabase)
      • createDefaultSyncGeodatabaseParametersAsync

        public ListenableFuture<SyncGeodatabaseParameters> createDefaultSyncGeodatabaseParametersAsync​(Geodatabase geodatabase,
                                                                                                       SyncGeodatabaseParameters.SyncDirection syncDirection)
        Executes an asynchronous operation to create a set of default parameters that can be used to synchronize a geodatabase with the service using the given sync direction. The result is a SyncGeodatabaseParameters object.

        This will populate the parameters with values matching what the service and the geodatabase supports. For a geodatabase with SyncModel.PER_LAYER, all geodatabase layers will be included. A service is editable if it has capabilities that include any of create, update, or delete. In this case both SyncGeodatabaseParameters.SyncDirection.BIDIRECTIONAL and SyncGeodatabaseParameters.SyncDirection.UPLOAD are supported sync directions. Alternatively, a service that does not have create, update, or delete capability is considered read-only and only SyncGeodatabaseParameters.SyncDirection.DOWNLOAD will be supported. If the given sync direction is not compatible with the service or the geodatabase is not sync enabled, the returned async operation will fail.

        Parameters:
        geodatabase - the geodatabase to be synchronized
        syncDirection - the sync direction to use when syncing the Geodatabase
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
        • IOException if the network request fails
        Throws:
        java.lang.IllegalArgumentException - if geodatabase or syncDirection is null
        Since:
        100.4.0
      • generateGeodatabaseAsync

        @Deprecated
        public GenerateGeodatabaseJob generateGeodatabaseAsync​(GenerateGeodatabaseParameters params,
                                                               java.lang.String fileNameWithPath)
        Deprecated.
        Creates a GenerateGeodatabaseJob that can be used to generate a Geodatabase from the service using the specified parameters.
        Parameters:
        params - the parameters to be used for the generate geodatabase operation
        fileNameWithPath - full path, including filename, to which to write the geodatabase
        Returns:
        a GenerateGeodatabaseJob that will generate the geodatabase. The result is a Geodatabase object if the job completed successfully. Note you must call Job.start() to start the Job.
        Throws:
        java.lang.IllegalArgumentException - if params is null, or if fileNameWithPath is null or empty
        Since:
        100.0.0
      • generateGeodatabase

        public GenerateGeodatabaseJob generateGeodatabase​(GenerateGeodatabaseParameters params,
                                                          java.lang.String fileNameWithPath)
        Creates a GenerateGeodatabaseJob that can be used to generate a Geodatabase from the service using the specified parameters.
        Parameters:
        params - the parameters to be used for the generate geodatabase operation
        fileNameWithPath - full path, including filename, to which to write the geodatabase
        Returns:
        a GenerateGeodatabaseJob that will generate the geodatabase. The result is a Geodatabase object if the job completed successfully. Note you must call Job.start() to start the Job.
        Throws:
        java.lang.IllegalArgumentException - if params is null, or if fileNameWithPath is null or empty
        Since:
        100.4.0
      • syncGeodatabaseAsync

        @Deprecated
        public SyncGeodatabaseJob syncGeodatabaseAsync​(SyncGeodatabaseParameters params,
                                                       Geodatabase geodatabase)
        Deprecated.
        Creates a SyncGeodatabaseJob that will synchronize a geodatabase with the service. Synchronization can include sending feature edits made locally and retrieving feature edits made on the server. Only changes are sent/received during this process to ensure only the minimum required data is transferred.
        Parameters:
        params - the parameters to be used for the synchronize operation
        geodatabase - the geodatabase to be synchronized
        Returns:
        a SyncGeodatabaseJob that will synchronize the geodatabase. The result is a List (may be empty) of SyncLayerResult objects. Note you must call Job.start() to start the Job.
        Throws:
        java.lang.IllegalArgumentException - if params or geodatabase is null
        Since:
        100.0.0
      • syncGeodatabase

        public SyncGeodatabaseJob syncGeodatabase​(SyncGeodatabaseParameters.SyncDirection syncDirection,
                                                  boolean rollbackOnFailure,
                                                  Geodatabase geodatabase)
        Creates a SyncGeodatabaseJob to synchronize a geodatabase back to it's service using the given sync direction and a rollback on failure boolean value. If the given direction is not compatible with the service, the returned job will fail.

        Synchronization can include sending feature edits made locally and retrieving feature edits made on the server. Only changes are sent/received during this process to ensure only the minimum required data is transferred.

        Parameters:
        syncDirection - sync direction to use when syncing the geodatabase
        rollbackOnFailure - true to roll back (not apply) all the changes to the service and/or geodatabase if the job fails, false to accept the changes up until the point when the job fails
        geodatabase - the geodatabase to be synchronized
        Returns:
        a SyncGeodatabaseJob that will synchronize the geodatabase. The result is a List (may be empty) of SyncLayerResult objects. Note you must call Job.start() to start the Job.
        Throws:
        java.lang.IllegalArgumentException - if syncDirection or geodatabase are null
        Since:
        100.4.0
      • syncGeodatabase

        public SyncGeodatabaseJob syncGeodatabase​(SyncGeodatabaseParameters params,
                                                  Geodatabase geodatabase)
        Creates a SyncGeodatabaseJob that will synchronize a geodatabase with the service. Synchronization can include sending feature edits made locally and retrieving feature edits made on the server. Only changes are sent/received during this process to ensure only the minimum required data is transferred.
        Parameters:
        params - the parameters to be used for the synchronize operation
        geodatabase - the geodatabase to be synchronized
        Returns:
        a SyncGeodatabaseJob that will synchronize the geodatabase. The result is a List (may be empty) of SyncLayerResult objects. Note you must call Job.start() to start the Job.
        Throws:
        java.lang.IllegalArgumentException - if params or geodatabase is null
        Since:
        100.4.0
      • unregisterGeodatabaseAsync

        public ListenableFuture<java.lang.Void> unregisterGeodatabaseAsync​(Geodatabase geodatabase)
        Executes an asynchronous operation to unregister a geodatabase from the service. This removes the geodatabase's replica ID from the service which means it can no longer be synchronized.

        After unregistering a geodatabase it can no longer be synced back to the service. This is often used prior to deleting a local geodatabase. This operation is not related to registerSyncEnabledGeodatabaseAsync(Geodatabase), which is for registering copies of a sync enabled geodatabase.

        Parameters:
        geodatabase - the geodatabase to be unregistered
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
        • IOException if the network request fails
        Throws:
        java.lang.IllegalArgumentException - if geodatabase is null
        Since:
        100.0.0
      • unregisterGeodatabaseAsync

        public ListenableFuture<java.lang.Void> unregisterGeodatabaseAsync​(java.util.UUID syncId)
        Executes an asynchronous operation to unregister a geodatabase from the service using the sync ID. Note that this overload uses the geodatabase's sync ID rather than a reference to the geodatabase itself.

        This is commonly used to enable cleanup of the service after the local geodatabase has already been deleted. See Geodatabase.getSyncId(). After unregistering a geodatabase it can no longer be synced back to the service. This operation is not related to registerSyncEnabledGeodatabaseAsync(Geodatabase) which is for registering copies of a sync enabled geodatabase.

        Parameters:
        syncId - the syncID of geodatabase to unregister
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
        • IOException if the network request fails
        Throws:
        java.lang.IllegalArgumentException - if syncID is null
        Since:
        100.6.0
      • registerSyncEnabledGeodatabaseAsync

        public ListenableFuture<java.lang.Void> registerSyncEnabledGeodatabaseAsync​(Geodatabase geodatabase)
        Executes an asynchronous operation to register a existing sync enabled geodatabase (created by another client) with its original service so the geodatabase can be synchronized with the service.
        Parameters:
        geodatabase - the geodatabase to register
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. Calling get() on the returned future may throw an ExecutionException with its cause set to:
        • IOException if the network request fails
        Throws:
        java.lang.IllegalArgumentException - if geodatabase is null
        Since:
        100.0.0
      • importGeodatabaseDeltaAsync

        @Deprecated
        public ListenableFuture<java.util.List<SyncLayerResult>> importGeodatabaseDeltaAsync​(Geodatabase geodatabase,
                                                                                             java.lang.String deltaFilePath)
        Deprecated.
        As of 100.3.0, replaced by importDeltaAsync(Geodatabase, String).
        Executes an asynchronous operation to import a valid geodatabase delta and apply it to the given geodatabase. The result is a list of SyncLayerResult objects.
        Parameters:
        geodatabase - the geodatabase to apply a delta to
        deltaFilePath - a valid file name with path to apply the delta from
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation.
        Throws:
        java.lang.IllegalArgumentException - if the geodatabase or deltaFilePath is null, or if deltaFilePath is empty
        Since:
        100.0.0
        See Also:
        SyncLayerResult
      • importDeltaAsync

        public static ListenableFuture<java.util.List<SyncLayerResult>> importDeltaAsync​(Geodatabase geodatabase,
                                                                                         java.lang.String inputPath)
        Executes an asynchronous operation to import a geodatabase delta and apply it to the given geodatabase. The result is a list of SyncLayerResult objects.

        A delta geodatabase contains the changes that have occurred since a mobile replica Geodatabase was last-synchronized with the feature service. See Synchronize Replica.

        Parameters:
        geodatabase - the geodatabase to apply a delta to
        inputPath - the path and filename to import the delta from
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation.
        Throws:
        java.lang.IllegalArgumentException - if geodatabase or inputPath is null, or if inputPath is empty
        Since:
        100.3.0
        See Also:
        SyncLayerResult
      • exportDeltaAsync

        public static ListenableFuture<java.lang.Boolean> exportDeltaAsync​(Geodatabase geodatabase,
                                                                           java.lang.String outputPath)
        Executes an asynchronous operation to generate an upload delta geodatabase file containing all the changes since the last sync.

        A delta geodatabase contains the changes that have occurred since a mobile replica Geodatabase was last synchronized with the feature service. See Synchronize Replica for an overview of the delta files used in synchronization. An "upload" delta geodatabase contains the local edits, performed on the user's device, to be sent to the originating feature service.

        When you run this task, any local edits in the Geodatabase will be exported to the specified output path. The output path should include the full path and file name (ending in ".geodatabase") for the export.

        The delta file created by this method is not sent to the server and has no impact on any subsequent sync job. You can call this method repeatedly without affecting the state of the local geodatabase.

        The task returned by this method has a boolean result that indicates whether or not a delta geodatabase was created.

        You should not execute more than one sync on a particular geodatabase at the same time. This includes any operations that export or import deltas from the local Geodatabase:

        Parameters:
        geodatabase - the geodatabase to generate a delta from
        outputPath - the path and filename to save the generated delta to
        Returns:
        a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation. The result is a Boolean indicating whether a delta was generated or not.
        Throws:
        java.lang.IllegalArgumentException - if geodatabase is null
        java.lang.IllegalArgumentException - if outputPath is null or empty
        Since:
        100.10.0
        See Also:
        SyncGeodatabaseParameters.isKeepGeodatabaseDeltas()
      • getLoadStatus

        public LoadStatus getLoadStatus()
        Description copied from interface: Loadable
        Returns the LoadStatus of the loadable resource.
        Specified by:
        getLoadStatus in interface Loadable
        Returns:
        the LoadStatus of the loadable resource
      • cancelLoad

        public void cancelLoad()
        Description copied from interface: Loadable
        Cancels loading metadata for the object.

        Cancels loading the metadata if the object is loading, and always invokes the done loading listener.

        A load operation that is in progress (LoadStatus.LOADING state) can be cancelled by calling this method and the resource will transition from LoadStatus.LOADING to LoadStatus.FAILED_TO_LOAD state. If the load operation was successfully cancelled, a CancellationException will be returned from Loadable.getLoadError().

        Cancellation should be used carefully because all enqueued done loading listeners for that resource instance will get invoked with an error stating that the operation was cancelled. Thus, one component in the application can cancel the load operation initiated by other components.

        This method does nothing if the resource is not in LoadStatus.LOADING state.

        Specified by:
        cancelLoad in interface Loadable
      • loadAsync

        public void loadAsync()
        Description copied from interface: Loadable
        Loads the metadata of the loadable resource asynchronously.

        The load status changes from LoadStatus.NOT_LOADED to LoadStatus.LOADING. A listener can be added via Loadable.addDoneLoadingListener(java.lang.Runnable) that is invoked upon completion of the asynchronous load operation.

        If the load operation completes successfully, the load status will be LoadStatus.LOADED, which means the resource has loaded its metadata.

        If the load operation failed, the load status will be LoadStatus.FAILED_TO_LOAD and the error can be retrieved by calling Loadable.getLoadError().

        This method can be called concurrently and repeatedly, but only one attempt is ever made to perform the load operation. If a load operation is already in progress (LoadStatus.LOADING state) when loadAsync is called, it simply piggy-backs on the outstanding operation and the done loading listener added to the loadable resource is enqueued to be invoked when that operation completes. If the operation has already completed (LoadStatus.LOADED or LoadStatus.FAILED_TO_LOAD state) when loadAsync is called, the done loading listener is immediately invoked when added to the loadable resource.

        If a loadable resource has failed to load, calling loadAsync on it subsequently will not change its state. The done loading listener will be invoked immediately when added to the loadable resource. In order to retry loading the resource, Loadable.retryLoadAsync() needs to be used.

        A load operation that is in progress (LoadStatus.LOADING state) can be cancelled by calling Loadable.cancelLoad().

        Specified by:
        loadAsync in interface Loadable
      • retryLoadAsync

        public void retryLoadAsync()
        Description copied from interface: Loadable
        Loads or retries loading metadata for the object asynchronously.

        Will retry loading the metadata if the object's load status is LoadStatus.FAILED_TO_LOAD. Will load the object if it is not loaded. Will not retry to load the object if the object is loaded.

        For more details on the load process see Loadable.loadAsync().

        Specified by:
        retryLoadAsync in interface Loadable
      • addDoneLoadingListener

        public void addDoneLoadingListener​(java.lang.Runnable listener)
        Description copied from interface: Loadable
        Adds a listener to the loadable resource that is invoked when loading has completed.

        The listener may be added at any point, whether the loadable resource has already completed loading or not.

        • For resources that are not loaded when the listener is added (LoadStatus is NOT_LOADED or LOADING): When the resource completes loading, the listener will be invoked on the UI thread if it is added from the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.
        • For resources that are already loaded when the listener is added (LoadStatus is LOADED or FAILED_TO_LOAD): The listener will be called immediately, on the current thread.

        Alternatively, to be notified when there is any change in the load status, use the Loadable.addLoadStatusChangedListener(LoadStatusChangedListener) method instead.

        Specified by:
        addDoneLoadingListener in interface Loadable
        Parameters:
        listener - a Runnable that is invoked upon completion of the load operation
      • removeDoneLoadingListener

        public boolean removeDoneLoadingListener​(java.lang.Runnable listener)
        Description copied from interface: Loadable
        Removes a done loading listener from the loadable resource.
        Specified by:
        removeDoneLoadingListener in interface Loadable
        Parameters:
        listener - the listener to be removed
        Returns:
        true if the listener was removed, otherwise false
      • addLoadStatusChangedListener

        public void addLoadStatusChangedListener​(LoadStatusChangedListener listener)
        Description copied from interface: Loadable
        Adds a LoadStatusChangedListener to the loadable resource that is invoked whenever the load status changes.

        Adding this listener on the UI thread will cause it to be invoked on the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.

        The listener will not be called if added to a loadable resource that has already completed loading. To be notified when a loadable resource has completed loading, including if the resource is already loaded when the listener is added, use the Loadable.addDoneLoadingListener(Runnable) method.

        Specified by:
        addLoadStatusChangedListener in interface Loadable
        Parameters:
        listener - the LoadStatusChangedListener to be added
      • removeLoadStatusChangedListener

        public boolean removeLoadStatusChangedListener​(LoadStatusChangedListener listener)
        Description copied from interface: Loadable
        Removes a LoadStatusChangedListener from the loadable resource.
        Specified by:
        removeLoadStatusChangedListener in interface Loadable
        Parameters:
        listener - the LoadStatusChangedListener to be removed
        Returns:
        true if the listener was removed, otherwise false