Java Code Examples for android.content.ContentProviderClient#bulkInsert()

The following examples show how to use android.content.ContentProviderClient#bulkInsert() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncAdapter.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
private void syncEvents(ContentProviderClient provider, String cookie) {
    try {
        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);
    }
}
 
Example 2
Source File: QuantumFlux.java    From QuantumFlux with Apache License 2.0 5 votes vote down vote up
public static <T> int insertAll(ContentProviderClient providerClient, List<T> dataModelObjects) throws RemoteException {
    if (dataModelObjects == null || dataModelObjects.isEmpty())
        return 0;

    TableDetails tableDetails = findTableDetails(dataModelObjects.get(0).getClass());
    Uri insertUri = UriMatcherHelper.generateItemUriBuilder(tableDetails).build();

    ContentValues[] values = new ContentValues[dataModelObjects.size()];
    for (int i = 0; i < dataModelObjects.size(); i++) {
        values[i] = ModelInflater.deflate(tableDetails, dataModelObjects.get(i));
    }

    return providerClient.bulkInsert(insertUri, values);
}
 
Example 3
Source File: AbstractContentProviderStub.java    From DroidPlugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    String targetAuthority = uri.getQueryParameter(Env.EXTRA_TARGET_AUTHORITY);
    if (!TextUtils.isEmpty(targetAuthority) && !TextUtils.equals(targetAuthority, uri.getAuthority())) {
        ContentProviderClient client = getContentProviderClient(targetAuthority);
        try {
            return client.bulkInsert(buildNewUri(uri, targetAuthority), values);
        } catch (RemoteException e) {
            handleExpcetion(e);
        }
    }
    return super.bulkInsert(uri, values);
}