use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.
the class CacheFileMetadataIndex method delete.
/**
* Deletes index data for the specified cache.
*
* <p>This method may be slow and shouldn't normally be called on the main thread.
*
* @param databaseProvider Provides the database in which the index is stored.
* @param uid The cache UID.
* @throws DatabaseIOException If an error occurs deleting the index data.
*/
@WorkerThread
public static void delete(DatabaseProvider databaseProvider, long uid) throws DatabaseIOException {
String hexUid = Long.toHexString(uid);
try {
String tableName = getTableName(hexUid);
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransactionNonExclusive();
try {
VersionTable.removeVersion(writableDatabase, VersionTable.FEATURE_CACHE_FILE_METADATA, hexUid);
dropTable(writableDatabase, tableName);
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 CacheFileMetadataIndex method set.
/**
* Sets metadata for a given file.
*
* <p>This method may be slow and shouldn't normally be called on the main thread.
*
* @param name The name of the file.
* @param length The file length.
* @param lastTouchTimestamp The file last touch timestamp.
* @throws DatabaseIOException If an error occurs setting the metadata.
*/
@WorkerThread
public void set(String name, long length, long lastTouchTimestamp) throws DatabaseIOException {
Assertions.checkNotNull(tableName);
try {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, name);
values.put(COLUMN_LENGTH, length);
values.put(COLUMN_LAST_TOUCH_TIMESTAMP, lastTouchTimestamp);
writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */
null, values);
} catch (SQLException e) {
throw new DatabaseIOException(e);
}
}
use of com.google.android.exoplayer2.database.DatabaseIOException in project ExoPlayer by google.
the class CacheFileMetadataIndex method initialize.
/**
* Initializes the index for the given cache UID.
*
* <p>This method may be slow and shouldn't normally be called on the main thread.
*
* @param uid The cache UID.
* @throws DatabaseIOException If an error occurs initializing the index.
*/
@WorkerThread
public void initialize(long uid) throws DatabaseIOException {
try {
String hexUid = Long.toHexString(uid);
tableName = getTableName(hexUid);
SQLiteDatabase readableDatabase = databaseProvider.getReadableDatabase();
int version = VersionTable.getVersion(readableDatabase, VersionTable.FEATURE_CACHE_FILE_METADATA, hexUid);
if (version != TABLE_VERSION) {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransactionNonExclusive();
try {
VersionTable.setVersion(writableDatabase, VersionTable.FEATURE_CACHE_FILE_METADATA, hexUid, TABLE_VERSION);
dropTable(writableDatabase, tableName);
writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA);
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 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);
}
}
Aggregations