Last active
March 1, 2017 19:10
-
-
Save parahall/8696907731265117f539f083ed77da07 to your computer and use it in GitHub Desktop.
KolGeneProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class KolGeneProvider extends ContentProvider { | |
//... | |
@Nullable @Override public Uri insert(@NonNull Uri uri, ContentValues values) { | |
//open DB for write | |
final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); | |
//match URI to action. | |
final int match = sUriMatcher.match(uri); | |
Uri returnUri; | |
switch (match) { | |
//case of creating order. | |
case ORDER: | |
long _id = db.insertWithOnConflict(KolGeneContract.OrderEntry.TABLE_NAME, null, values, | |
SQLiteDatabase.CONFLICT_REPLACE); | |
if (_id > 0) { | |
returnUri = KolGeneContract.OrderEntry.buildOrderUriWithId(_id); | |
} else { | |
throw new android.database.SQLException( | |
"Failed to insert row into " + uri + " id=" + _id); | |
} | |
break; | |
default: | |
throw new UnsupportedOperationException("Unknown uri: " + uri); | |
} | |
//notify observables about the change | |
getContext().getContentResolver().notifyChange(uri, null); | |
return returnUri; | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment