示例#1
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    Cursor retCursor;

    if (sUriMatcher.match(uri) == USERS) {
      retCursor =
          mOpenHelper
              .getReadableDatabase()
              .query(
                  UserContract.UserEntry.TABLE_NAME,
                  projection,
                  selection,
                  selectionArgs,
                  null,
                  null,
                  sortOrder);

    } else {
      throw new UnsupportedOperationException("Unknown Uri: " + uri);
    }

    retCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return retCursor;
  }
示例#2
0
  @SuppressLint("LongLogTag")
  @Override
  public Uri insert(Uri uri, ContentValues values) {

    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);

    Uri returnUri;

    if (match == USERS) {

      try {
        long _id = db.insert(UserContract.UserEntry.TABLE_NAME, null, values);
        returnUri = UserContract.UserEntry.buildUserUri(_id);
      } catch (SQLiteConstraintException e) {
        Log.e("Username unique exception: ", e.toString());
        returnUri = UserContract.UserEntry.buildUserUri(-1);
      }

    } else {
      throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    if (db != null) db.close();

    getContext().getContentResolver().notifyChange(uri, null);
    return returnUri;
  }