use of com.google.android.exoplayer2.offline.Download in project ExoPlayer by google.
the class DefaultDownloadIndex method ensureInitialized.
private void ensureInitialized() throws DatabaseIOException {
synchronized (initializationLock) {
if (initialized) {
return;
}
try {
SQLiteDatabase readableDatabase = databaseProvider.getReadableDatabase();
int version = VersionTable.getVersion(readableDatabase, VersionTable.FEATURE_OFFLINE, name);
if (version != TABLE_VERSION) {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransactionNonExclusive();
try {
VersionTable.setVersion(writableDatabase, VersionTable.FEATURE_OFFLINE, name, TABLE_VERSION);
List<Download> upgradedDownloads = version == 2 ? loadDownloadsFromVersion2(writableDatabase) : new ArrayList<>();
writableDatabase.execSQL("DROP TABLE IF EXISTS " + tableName);
writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA);
for (Download download : upgradedDownloads) {
putDownloadInternal(download, writableDatabase);
}
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
initialized = true;
} catch (SQLException e) {
throw new DatabaseIOException(e);
}
}
}
Aggregations