Java Code Examples for com.google.android.exoplayer2.database.VersionTable#getVersion()
The following examples show how to use
com.google.android.exoplayer2.database.VersionTable#getVersion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultDownloadIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
private void ensureInitialized() throws DatabaseIOException { 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); writableDatabase.execSQL("DROP TABLE IF EXISTS " + tableName); writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA); writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } initialized = true; } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example 2
Source File: DefaultDownloadIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private void ensureInitialized() throws DatabaseIOException { 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.beginTransaction(); try { VersionTable.setVersion( writableDatabase, VersionTable.FEATURE_OFFLINE, name, TABLE_VERSION); writableDatabase.execSQL("DROP TABLE IF EXISTS " + tableName); writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA); writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } initialized = true; } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example 3
Source File: CacheFileMetadataIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Initializes the index for the given cache UID. * * @param uid The cache UID. * @throws DatabaseIOException If an error occurs initializing the index. */ 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.beginTransaction(); 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); } }
Example 4
Source File: DefaultDownloadIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
private void ensureInitialized() throws DatabaseIOException { 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.beginTransaction(); try { VersionTable.setVersion( writableDatabase, VersionTable.FEATURE_OFFLINE, name, TABLE_VERSION); writableDatabase.execSQL("DROP TABLE IF EXISTS " + tableName); writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA); writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } initialized = true; } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example 5
Source File: CacheFileMetadataIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Initializes the index for the given cache UID. * * @param uid The cache UID. * @throws DatabaseIOException If an error occurs initializing the index. */ 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.beginTransaction(); 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); } }
Example 6
Source File: CachedContentIndex.java From MediaSDK with Apache License 2.0 | 5 votes |
@Override public boolean exists() throws DatabaseIOException { return VersionTable.getVersion( databaseProvider.getReadableDatabase(), VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid) != VersionTable.VERSION_UNSET; }
Example 7
Source File: CacheFileMetadataIndex.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 8
Source File: CachedContentIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public boolean exists() throws DatabaseIOException { return VersionTable.getVersion( databaseProvider.getReadableDatabase(), VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid) != VersionTable.VERSION_UNSET; }
Example 9
Source File: CachedContentIndex.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public boolean exists() throws DatabaseIOException { return VersionTable.getVersion( databaseProvider.getReadableDatabase(), VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid) != VersionTable.VERSION_UNSET; }
Example 10
Source File: CachedContentIndex.java From MediaSDK with Apache License 2.0 | 4 votes |
@Override public void load( HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey) throws IOException { Assertions.checkState(pendingUpdates.size() == 0); try { int version = VersionTable.getVersion( databaseProvider.getReadableDatabase(), VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid); if (version != TABLE_VERSION) { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransactionNonExclusive(); try { initializeTable(writableDatabase); writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } try (Cursor cursor = getCursor()) { while (cursor.moveToNext()) { int id = cursor.getInt(COLUMN_INDEX_ID); String key = cursor.getString(COLUMN_INDEX_KEY); byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA); ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes); DataInputStream input = new DataInputStream(inputStream); DefaultContentMetadata metadata = readContentMetadata(input); CachedContent cachedContent = new CachedContent(id, key, metadata); content.put(cachedContent.key, cachedContent); idToKey.put(cachedContent.id, cachedContent.key); } } } catch (SQLiteException e) { content.clear(); idToKey.clear(); throw new DatabaseIOException(e); } }
Example 11
Source File: CachedContentIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public void load( HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey) throws IOException { Assertions.checkState(pendingUpdates.size() == 0); try { int version = VersionTable.getVersion( databaseProvider.getReadableDatabase(), VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid); if (version != TABLE_VERSION) { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransaction(); try { initializeTable(writableDatabase); writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } try (Cursor cursor = getCursor()) { while (cursor.moveToNext()) { int id = cursor.getInt(COLUMN_INDEX_ID); String key = cursor.getString(COLUMN_INDEX_KEY); byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA); ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes); DataInputStream input = new DataInputStream(inputStream); DefaultContentMetadata metadata = readContentMetadata(input); CachedContent cachedContent = new CachedContent(id, key, metadata); content.put(cachedContent.key, cachedContent); idToKey.put(cachedContent.id, cachedContent.key); } } } catch (SQLiteException e) { content.clear(); idToKey.clear(); throw new DatabaseIOException(e); } }
Example 12
Source File: CachedContentIndex.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public void load( HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey) throws IOException { Assertions.checkState(pendingUpdates.size() == 0); try { int version = VersionTable.getVersion( databaseProvider.getReadableDatabase(), VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid); if (version != TABLE_VERSION) { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransaction(); try { initializeTable(writableDatabase); writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } try (Cursor cursor = getCursor()) { while (cursor.moveToNext()) { int id = cursor.getInt(COLUMN_INDEX_ID); String key = cursor.getString(COLUMN_INDEX_KEY); byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA); ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes); DataInputStream input = new DataInputStream(inputStream); DefaultContentMetadata metadata = readContentMetadata(input); CachedContent cachedContent = new CachedContent(id, key, metadata); content.put(cachedContent.key, cachedContent); idToKey.put(cachedContent.id, cachedContent.key); } } } catch (SQLiteException e) { content.clear(); idToKey.clear(); throw new DatabaseIOException(e); } }