Search in sources :

Example 6 with DatabaseIOException

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);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException) WorkerThread(androidx.annotation.WorkerThread)

Example 7 with DatabaseIOException

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);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 8 with DatabaseIOException

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);
    }
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 9 with DatabaseIOException

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);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 10 with DatabaseIOException

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();
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)13 DatabaseIOException (com.google.android.exoplayer2.database.DatabaseIOException)12 SQLException (android.database.SQLException)11 DownloadBuilder (com.google.android.exoplayer2.testutil.DownloadBuilder)7 Test (org.junit.Test)7 WorkerThread (androidx.annotation.WorkerThread)6 ContentValues (android.content.ContentValues)5 Cursor (android.database.Cursor)1 SQLiteException (android.database.sqlite.SQLiteException)1 HashMap (java.util.HashMap)1