Search in sources :

Example 1 with DatabaseIOException

use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.

the class DefaultDownloadIndex method putDownload.

@Override
public void putDownload(Download download) throws DatabaseIOException {
    ensureInitialized();
    try {
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        putDownloadInternal(download, writableDatabase);
    } catch (SQLiteException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteException(android.database.sqlite.SQLiteException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException)

Example 2 with DatabaseIOException

use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.

the class DefaultDownloadIndex method setStopReason.

@Override
public void setStopReason(String id, int stopReason) throws DatabaseIOException {
    ensureInitialized();
    try {
        ContentValues values = new ContentValues();
        values.put(COLUMN_STOP_REASON, stopReason);
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        writableDatabase.update(tableName, values, WHERE_STATE_IS_TERMINAL + " AND " + WHERE_ID_EQUALS, new String[] { id });
    } catch (SQLException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException)

Example 3 with DatabaseIOException

use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.

the class DefaultDownloadIndex method setStatesToRemoving.

@Override
public void setStatesToRemoving() throws DatabaseIOException {
    ensureInitialized();
    try {
        ContentValues values = new ContentValues();
        values.put(COLUMN_STATE, Download.STATE_REMOVING);
        // Only downloads in STATE_FAILED are allowed a failure reason, so we need to clear it here in
        // case we're moving downloads from STATE_FAILED to STATE_REMOVING.
        values.put(COLUMN_FAILURE_REASON, Download.FAILURE_REASON_NONE);
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        writableDatabase.update(tableName, values, /* whereClause= */
        null, /* whereArgs= */
        null);
    } catch (SQLException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException)

Example 4 with DatabaseIOException

use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.

the class DefaultDownloadIndex method setDownloadingStatesToQueued.

@Override
public void setDownloadingStatesToQueued() throws DatabaseIOException {
    ensureInitialized();
    try {
        ContentValues values = new ContentValues();
        values.put(COLUMN_STATE, Download.STATE_QUEUED);
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        writableDatabase.update(tableName, values, WHERE_STATE_IS_DOWNLOADING, /* whereArgs= */
        null);
    } catch (SQLException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException)

Example 5 with DatabaseIOException

use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.

the class CacheFileMetadataIndex method remove.

/**
 * Removes metadata.
 *
 * <p>This method may be slow and shouldn't normally be called on the main thread.
 *
 * @param name The name of the file whose metadata is to be removed.
 * @throws DatabaseIOException If an error occurs removing the metadata.
 */
@WorkerThread
public void remove(String name) throws DatabaseIOException {
    Assertions.checkNotNull(tableName);
    try {
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        writableDatabase.delete(tableName, WHERE_NAME_EQUALS, new String[] { name });
    } 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)

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