コード例 #1
0
  @Override
  public Uri insert(Uri uri, ContentValues values) {
    // Find matching path.
    final int match = sUriMatcher.match(uri);

    // Avoid the expensive string concatenation below if not loggable
    if (BuildConfig.DEBUG) {
      Log.v(TAG, "insert(uri=" + uri + ", values=" + values.toString() + ")");
    }

    // Get the database and run the insert
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    switch (match) {
      case PAYMENTS:
        {
          db.insertOrThrow(AppDatabase.Tables.PAYMENTS, null, values);
          getContext().getContentResolver().notifyChange(uri, null);
          // Generate Uri with remote id.
          return AppContract.Payments.buildUri(values.getAsString(AppContract.Payments.ID));
        }
      default:
        {
          throw new UnsupportedOperationException("Unknown insert uri: " + uri);
        }
    }
  }