@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor retCursor; int match = match_uri(uri); switch (match) { case MATCHES: retCursor = mOpenHelper .getReadableDatabase() .query( DatabaseContract.SCORES_TABLE, projection, null, null, null, null, sortOrder); break; case MATCHES_WITH_DATE: retCursor = mOpenHelper .getReadableDatabase() .query( DatabaseContract.SCORES_TABLE, projection, SCORES_BY_DATE, selectionArgs, null, null, sortOrder); break; case MATCHES_WITH_ID: retCursor = mOpenHelper .getReadableDatabase() .query( DatabaseContract.SCORES_TABLE, projection, SCORES_BY_ID, selectionArgs, null, null, sortOrder); break; case MATCHES_WITH_LEAGUE: retCursor = mOpenHelper .getReadableDatabase() .query( DatabaseContract.SCORES_TABLE, projection, SCORES_BY_LEAGUE, selectionArgs, null, null, sortOrder); break; default: throw new UnsupportedOperationException("Unknown Uri" + uri); } retCursor.setNotificationUri(getContext().getContentResolver(), uri); return retCursor; }
@Override public int bulkInsert(Uri uri, ContentValues[] values) { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); switch (match_uri(uri)) { case MATCHES: db.beginTransaction(); int returncount = 0; try { for (ContentValues value : values) { long _id = db.insertWithOnConflict( DatabaseContract.SCORES_TABLE, null, value, SQLiteDatabase.CONFLICT_REPLACE); if (_id != -1) { returncount++; } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } getContext().getContentResolver().notifyChange(uri, null); return returncount; default: return super.bulkInsert(uri, values); } }