Java Code Examples for android.database.sqlite.SQLiteDatabase#replaceOrThrow()

The following examples show how to use android.database.sqlite.SQLiteDatabase#replaceOrThrow() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: MediaSDK   File: DefaultDownloadIndex.java    License: Apache License 2.0 6 votes vote down vote up
@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 2
@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 3
@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 4
Source Project: MediaSDK   File: VersionTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the version of a specified instance of a specified feature.
 *
 * @param writableDatabase The database to update.
 * @param feature The feature.
 * @param instanceUid The unique identifier of the instance of the feature.
 * @param version The version.
 * @throws DatabaseIOException If an error occurs executing the SQL.
 */
public static void setVersion(
    SQLiteDatabase writableDatabase, @Feature int feature, String instanceUid, int version)
    throws DatabaseIOException {
  try {
    writableDatabase.execSQL(SQL_CREATE_TABLE_IF_NOT_EXISTS);
    ContentValues values = new ContentValues();
    values.put(COLUMN_FEATURE, feature);
    values.put(COLUMN_INSTANCE_UID, instanceUid);
    values.put(COLUMN_VERSION, version);
    writableDatabase.replaceOrThrow(TABLE_NAME, /* nullColumnHack= */ null, values);
  } catch (SQLException e) {
    throw new DatabaseIOException(e);
  }
}
 
Example 5
Source Project: MediaSDK   File: CachedContentIndex.java    License: Apache License 2.0 5 votes vote down vote up
private void addOrUpdateRow(SQLiteDatabase writableDatabase, CachedContent cachedContent)
    throws IOException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  writeContentMetadata(cachedContent.getMetadata(), new DataOutputStream(outputStream));
  byte[] data = outputStream.toByteArray();

  ContentValues values = new ContentValues();
  values.put(COLUMN_ID, cachedContent.id);
  values.put(COLUMN_KEY, cachedContent.key);
  values.put(COLUMN_METADATA, data);
  writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values);
}
 
Example 6
Source Project: MediaSDK   File: CacheFileMetadataIndex.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 7
public void createOrUpdateSingleNoteWidgetData(@NonNull SingleNoteWidgetData data) throws SQLException {
    validateAccountId(data.getAccountId());
    final SQLiteDatabase db = getWritableDatabase();
    final ContentValues values = new ContentValues(4);
    values.put(key_id, data.getAppWidgetId());
    values.put(key_account_id, data.getAccountId());
    values.put(key_note_id, data.getNoteId());
    values.put(key_theme_mode, data.getThemeMode());
    db.replaceOrThrow(table_widget_single_notes, null, values);
}
 
Example 8
public void createOrUpdateNoteListWidgetData(@NonNull NoteListsWidgetData data) throws SQLException {
    validateAccountId(data.getAccountId());
    final SQLiteDatabase db = getWritableDatabase();
    final ContentValues values = new ContentValues(5);
    if (data.getMode() != MODE_DISPLAY_CATEGORY && data.getCategoryId() != null) {
        throw new UnsupportedOperationException("Cannot create a widget with a categoryId when mode is not " + MODE_DISPLAY_CATEGORY);
    }
    values.put(key_id, data.getAppWidgetId());
    values.put(key_account_id, data.getAccountId());
    values.put(key_category_id, data.getCategoryId());
    values.put(key_theme_mode, data.getThemeMode());
    values.put(key_mode, data.getMode());
    db.replaceOrThrow(table_widget_note_list, null, values);
}
 
Example 9
/**
 * Sets the version of a specified instance of a specified feature.
 *
 * @param writableDatabase The database to update.
 * @param feature The feature.
 * @param instanceUid The unique identifier of the instance of the feature.
 * @param version The version.
 * @throws DatabaseIOException If an error occurs executing the SQL.
 */
public static void setVersion(
    SQLiteDatabase writableDatabase, @Feature int feature, String instanceUid, int version)
    throws DatabaseIOException {
  try {
    writableDatabase.execSQL(SQL_CREATE_TABLE_IF_NOT_EXISTS);
    ContentValues values = new ContentValues();
    values.put(COLUMN_FEATURE, feature);
    values.put(COLUMN_INSTANCE_UID, instanceUid);
    values.put(COLUMN_VERSION, version);
    writableDatabase.replaceOrThrow(TABLE_NAME, /* nullColumnHack= */ null, values);
  } catch (SQLException e) {
    throw new DatabaseIOException(e);
  }
}
 
Example 10
private void addOrUpdateRow(SQLiteDatabase writableDatabase, CachedContent cachedContent)
    throws IOException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  writeContentMetadata(cachedContent.getMetadata(), new DataOutputStream(outputStream));
  byte[] data = outputStream.toByteArray();

  ContentValues values = new ContentValues();
  values.put(COLUMN_ID, cachedContent.id);
  values.put(COLUMN_KEY, cachedContent.key);
  values.put(COLUMN_METADATA, data);
  writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values);
}
 
Example 11
/**
 * Sets metadata for a given file.
 *
 * @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.
 */
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);
  }
}
 
Example 12
/**
 * Sets the version of a specified instance of a specified feature.
 *
 * @param writableDatabase The database to update.
 * @param feature The feature.
 * @param instanceUid The unique identifier of the instance of the feature.
 * @param version The version.
 * @throws DatabaseIOException If an error occurs executing the SQL.
 */
public static void setVersion(
    SQLiteDatabase writableDatabase, @Feature int feature, String instanceUid, int version)
    throws DatabaseIOException {
  try {
    writableDatabase.execSQL(SQL_CREATE_TABLE_IF_NOT_EXISTS);
    ContentValues values = new ContentValues();
    values.put(COLUMN_FEATURE, feature);
    values.put(COLUMN_INSTANCE_UID, instanceUid);
    values.put(COLUMN_VERSION, version);
    writableDatabase.replaceOrThrow(TABLE_NAME, /* nullColumnHack= */ null, values);
  } catch (SQLException e) {
    throw new DatabaseIOException(e);
  }
}
 
Example 13
private void addOrUpdateRow(SQLiteDatabase writableDatabase, CachedContent cachedContent)
    throws IOException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  writeContentMetadata(cachedContent.getMetadata(), new DataOutputStream(outputStream));
  byte[] data = outputStream.toByteArray();

  ContentValues values = new ContentValues();
  values.put(COLUMN_ID, cachedContent.id);
  values.put(COLUMN_KEY, cachedContent.key);
  values.put(COLUMN_METADATA, data);
  writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */ null, values);
}
 
Example 14
/**
 * Sets metadata for a given file.
 *
 * @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.
 */
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);
  }
}