com.brightcove.player.edge

## Class OfflineStoreManager

- java.lang.Object
- - com.brightcove.player.store.BaseStore
  - - com.brightcove.player.edge.OfflineStoreManager

-     public class OfflineStoreManager
      extends BaseStore

  Store manager can be used to persist data into an application specific private database.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `OfflineStoreManager.CanChangeDownloadIdentifier` Any method attempting to call `changeDownloadIdentifier(Video)` must be annotated explicitly with this annotation.

  - ### Field Summary

    - ### Fields inherited from class com.brightcove.player.store.BaseStore

      `context, dataStore, MAX_SQL_EXPRESSIONS, MAX_SQL_VARIABLES, source`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `com.brightcove.player.store.DownloadRequestSet` | `addDownloadRequests(com.brightcove.player.store.DownloadRequestSet requestSet, IDownloadManager.IRequest... requests)` Creates a new blank download request set.
    `com.brightcove.player.store.OfflineVideo` | `changeDownloadIdentifier(Video video)` Changes the download identifier associated with given video.
    `int` | `countDownloadRequestsInState(java.lang.Long requestSetKey, int statusCode)` Counts the download requests belonging to a DownloadRequestSet with the specified status code.
    `com.brightcove.player.store.DownloadRequestSet` | `createDownloadRequestSet(RequestConfig requestConfig, long estimatedSize)` Creates a new blank download request set.
    `boolean` | `deleteDownloadRequestSet(java.lang.Long key)` Deletes the specified request set from the store.
    `boolean` | `deleteOfflineVideo(java.lang.String videoId)` Deletes the first offline video entity with the given video identifier.
    `java.util.List<com.brightcove.player.store.OfflineVideo>` | `findAllOfflineVideo()` Finds all offline video entities.
    `java.util.List<com.brightcove.player.store.OfflineVideo>` | `findAllOfflineVideo(int status)` Finds all offline video entities with the specified status
    `java.util.List<com.brightcove.player.store.DownloadRequest>` | `findCurrentDownloadBatchInProgress(int batchSize)` Finds the current set of download request which are still being processed.
    `java.util.List<com.brightcove.player.store.DownloadRequestSet>` | `findCurrentDownloadRequestSetInProgress()` Finds the current set of download request set which are still being processed.
    `com.brightcove.player.store.DownloadRequestSet` | `findDownloadRequestSetByKey(java.lang.Long key)` Finds a download request set with the specified unique key.
    `java.util.Collection<com.brightcove.player.store.DownloadRequestSet>` | `findDownloadRequestSets(java.lang.Long... requestIds)` Finds the download request sets to which the given requests belong to.
    `java.util.List<com.brightcove.player.store.DownloadRequest>` | `findDownloadsToBeQueued(int batchSize, boolean excludeWifiOnly)` Fetches a list of download requests that not have been queued for download by the `DownloadManager`.
    `android.net.Uri` | `findOfflineAssetUri(android.net.Uri uri)` Finds the local URI of a remote asset that has been downloaded successfully.
    `com.brightcove.player.store.OfflineVideo` | `findOfflineVideo(java.lang.String videoId)` Finds the first offline video entity with the given video identifier.
    `static OfflineStoreManager` | `getInstance(android.content.Context context)` Gets reference to the single instance of `OfflineStoreManager`
    `boolean` | `isCurrentDownloadBatchInProgress()` Checks if the current set of download request are still being processed.
    `boolean` | `isDownloadCompleted(java.lang.Long requestSetKey)` Checks if the DownloadRequestSet is completed.
    `java.util.List<com.brightcove.player.store.DownloadRequest>` | `markRequestSetForRemoval(java.lang.Long key)` Marks the specified request set for removal.
    `java.util.List<com.brightcove.player.store.DownloadRequest>` | `pauseDownloadRequestSet(java.lang.Long key)` Marks a download request set as paused.
    `<E extends IdentifiableEntity> E` | `refreshEntity(E entity)` Refresh the given entity.
    `com.brightcove.player.store.DownloadRequestSet` | `resumeDownloadRequestSet(java.lang.Long key)` Marks a download request set as waiting to be queued.
    `<T extends IdentifiableEntity> T` | `saveEntity(T entity)` Inserts or updates the given entity.
    `com.brightcove.player.store.OfflineVideo` | `saveOfflineLicense(Video video)` Updates the entity with given unique video identifier to save the video license information.
    `com.brightcove.player.store.OfflineVideo` | `saveOfflineVideo(Video video)` Updates the entity with given unique video identifier to save the video metadata object, while retaining the previously saved license information.
    `com.brightcove.player.store.OfflineVideo` | `saveOfflineVideo(Video video, java.io.File downloadDirectory, com.brightcove.player.store.DownloadRequestSet requestSet)` Saves the offline video information into the store.
    `static java.util.List<Video>` | `toVideoList(java.util.List<com.brightcove.player.store.OfflineVideo> entityList)` Converts the given list of `OfflineVideo` objects into a list of `Video` objects.
    `boolean` | `updateDownloadId(java.lang.Long key, java.lang.Long downloadId)` Sets the download identifier for the request with the specified primary key.
    `com.brightcove.player.store.OfflineVideo` | `updateDownloadRequestIdList(java.lang.String videoId, java.util.List<java.lang.Long> requestIdList, long estimatedSize)` Updates the entity with given unique video identifier to save the current list of download request identifiers.
    `boolean` | `updateDownloadRequestSetStatus(com.brightcove.player.store.DownloadRequestSet requestSet, int statusCode, int reasonCode, com.brightcove.player.store.DownloadRequest downloadRequest, boolean evaluateAllSegments)` Updates the status of Download Request Set.
    `com.brightcove.player.store.DownloadRequest` | `updateDownloadRequestStatusByDownloadId(java.lang.Long downloadId, int statusCode, int reasonCode, long bytesDownloaded, long actualSize, boolean updateParentRecord)` Updates the status of download request.

    - ### Methods inherited from class com.brightcove.player.store.BaseStore

      `compact, deleteEntity, getDefaultDatabaseName, getDefaultDatabasePassword, getFileSize, onCreated, onUpgraded`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getInstance

          public static OfflineStoreManager getInstance(@NonNull
                                                        android.content.Context context)

      Gets reference to the single instance of `OfflineStoreManager`
      Parameters:
        `context` - reference to the host application context.
      Returns:
        reference to the `OfflineStoreManager`

    - #### refreshEntity

          @Nullable
          public <E extends IdentifiableEntity> E refreshEntity(@Nullable
                                                                          E entity)

      Refresh the given entity. This refreshes the already loaded properties in the entity. If no properties are loaded then the default properties will be loaded.
      Overrides:
        `refreshEntity` in class `BaseStore`
      Type Parameters:
        `E` - the expected type of the entity;
      Parameters:
        `entity` - reference to the entity to be refreshed.
      Returns:
        null if the entity is null or if it does not exist in the store, otherwise reference to the updated entity

    - #### saveEntity

          public <T extends IdentifiableEntity> T saveEntity(@NonNull
                                                             T entity)

      Inserts or updates the given entity.
      Overrides:
        `saveEntity` in class `BaseStore`
      Parameters:
        `entity` - the entity to be save.
      Returns:
        the updated the entity.;

    - #### updateDownloadRequestIdList

          @Nullable
          public com.brightcove.player.store.OfflineVideo updateDownloadRequestIdList(@NonNull
                                                                                                java.lang.String videoId,
                                                                                                @Nullable
                                                                                                java.util.List<java.lang.Long> requestIdList,
                                                                                                long estimatedSize)

      Updates the entity with given unique video identifier to save the current list of download request identifiers.
      Parameters:
        `videoId` - the unique video identifier.
        `requestIdList` - a list of download request identifiers.
      Returns:
        null if an entity with specified video identifier was found, otherwise reference to the updated entity.

    - #### saveOfflineVideo

          public com.brightcove.player.store.OfflineVideo saveOfflineVideo(@NonNull
                                                                           Video video,
                                                                           @NonNull
                                                                           java.io.File downloadDirectory,
                                                                           @NonNull
                                                                           com.brightcove.player.store.DownloadRequestSet requestSet)

      Saves the offline video information into the store.
      Parameters:
        `video` - the video information to be saved.
        `downloadDirectory` - the download directory for this video.
        `requestSet` - the download request set related to this video.
      Returns:
        reference to the newly created entity.

    - #### saveOfflineVideo

          @NonNull
          public com.brightcove.player.store.OfflineVideo saveOfflineVideo(Video video)

      Updates the entity with given unique video identifier to save the video metadata object, while retaining the previously saved license information.
      Parameters:
        `video` - the video to be saved.
      Returns:
        reference to the updated entity.
      See Also:
        `saveOfflineLicense(Video)`

    - #### saveOfflineLicense

          @NonNull
          public com.brightcove.player.store.OfflineVideo saveOfflineLicense(@NonNull
                                                                                      Video video)

      Updates the entity with given unique video identifier to save the video license information.
      Parameters:
        `video` - the video to be saved.
      Returns:
        reference to the updated entity.
      See Also:
        `saveOfflineVideo(Video)`

    - #### findOfflineVideo

          @Nullable
          public com.brightcove.player.store.OfflineVideo findOfflineVideo(@NonNull
                                                                                     java.lang.String videoId)

      Finds the first offline video entity with the given video identifier.
      Parameters:
        `videoId` - the unique video identifier.
      Returns:
        null if there is no offline entity with the given identifier, otherwise reference to first matching entity.

    - #### findAllOfflineVideo

          @NonNull
          public java.util.List<com.brightcove.player.store.OfflineVideo> findAllOfflineVideo()

      Finds all offline video entities.
      Returns:
        a list of offline video entities.

    - #### findAllOfflineVideo

          @NonNull
          public java.util.List<com.brightcove.player.store.OfflineVideo> findAllOfflineVideo(int status)

      Finds all offline video entities with the specified status
      Returns:
        a list of offline video entities.

    - #### deleteOfflineVideo

          public boolean deleteOfflineVideo(@NonNull
                                            java.lang.String videoId)

      Deletes the first offline video entity with the given video identifier.
      Parameters:
        `videoId` - the unique video identifier.
      Returns:
        true if a matching entity was found and deleted, otherwise false.

    - #### createDownloadRequestSet

          @NonNull
          public com.brightcove.player.store.DownloadRequestSet createDownloadRequestSet(@Nullable
                                                                                                  RequestConfig requestConfig,
                                                                                                  long estimatedSize)

      Creates a new blank download request set.
      Returns:
        reference to the newly created entity

    - #### addDownloadRequests

          @NonNull
          public com.brightcove.player.store.DownloadRequestSet addDownloadRequests(@NonNull
                                                                                             com.brightcove.player.store.DownloadRequestSet requestSet,
                                                                                             @NonNull
                                                                                             IDownloadManager.IRequest... requests)

      Creates a new blank download request set.
      Returns:
        reference to the newly created entity

    - #### findDownloadRequestSetByKey

          @Nullable
          public com.brightcove.player.store.DownloadRequestSet findDownloadRequestSetByKey(@NonNull
                                                                                                      java.lang.Long key)

      Finds a download request set with the specified unique key.
      Parameters:
        `key` - the primary key of the request set.
      Returns:
        null if the entity was not found, otherwise reference to the entity.

    - #### findOfflineAssetUri

          @Nullable
          public android.net.Uri findOfflineAssetUri(@Nullable
                                                               android.net.Uri uri)

      Finds the local URI of a remote asset that has been downloaded successfully.
      Parameters:
        `uri` - the remote URI to the asset.
      Returns:
        null if the asset is not available, otherwise URI to the local copy of the asset.

    - #### findDownloadRequestSets

          public java.util.Collection<com.brightcove.player.store.DownloadRequestSet> findDownloadRequestSets(@NonNull
                                                                                                              java.lang.Long... requestIds)

      Finds the download request sets to which the given requests belong to.
      Parameters:
        `requestIds` - an array of one or more download requests.
      Returns:
        a list of download request sets.

    - #### deleteDownloadRequestSet

          public boolean deleteDownloadRequestSet(@NonNull
                                                  java.lang.Long key)

      Deletes the specified request set from the store.
      Parameters:
        `key` - the primary key of the request set to be deleted.
      Returns:
        true if a matching entity was found and deleted, otherwise false.

    - #### updateDownloadRequestStatusByDownloadId

          @Nullable
          public com.brightcove.player.store.DownloadRequest updateDownloadRequestStatusByDownloadId(@NonNull
                                                                                                               java.lang.Long downloadId,
                                                                                                               int statusCode,
                                                                                                               int reasonCode,
                                                                                                               long bytesDownloaded,
                                                                                                               long actualSize,
                                                                                                               boolean updateParentRecord)

      Updates the status of download request.
      Parameters:
        `downloadId` - the unique identifier of the download request that caused the status change.
        `statusCode` - the new status of the download.
        `reasonCode` - the reason code for the new status, if any.
        `bytesDownloaded` - the number of bytes downloaded so far.
        `actualSize` - the total size of the download.
        `updateParentRecord` - true to update the DownloadRequestSet parent record.
      Returns:
        reference to the updated entity if it was found and updated, otherwise null.

    - #### updateDownloadRequestSetStatus

          public boolean updateDownloadRequestSetStatus(com.brightcove.player.store.DownloadRequestSet requestSet,
                                                        int statusCode,
                                                        int reasonCode,
                                                        com.brightcove.player.store.DownloadRequest downloadRequest,
                                                        boolean evaluateAllSegments)

      Updates the status of Download Request Set.
      Parameters:
        `requestSet` - the Download Request Set
        `statusCode` - the new status of the download segment.
        `reasonCode` - the reason code for the new status, if any.
        `downloadRequest` - the new segment Download Request
        `evaluateAllSegments` - if true, it makes sure to evaluate all download request segments to get the overall status.
      Returns:
        true if updated.

    - #### pauseDownloadRequestSet

          @NonNull
          public java.util.List<com.brightcove.player.store.DownloadRequest> pauseDownloadRequestSet(@NonNull
                                                                                                              java.lang.Long key)

      Marks a download request set as paused.
      Parameters:
        `key` - the primary key of the request set to be paused.
      Returns:
        a list of download requests that have to be removed from the active download queue.

    - #### resumeDownloadRequestSet

          @Nullable
          public com.brightcove.player.store.DownloadRequestSet resumeDownloadRequestSet(@NonNull
                                                                                                   java.lang.Long key)

      Marks a download request set as waiting to be queued.
      Parameters:
        `key` - the primary key of the request set to be paused.
      Returns:
        null if the request set was not found, otherwise reference to the updated request set.

    - #### updateDownloadId

          public boolean updateDownloadId(@NonNull
                                          java.lang.Long key,
                                          java.lang.Long downloadId)

      Sets the download identifier for the request with the specified primary key.
      Parameters:
        `key` - the primary key of the request to be updated.
        `downloadId` - the unique identifier to the download request in the `DownloadManager`
      Returns:
        true if the entity was found and updated, otherwise false.

    - #### changeDownloadIdentifier

          @Nullable
          public com.brightcove.player.store.OfflineVideo changeDownloadIdentifier(@NonNull
                                                                                             Video video)

      Changes the download identifier associated with given video. This method is intended for internal use only. Please do not call this in the application project.
      Parameters:
        `video` - reference to the video.
      Returns:
        the offline video entity associated with this video, if any.

    - #### markRequestSetForRemoval

          @NonNull
          public java.util.List<com.brightcove.player.store.DownloadRequest> markRequestSetForRemoval(@NonNull
                                                                                                               java.lang.Long key)

      Marks the specified request set for removal. A request set that has been marked for removal will not be queued or checked for further status changes. Any download requests in the set that has been queued already will be removed. The request set itself will be deleted once all the requests have been removed.
      Parameters:
        `key` - the primary key of the request set to be updated.
      Returns:
        a list download requests that must be removed from the download queue.

    - #### findDownloadsToBeQueued

          @NonNull
          public java.util.List<com.brightcove.player.store.DownloadRequest> findDownloadsToBeQueued(int batchSize,
                                                                                                              boolean excludeWifiOnly)

      Fetches a list of download requests that not have been queued for download by the `DownloadManager`.
      Parameters:
        `batchSize` - the maximum number of entities to fetch.
        `excludeWifiOnly` - true if the requests that allowed only on wifi networks must be excluded, otherwise false.
      Returns:
        a list of pending download requests.

    - #### isCurrentDownloadBatchInProgress

          public boolean isCurrentDownloadBatchInProgress()

      Checks if the current set of download request are still being processed.
      Returns:
        true if the current set of download request are still being processed, otherwise false.

    - #### countDownloadRequestsInState

          public int countDownloadRequestsInState(@NonNull
                                                  java.lang.Long requestSetKey,
                                                  int statusCode)

      Counts the download requests belonging to a DownloadRequestSet with the specified status code.
      Parameters:
        `requestSetKey` - the Download Request Set key.
        `statusCode` - the status code.
      Returns:
        the count.

    - #### isDownloadCompleted

          public boolean isDownloadCompleted(@NonNull
                                             java.lang.Long requestSetKey)

      Checks if the DownloadRequestSet is completed.
      Parameters:
        `requestSetKey` - the Download Request Set key.
      Returns:
        true is download is completed.

    - #### findCurrentDownloadBatchInProgress

          public java.util.List<com.brightcove.player.store.DownloadRequest> findCurrentDownloadBatchInProgress(int batchSize)

      Finds the current set of download request which are still being processed.
      Parameters:
        `batchSize` - the maximum number of entities to fetch
      Returns:
        a list of download requests

    - #### findCurrentDownloadRequestSetInProgress

          public java.util.List<com.brightcove.player.store.DownloadRequestSet> findCurrentDownloadRequestSetInProgress()

      Finds the current set of download request set which are still being processed.
      Returns:
        a list of download request sets

    - #### toVideoList

          public static java.util.List<Video> toVideoList(@NonNull
                                                          java.util.List<com.brightcove.player.store.OfflineVideo> entityList)

      Converts the given list of `OfflineVideo` objects into a list of `Video` objects.
      Parameters:
        `entityList` - the list to be converted.
      Returns:
        the converted list.