Search in sources :

Example 41 with DatabaseIOException

use of androidx.media3.database.DatabaseIOException in project media by androidx.

the class CacheFileMetadataIndex method getAll.

/**
 * Returns all file metadata keyed by file name. The returned map is mutable and may be modified
 * by the caller.
 *
 * <p>This method may be slow and shouldn't normally be called on the main thread.
 *
 * @return The file metadata keyed by file name.
 * @throws DatabaseIOException If an error occurs loading the metadata.
 */
@WorkerThread
public Map<String, CacheFileMetadata> getAll() throws DatabaseIOException {
    try (Cursor cursor = getCursor()) {
        Map<String, CacheFileMetadata> fileMetadata = new HashMap<>(cursor.getCount());
        while (cursor.moveToNext()) {
            String name = checkNotNull(cursor.getString(COLUMN_INDEX_NAME));
            long length = cursor.getLong(COLUMN_INDEX_LENGTH);
            long lastTouchTimestamp = cursor.getLong(COLUMN_INDEX_LAST_TOUCH_TIMESTAMP);
            fileMetadata.put(name, new CacheFileMetadata(length, lastTouchTimestamp));
        }
        return fileMetadata;
    } catch (SQLException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(android.database.SQLException) Cursor(android.database.Cursor) DatabaseIOException(androidx.media3.database.DatabaseIOException) WorkerThread(androidx.annotation.WorkerThread)

Example 42 with DatabaseIOException

use of androidx.media3.database.DatabaseIOException in project media by androidx.

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(androidx.media3.database.DatabaseIOException) WorkerThread(androidx.annotation.WorkerThread)

Example 43 with DatabaseIOException

use of androidx.media3.database.DatabaseIOException in project media by androidx.

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(androidx.media3.database.DatabaseIOException)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)35 SQLException (android.database.SQLException)33 DatabaseIOException (com.google.android.exoplayer2.database.DatabaseIOException)24 WorkerThread (androidx.annotation.WorkerThread)18 ContentValues (android.content.ContentValues)16 DatabaseIOException (androidx.media3.database.DatabaseIOException)12 DownloadBuilder (androidx.media3.test.utils.DownloadBuilder)7 Test (org.junit.Test)7 Cursor (android.database.Cursor)3 SQLiteException (android.database.sqlite.SQLiteException)3 HashMap (java.util.HashMap)3 StreamKey (androidx.media3.common.StreamKey)1