@Nullable @Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor retCursor; switch (uriMatcher.match(uri)) { case PROJECTS: retCursor = projectDBHelper .getReadableDatabase() .query( ProjectContract.ProjectEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); break; case PROJECT_BY_ID: String id = uri.getPathSegments().get(1); retCursor = projectDBHelper .getReadableDatabase() .query( ProjectContract.ProjectEntry.TABLE_NAME, projection, "_id=?", new String[] {id}, null, null, null); break; default: throw new UnsupportedOperationException("Unknown uri: " + uri); } ; retCursor.setNotificationUri(getContext().getContentResolver(), uri); return retCursor; }
@Nullable @Override public Uri insert(Uri uri, ContentValues values) { long id = projectDBHelper .getWritableDatabase() .insertWithOnConflict( ProjectContract.ProjectEntry.TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE); return ContentUris.withAppendedId(uri, id); }
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { String id = null; if (uriMatcher.match(uri) == PROJECT_BY_ID) { id = uri.getPathSegments().get(1); } if (id != null) { return projectDBHelper .getWritableDatabase() .update(ProjectContract.ProjectEntry.TABLE_NAME, values, "_id=?", new String[] {id}); } return -1; }