@Override public int bulkInsert(Uri uri, ContentValues[] values) { SQLiteDatabase db = weatherDbHelper.getWritableDatabase(); final int match = uriMatcher.match(uri); switch (match) { case WEATHER: db.beginTransaction(); int returnCount = 0; try { for (ContentValues value : values) { long id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value); if (-1 != id) { ++returnCount; } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } getContext().getContentResolver().notifyChange(uri, null); return returnCount; default: return super.bulkInsert(uri, values); } }
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { final String tableName = getTableName(uri); // do the actual deletion int affectedRows = weatherDbHelper.getWritableDatabase().delete(tableName, selection, selectionArgs); // notify any registered observers of this change if (selection == null || affectedRows > 0) { getContext().getContentResolver().notifyChange(uri, null); } return affectedRows; }
@Override public Uri insert(Uri uri, ContentValues contentValues) { final int match = uriMatcher.match(uri); Uri returnUri = null; SQLiteDatabase db = weatherDbHelper.getWritableDatabase(); switch (match) { case WEATHER: { long id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, contentValues); if (id > 0) { returnUri = WeatherContract.WeatherEntry.buildWeatherUri(id); } else { throw new SQLException("Failed to insert row into " + uri); } break; } case LOCATION: { long id = db.insert(WeatherContract.LocationEntry.TABLE_NAME, null, contentValues); if (id > 0) { returnUri = WeatherContract.LocationEntry.buildLocationUri(id); } else { throw new SQLException("Failed to insert row into " + uri); } break; } default: throw new UnsupportedOperationException("Unknown uri " + uri); } // notify any registered observers of this change getContext().getContentResolver().notifyChange(uri, null); return returnUri; }