@Test public void putDownload_setsVersion() throws DatabaseIOException { SQLiteDatabase readableDatabase = databaseProvider.getReadableDatabase(); assertThat(VersionTable.getVersion(readableDatabase, VersionTable.FEATURE_OFFLINE, EMPTY_NAME)) .isEqualTo(VersionTable.VERSION_UNSET); downloadIndex.putDownload(new DownloadBuilder("id1").build()); assertThat(VersionTable.getVersion(readableDatabase, VersionTable.FEATURE_OFFLINE, EMPTY_NAME)) .isEqualTo(DefaultDownloadIndex.TABLE_VERSION); }
@Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
DefaultDownloadIndex implements WritableDownloadIndex { @Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } } }
DefaultDownloadIndex implements WritableDownloadIndex { @Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } } DefaultDownloadIndex(DatabaseProvider databaseProvider);  DefaultDownloadIndex(DatabaseProvider databaseProvider, String name); }
DefaultDownloadIndex implements WritableDownloadIndex { @Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } } DefaultDownloadIndex(DatabaseProvider databaseProvider);  DefaultDownloadIndex(DatabaseProvider databaseProvider, String name); @Override @Nullable Download getDownload(String id); @Override DownloadCursor getDownloads(@Download.State int... states); @Override void putDownload(Download download); @Override void removeDownload(String id); @Override void setDownloadingStatesToQueued(); @Override void setStopReason(int stopReason); @Override void setStopReason(String id, int stopReason); }
DefaultDownloadIndex implements WritableDownloadIndex { @Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } } DefaultDownloadIndex(DatabaseProvider databaseProvider);  DefaultDownloadIndex(DatabaseProvider databaseProvider, String name); @Override @Nullable Download getDownload(String id); @Override DownloadCursor getDownloads(@Download.State int... states); @Override void putDownload(Download download); @Override void removeDownload(String id); @Override void setDownloadingStatesToQueued(); @Override void setStopReason(int stopReason); @Override void setStopReason(String id, int stopReason);  }