com.google.android.exoplayer2.database.VersionTable Java Examples

The following examples show how to use com.google.android.exoplayer2.database.VersionTable. 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 vote down vote up
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: CacheFileMetadataIndex.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #3
Source File: CacheFileMetadataIndex.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deletes index data for the specified cache.
 *
 * @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.
 */
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.beginTransaction();
    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);
  }
}
 
Example #4
Source File: CachedContentIndex.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static void delete(DatabaseProvider databaseProvider, String hexUid)
    throws DatabaseIOException {
  try {
    String tableName = getTableName(hexUid);
    SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
    writableDatabase.beginTransactionNonExclusive();
    try {
      VersionTable.removeVersion(
          writableDatabase, VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid);
      dropTable(writableDatabase, tableName);
      writableDatabase.setTransactionSuccessful();
    } finally {
      writableDatabase.endTransaction();
    }
  } catch (SQLException e) {
    throw new DatabaseIOException(e);
  }
}
 
Example #5
Source File: CacheFileMetadataIndex.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example #6
Source File: CachedContentIndex.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static void delete(DatabaseProvider databaseProvider, String hexUid)
    throws DatabaseIOException {
  try {
    String tableName = getTableName(hexUid);
    SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
    writableDatabase.beginTransaction();
    try {
      VersionTable.removeVersion(
          writableDatabase, VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid);
      dropTable(writableDatabase, tableName);
      writableDatabase.setTransactionSuccessful();
    } finally {
      writableDatabase.endTransaction();
    }
  } catch (SQLException e) {
    throw new DatabaseIOException(e);
  }
}
 
Example #7
Source File: DefaultDownloadIndex.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
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 #8
Source File: DefaultDownloadIndex.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
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 #9
Source File: CacheFileMetadataIndex.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #10
Source File: CachedContentIndex.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static void delete(DatabaseProvider databaseProvider, String hexUid)
    throws DatabaseIOException {
  try {
    String tableName = getTableName(hexUid);
    SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
    writableDatabase.beginTransaction();
    try {
      VersionTable.removeVersion(
          writableDatabase, VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid);
      dropTable(writableDatabase, tableName);
      writableDatabase.setTransactionSuccessful();
    } finally {
      writableDatabase.endTransaction();
    }
  } catch (SQLException e) {
    throw new DatabaseIOException(e);
  }
}
 
Example #11
Source File: CacheFileMetadataIndex.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deletes index data for the specified cache.
 *
 * @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.
 */
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.beginTransaction();
    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);
  }
}
 
Example #12
Source File: CachedContentIndex.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public boolean exists() throws DatabaseIOException {
  return VersionTable.getVersion(
          databaseProvider.getReadableDatabase(),
          VersionTable.FEATURE_CACHE_CONTENT_METADATA,
          hexUid)
      != VersionTable.VERSION_UNSET;
}
 
Example #13
Source File: CachedContentIndex.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean exists() throws DatabaseIOException {
  return VersionTable.getVersion(
          databaseProvider.getReadableDatabase(),
          VersionTable.FEATURE_CACHE_CONTENT_METADATA,
          hexUid)
      != VersionTable.VERSION_UNSET;
}
 
Example #14
Source File: CachedContentIndex.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean exists() throws DatabaseIOException {
  return VersionTable.getVersion(
          databaseProvider.getReadableDatabase(),
          VersionTable.FEATURE_CACHE_CONTENT_METADATA,
          hexUid)
      != VersionTable.VERSION_UNSET;
}
 
Example #15
Source File: CacheFileMetadataIndex.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #16
Source File: CachedContentIndex.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void initializeTable(SQLiteDatabase writableDatabase) throws DatabaseIOException {
  VersionTable.setVersion(
      writableDatabase, VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid, TABLE_VERSION);
  dropTable(writableDatabase, tableName);
  writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA);
}
 
Example #17
Source File: CachedContentIndex.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@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 #18
Source File: CachedContentIndex.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@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 #19
Source File: CachedContentIndex.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void initializeTable(SQLiteDatabase writableDatabase) throws DatabaseIOException {
  VersionTable.setVersion(
      writableDatabase, VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid, TABLE_VERSION);
  dropTable(writableDatabase, tableName);
  writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA);
}
 
Example #20
Source File: CachedContentIndex.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private void initializeTable(SQLiteDatabase writableDatabase) throws DatabaseIOException {
  VersionTable.setVersion(
      writableDatabase, VersionTable.FEATURE_CACHE_CONTENT_METADATA, hexUid, TABLE_VERSION);
  dropTable(writableDatabase, tableName);
  writableDatabase.execSQL("CREATE TABLE " + tableName + " " + TABLE_SCHEMA);
}
 
Example #21
Source File: CachedContentIndex.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@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);
  }
}