List of usage examples for android.content ContentProviderClient bulkInsert
public int bulkInsert(@NonNull Uri url, @NonNull ContentValues[] initialValues) throws RemoteException
From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java
private void syncEvents(ContentProviderClient provider, String cookie) { try {// w w w . jav a2 s .c o m RequestQueue requestQueue = GutenbergApplication.from(getContext()).getRequestQueue(); JSONArray events = getEvents(requestQueue, cookie); Pair<String[], ContentValues[]> pair = parseEvents(events); String[] eventIds = pair.first; provider.bulkInsert(Table.EVENT.getBaseUri(), pair.second); ArrayList<ContentProviderOperation> operations = new ArrayList<>(); operations.add(ContentProviderOperation.newDelete(Table.EVENT.getBaseUri()) .withSelection(Table.Event.ID + " NOT IN ('" + TextUtils.join("', '", eventIds) + "')", null) .build()); operations.add(ContentProviderOperation.newDelete(Table.ATTENDEE.getBaseUri()) .withSelection(Table.Attendee.EVENT_ID + " NOT IN ('" + TextUtils.join("', '", eventIds) + "')", null) .build()); provider.applyBatch(operations); for (String eventId : eventIds) { JSONArray attendees = getAttendees(requestQueue, eventId, cookie); provider.bulkInsert(Table.ATTENDEE.getBaseUri(), parseAttendees(eventId, attendees)); } Log.d(TAG, eventIds.length + " event(s) synced."); } catch (ExecutionException | InterruptedException | JSONException | RemoteException | OperationApplicationException e) { Log.e(TAG, "Error performing sync.", e); } }