Class Geodatabase

  • All Implemented Interfaces:
    Loadable

    public final class Geodatabase
    extends Object
    implements Loadable
    A mobile geodatabase containing offline feature data.

    The Geodatabase class is used for opening and accessing the contents of a mobile geodatabase. A geodatabase is either an offline copy of data from an ArcGIS service (created as a result of a GeodatabaseSyncTask), or can be created using ArcMap or ArcGIS Pro. The geodatabase contains one or more GeodatabaseFeatureTables. Each GeodatabaseFeatureTable contains attribute data. For spatial features, it also stores the geometry and rendering information.

    A GeodatabaseFeatureTable containing point, polyline or polygon features can be used to create a FeatureLayer. A GeodatabaseFeatureTable containing annotation features can be used to create an AnnotationLayer. Both of these layer types can be added to a map and viewed with a map view.

    Geodatabase implements the loadable interface; the geodatabase feature tables can be accessed after the geodatabase has been loaded.

    Since:
    100.0.0
    • Constructor Detail

      • Geodatabase

        public Geodatabase​(String geodatabasePath)
        Creates a new Geodatabase instance from a geodatabase at the given path.
        Parameters:
        geodatabasePath - path to geodatabase to be opened
        Throws:
        IllegalArgumentException - if geodatabasePath is null
        Since:
        100.0.0
    • Method Detail

      • getGeodatabaseFeatureTables

        public List<GeodatabaseFeatureTable> getGeodatabaseFeatureTables()
        Gets an unmodifiable list of the geodatabase feature tables that contain geometries such as points, lines or polygons.

        The results will not include feature tables containing annotation features. The list will be empty if the Geodatabase itself is not loaded.

        Returns:
        the geodatabase feature tables that contain geometries
        Since:
        100.0.0
        See Also:
        getGeodatabaseAnnotationTables()
      • getGeodatabaseFeatureTable

        public GeodatabaseFeatureTable getGeodatabaseFeatureTable​(String name)
        Gets a feature table containing point, line or polygon features from the geodatabase, as specified by the given name.
        Parameters:
        name - the name of the geodatabase feature table
        Returns:
        the specified geodatabase feature table, or null if the specified table does not exist or contains annotation feature data
        Since:
        100.0.0
        See Also:
        getGeodatabaseAnnotationTable(String)
      • getGeodatabaseFeatureTableByServiceLayerId

        public GeodatabaseFeatureTable getGeodatabaseFeatureTableByServiceLayerId​(int layerId)
        Gets a feature table from the geodatabase containing point, line or polygon features, as specified by the given service layer ID. The ID must match ArcGISFeatureLayerInfo.getServiceLayerId().
        Parameters:
        layerId - the service layer ID of the geodatabase feature table
        Returns:
        the specified geodatabase feature table, or null if the specified table does not exist or contains annotation feature data
        Since:
        100.0.0
        See Also:
        getGeodatabaseAnnotationTableByServiceLayerId(int)
      • getGeodatabaseAnnotationTables

        public List<GeodatabaseFeatureTable> getGeodatabaseAnnotationTables()
        Gets an unmodifiable list of the geodatabase feature tables that contain annotation features.

        The results will not include feature tables that contain geometries such as points, lines or polygons. The list will be empty if the Geodatabase itself is not loaded.

        Returns:
        the geodatabase feature tables that contain annotation features
        Since:
        100.6.0
        See Also:
        getGeodatabaseFeatureTables()
      • getGeodatabaseAnnotationTable

        public GeodatabaseFeatureTable getGeodatabaseAnnotationTable​(String name)
        Gets a feature table containing annotation features from the geodatabase, as specified by the given name.
        Parameters:
        name - the name of the geodatabase feature table
        Returns:
        the specified geodatabase feature table, or null if the specified table does not exist or does not contain annotation feature data
        Since:
        100.6.0
        See Also:
        getGeodatabaseFeatureTable(String)
      • getGeodatabaseAnnotationTableByServiceLayerId

        public GeodatabaseFeatureTable getGeodatabaseAnnotationTableByServiceLayerId​(int layerId)
        Gets a feature table containing annotation features from the geodatabase, as specified by the given service layer ID. The ID must match ArcGISFeatureLayerInfo.getServiceLayerId().
        Parameters:
        layerId - the service layer ID of the geodatabase feature table
        Returns:
        the specified geodatabase feature table, or null if the specified table does not exist or does not contain annotation feature data
        Since:
        100.6.0
        See Also:
        getGeodatabaseFeatureTableByServiceLayerId(int)
      • hasLocalEdits

        public boolean hasLocalEdits()
        Indicates if the geodatabase has been edited locally.
        Returns:
        true if there are local edits, false otherwise
        Since:
        100.0.0
      • getServiceUrl

        public String getServiceUrl()
        Gets the URL of the service the geodatabase was created from.
        Returns:
        URL of the service the geodatabase was created from
        Since:
        100.0.0
      • getSyncId

        public UUID getSyncId()
        Gets the sync ID of the geodatabase. The geodatabase's sync ID is the same as the replica ID described in the REST documentation. This is used by the service that created the geodatabase to uniquely identify it when carrying out sync operations. It can also be used when unregistering the geodatabase if it has already been deleted locally. See GeodatabaseSyncTask.unregisterGeodatabaseAsync(UUID).
        Returns:
        Sync ID of the given geodatabase or null if there is an error. Will also return null if this is not a sync enabled geodatabase or if the geodatabase is not loaded.
        Since:
        100.6.0
      • getSyncModel

        public SyncModel getSyncModel()
        Gets the sync model of the geodatabase. This was set when the geodatabase was created and determines how updates can be synced with the service. If the sync model is PER_GEODATABASE, layers cannot be synced independently: the whole geodatabase must be synced in one operation.

        If the sync model is PER_LAYER, layers can be synced independently of one another.

        Returns:
        the geodatabase's sync model
        Since:
        100.0.0
      • isSyncEnabled

        public boolean isSyncEnabled()
        Indicates if sync is enabled for the geodatabase. If this is true, the geodatabase can be synced with the service it was created from.
        Returns:
        true if sync is enabled, false otherwise
        Since:
        100.0.0
      • getGenerateGeodatabaseExtent

        public Envelope getGenerateGeodatabaseExtent()
        Gets the extent used to generate the sync enabled geodatabase.

        Use this to restrict editing of layers to within this extent.

        Returns:
        the extent used to generate the sync enabled geodatabase, or null if the geodatabase is not sync enabled
        Since:
        100.0.0
      • getPath

        public String getPath()
        Returns the geodatabase path.
        Returns:
        the geodatabase path
        Since:
        100.2.0
      • close

        public void close()
        Closes this geodatabase.

        After closing, the geodatabase file can be safely deleted or moved.

        Any operation on a closed geodatabase will result in undefined behavior - it may succeed or throw exceptions. So make sure that a closed geodatabase is no longer in use from, for example, feature layers, feature tables, geodatabase sync tasks, etc.

        Since:
        100.1.0
      • isInTransaction

        public boolean isInTransaction()
        Gets whether a transaction is active on the geodatabase.
        Returns:
        true if a transaction is active on the geodatabase, otherwise false
        Since:
        100.2.0
      • beginTransaction

        public void beginTransaction()
        Starts a new transaction on the geodatabase.

        An exception will be thrown if another transaction is already active on the geodatabase. A geodatabase cannot be synchronized while a transaction is active.

        Since:
        100.2.0
      • commitTransaction

        public void commitTransaction()
        Commits the current transaction on the geodatabase.

        Commit changes in the current transaction to the geodatabase. This will also end the transaction. An exception will be thrown if a transaction has not been started on the geodatabase.

        Since:
        100.2.0
      • rollbackTransaction

        public void rollbackTransaction()
        Rollback the current transaction on the geodatabase.

        Discard changes in the current transaction from the geodatabase. This will also end the transaction. An exception will be thrown if a transaction has not been started on the geodatabase.

        Since:
        100.2.0
      • getMinServerGeneration

        public long getMinServerGeneration()
        Returns the minimum server generation number for the geodatabase.

        Server generation numbers indicate the state of a geodatabase (or individual layers) with respect to changes which have been synced with the online service. The number increases as new changes from the online feature service are synced to the local geodatabase. If getSyncModel() is SyncModel.PER_GEODATABASE, the value will indicate the server generation number for the entire geodatabase. If the getSyncModel() is SyncModel.PER_LAYER, the value will be the lowest server generation number for all of the layers in the geodatabase. This property will be -1 if the geodatabase does not support sync (SyncModel.NONE).

        This property will be -1 until the geodatabase is LoadStatus.LOADED.

        Note that this property is only required when using advanced workflows to manually apply pre-generated changes and not when performing a sync directly against the online service.

        Returns:
        the minimum server generation number for the geodatabase
        Since:
        100.6.0
      • 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
      • getLoadError

        public ArcGISRuntimeException getLoadError()
        Description copied from interface: Loadable
        Returns the most recent error that was encountered when the loadable resource transitioned to the LoadStatus.FAILED_TO_LOAD state, either due to calling loadAsync or retryLoadAsync.

        If the resource subsequently transitions to LoadStatus.LOADED, for example if a call to retryLoadAsync completes successfully, the error is cleared out.

        Specified by:
        getLoadError in interface Loadable
        Returns:
        the most recent error that was encountered when the loadable resource transitioned to the LoadStatus.FAILED_TO_LOAD state.
      • cancelLoad

        public void cancelLoad()
        Description copied from interface: Loadable
        Cancels a pending load operation.

        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
        Tries to reload the metadata of the loadable resource asynchronously, but only if the resource failed to load previously (LoadStatus.FAILED_TO_LOAD state) or wasn't loaded to begin with ( LoadStatus.NOT_LOADED state).

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

        Specified by:
        retryLoadAsync in interface Loadable
      • addDoneLoadingListener

        public void addDoneLoadingListener​(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​(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