com.google.android.exoplayer2.database.DatabaseIOException Java Examples
The following examples show how to use
com.google.android.exoplayer2.database.DatabaseIOException.
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: CacheFileMetadataIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * 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 #2
Source File: CachedContentIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public void storeFully(HashMap<String, CachedContent> content) throws IOException { try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransactionNonExclusive(); try { initializeTable(writableDatabase); for (CachedContent cachedContent : content.values()) { addOrUpdateRow(writableDatabase, cachedContent); } writableDatabase.setTransactionSuccessful(); pendingUpdates.clear(); } finally { writableDatabase.endTransaction(); } } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #3
Source File: DefaultDownloadIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
private Cursor getCursor(String selection, @Nullable String[] selectionArgs) throws DatabaseIOException { try { String sortOrder = COLUMN_START_TIME_MS + " ASC"; return databaseProvider .getReadableDatabase() .query( tableName, COLUMNS, selection, selectionArgs, /* groupBy= */ null, /* having= */ null, sortOrder); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example #4
Source File: CachedContentIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void storeFully(HashMap<String, CachedContent> content) throws IOException { try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransaction(); try { initializeTable(writableDatabase); for (CachedContent cachedContent : content.values()) { addOrUpdateRow(writableDatabase, cachedContent); } writableDatabase.setTransactionSuccessful(); pendingUpdates.clear(); } finally { writableDatabase.endTransaction(); } } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #5
Source File: CachedContentIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void storeIncremental(HashMap<String, CachedContent> content) throws IOException { if (pendingUpdates.size() == 0) { return; } try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransaction(); try { for (int i = 0; i < pendingUpdates.size(); i++) { CachedContent cachedContent = pendingUpdates.valueAt(i); if (cachedContent == null) { deleteRow(writableDatabase, pendingUpdates.keyAt(i)); } else { addOrUpdateRow(writableDatabase, cachedContent); } } writableDatabase.setTransactionSuccessful(); pendingUpdates.clear(); } 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 |
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: CacheFileMetadataIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * 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 #8
Source File: DefaultDownloadIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
@SuppressWarnings("nullness:argument.type.incompatible") private Cursor getCursor(String selection, @Nullable String[] selectionArgs) throws DatabaseIOException { try { String sortOrder = COLUMN_START_TIME_MS + " ASC"; return databaseProvider .getReadableDatabase() .query( tableName, COLUMNS, selection, selectionArgs, /* groupBy= */ null, /* having= */ null, sortOrder); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example #9
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 #10
Source File: DefaultDownloadIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public void setStopReason(String id, int stopReason) throws DatabaseIOException { ensureInitialized(); try { ContentValues values = new ContentValues(); values.put(COLUMN_STOP_REASON, stopReason); SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.update( tableName, values, WHERE_STATE_IS_TERMINAL + " AND " + WHERE_ID_EQUALS, new String[] {id}); } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #11
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 #12
Source File: DefaultDownloadIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example #13
Source File: CacheFileMetadataIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Removes metadata. * * @param names The names of the files whose metadata is to be removed. * @throws DatabaseIOException If an error occurs removing the metadata. */ public void removeAll(Set<String> names) throws DatabaseIOException { Assertions.checkNotNull(tableName); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransaction(); try { for (String name : names) { writableDatabase.delete(tableName, WHERE_NAME_EQUALS, new String[] {name}); } writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #14
Source File: CachedContentIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public void storeIncremental(HashMap<String, CachedContent> content) throws IOException { if (pendingUpdates.size() == 0) { return; } try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransactionNonExclusive(); try { for (int i = 0; i < pendingUpdates.size(); i++) { CachedContent cachedContent = pendingUpdates.valueAt(i); if (cachedContent == null) { deleteRow(writableDatabase, pendingUpdates.keyAt(i)); } else { addOrUpdateRow(writableDatabase, cachedContent); } } writableDatabase.setTransactionSuccessful(); pendingUpdates.clear(); } finally { writableDatabase.endTransaction(); } } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #15
Source File: CachedContentIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
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 #16
Source File: CacheFileMetadataIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * 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 = 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); } }
Example #17
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 #18
Source File: DefaultDownloadIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void setStopReason(String id, int stopReason) throws DatabaseIOException { ensureInitialized(); try { ContentValues values = new ContentValues(); values.put(COLUMN_STOP_REASON, stopReason); SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.update( tableName, values, WHERE_STATE_IS_TERMINAL + " AND " + WHERE_ID_EQUALS, new String[] {id}); } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #19
Source File: CacheFileMetadataIndex.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Removes metadata. * * <p>This method may be slow and shouldn't normally be called on the main thread. * * @param names The names of the files whose metadata is to be removed. * @throws DatabaseIOException If an error occurs removing the metadata. */ @WorkerThread public void removeAll(Set<String> names) throws DatabaseIOException { Assertions.checkNotNull(tableName); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransactionNonExclusive(); try { for (String name : names) { writableDatabase.delete(tableName, WHERE_NAME_EQUALS, new String[] {name}); } writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #20
Source File: DefaultDownloadIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example #21
Source File: DefaultDownloadIndex.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void putDownload(Download download) throws DatabaseIOException { ensureInitialized(); ContentValues values = new ContentValues(); values.put(COLUMN_ID, download.request.id); values.put(COLUMN_TYPE, download.request.type); values.put(COLUMN_URI, download.request.uri.toString()); values.put(COLUMN_STREAM_KEYS, encodeStreamKeys(download.request.streamKeys)); values.put(COLUMN_CUSTOM_CACHE_KEY, download.request.customCacheKey); values.put(COLUMN_DATA, download.request.data); values.put(COLUMN_STATE, download.state); values.put(COLUMN_START_TIME_MS, download.startTimeMs); values.put(COLUMN_UPDATE_TIME_MS, download.updateTimeMs); values.put(COLUMN_CONTENT_LENGTH, download.contentLength); values.put(COLUMN_STOP_REASON, download.stopReason); values.put(COLUMN_FAILURE_REASON, download.failureReason); values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded()); values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded()); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example #22
Source File: CacheFileMetadataIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Removes metadata. * * @param names The names of the files whose metadata is to be removed. * @throws DatabaseIOException If an error occurs removing the metadata. */ public void removeAll(Set<String> names) throws DatabaseIOException { Assertions.checkNotNull(tableName); try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransaction(); try { for (String name : names) { writableDatabase.delete(tableName, WHERE_NAME_EQUALS, new String[] {name}); } writableDatabase.setTransactionSuccessful(); } finally { writableDatabase.endTransaction(); } } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #23
Source File: DefaultDownloadIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public void setStopReason(String id, int stopReason) throws DatabaseIOException { ensureInitialized(); try { ContentValues values = new ContentValues(); values.put(COLUMN_STOP_REASON, stopReason); SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.update( tableName, values, WHERE_STATE_IS_TERMINAL + " AND " + WHERE_ID_EQUALS, new String[] {id}); } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #24
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 #25
Source File: DefaultDownloadIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private Cursor getCursor(String selection, @Nullable String[] selectionArgs) throws DatabaseIOException { try { String sortOrder = COLUMN_START_TIME_MS + " ASC"; return databaseProvider .getReadableDatabase() .query( tableName, COLUMNS, selection, selectionArgs, /* groupBy= */ null, /* having= */ null, sortOrder); } catch (SQLiteException e) { throw new DatabaseIOException(e); } }
Example #26
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 #27
Source File: CacheFileMetadataIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * 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 #28
Source File: CachedContentIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public void storeFully(HashMap<String, CachedContent> content) throws IOException { try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransaction(); try { initializeTable(writableDatabase); for (CachedContent cachedContent : content.values()) { addOrUpdateRow(writableDatabase, cachedContent); } writableDatabase.setTransactionSuccessful(); pendingUpdates.clear(); } finally { writableDatabase.endTransaction(); } } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #29
Source File: CachedContentIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public void storeIncremental(HashMap<String, CachedContent> content) throws IOException { if (pendingUpdates.size() == 0) { return; } try { SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase(); writableDatabase.beginTransaction(); try { for (int i = 0; i < pendingUpdates.size(); i++) { CachedContent cachedContent = pendingUpdates.valueAt(i); if (cachedContent == null) { deleteRow(writableDatabase, pendingUpdates.keyAt(i)); } else { addOrUpdateRow(writableDatabase, cachedContent); } } writableDatabase.setTransactionSuccessful(); pendingUpdates.clear(); } finally { writableDatabase.endTransaction(); } } catch (SQLException e) { throw new DatabaseIOException(e); } }
Example #30
Source File: CachedContentIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
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); } }