use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.
the class CacheFileMetadataIndex method removeAll.
/**
* Removes metadata.
*
* <p>This method may be slow and shouldn't normally be called on the main thread.
*
* @param names The names of the files whose metadata is to be removed.
* @throws DatabaseIOException If an error occurs removing the metadata.
*/
@WorkerThread
public void removeAll(Set<String> names) throws DatabaseIOException {
Assertions.checkNotNull(tableName);
try {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransactionNonExclusive();
try {
for (String name : names) {
writableDatabase.delete(tableName, WHERE_NAME_EQUALS, new String[] { name });
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
} catch (SQLException e) {
throw new DatabaseIOException(e);
}
}
use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.
the class DefaultDownloadIndexTest method putDownload_setsVersion.
@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);
}
use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.
the class DefaultDownloadIndexTest method getDownloads_withStates_returnsAllDownloadStatusWithTheSameStates.
@Test
public void getDownloads_withStates_returnsAllDownloadStatusWithTheSameStates() throws DatabaseIOException {
Download download1 = new DownloadBuilder("id1").setStartTimeMs(0).setState(Download.STATE_REMOVING).build();
downloadIndex.putDownload(download1);
Download download2 = new DownloadBuilder("id2").setStartTimeMs(1).setState(STATE_STOPPED).build();
downloadIndex.putDownload(download2);
Download download3 = new DownloadBuilder("id3").setStartTimeMs(2).setState(Download.STATE_COMPLETED).build();
downloadIndex.putDownload(download3);
try (DownloadCursor cursor = downloadIndex.getDownloads(Download.STATE_REMOVING, Download.STATE_COMPLETED)) {
assertThat(cursor.getCount()).isEqualTo(2);
cursor.moveToNext();
assertEqual(cursor.getDownload(), download1);
cursor.moveToNext();
assertEqual(cursor.getDownload(), download3);
}
}
use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.
the class DefaultDownloadIndexTest method addAndGetDownload_nonExistingId_returnsTheSameDownload.
@Test
public void addAndGetDownload_nonExistingId_returnsTheSameDownload() throws DatabaseIOException {
String id = "id";
Download download = new DownloadBuilder(id).build();
downloadIndex.putDownload(download);
Download readDownload = downloadIndex.getDownload(id);
assertEqual(readDownload, download);
}
use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.
the class DefaultDownloadIndexTest method removeDownload_existingId_getDownloadReturnsNull.
@Test
public void removeDownload_existingId_getDownloadReturnsNull() throws DatabaseIOException {
String id = "id";
Download download = new DownloadBuilder(id).build();
downloadIndex.putDownload(download);
downloadIndex.removeDownload(id);
Download readDownload = downloadIndex.getDownload(id);
assertThat(readDownload).isNull();
}
Aggregations