Example usage for android.content ContentProviderOperation newDelete

List of usage examples for android.content ContentProviderOperation newDelete

Introduction

In this page you can find the example usage for android.content ContentProviderOperation newDelete.

Prototype

public static Builder newDelete(Uri uri) 

Source Link

Document

Create a Builder suitable for building a delete ContentProviderOperation .

Usage

From source file:org.exfio.weavedroid.resource.LocalAddressBook.java

public void deleteAllExceptRemoteNames(Resource[] remoteResources) {
    String where;//from w  w w. ja  v a2 s . co  m

    if (remoteResources.length != 0) {
        List<String> sqlFileNames = new LinkedList<String>();
        for (Resource res : remoteResources)
            sqlFileNames.add(DatabaseUtils.sqlEscapeString(res.getId()));
        where = entryColumnRemoteId() + " NOT IN (" + StringUtils.join(sqlFileNames, ",") + ")";
    } else
        where = entryColumnRemoteId() + " IS NOT NULL";

    Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection(where, null);
    pendingOperations.add(builder.withYieldAllowed(true).build());
}

From source file:at.bitfire.davdroid.mirakel.resource.LocalAddressBook.java

public void deleteAllExceptRemoteNames(Resource[] remoteResources) {
    String where;/*  w  w w  . j a  v  a 2  s .  c o  m*/

    if (remoteResources.length != 0) {
        List<String> sqlFileNames = new LinkedList<String>();
        for (Resource res : remoteResources)
            sqlFileNames.add(DatabaseUtils.sqlEscapeString(res.getName()));
        where = entryColumnRemoteName() + " NOT IN (" + StringUtils.join(sqlFileNames, ",") + ")";
    } else
        where = entryColumnRemoteName() + " IS NOT NULL";

    Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection(where, null);
    pendingOperations.add(builder.withYieldAllowed(true).build());
}

From source file:org.exfio.csyncdroid.resource.LocalAddressBook.java

public void deleteAllExceptRemoteIds(String[] preserveIds) {
    String where;//from   ww  w  . ja v a 2 s  .c om

    if (preserveIds.length != 0) {
        where = entryColumnRemoteId() + " NOT IN (" + SQLUtils.quoteArray(preserveIds) + ")";
    } else
        where = entryColumnRemoteId() + " IS NOT NULL";

    Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection(where, null);
    pendingOperations.add(builder.withYieldAllowed(true).build());
}

From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteScheduleHandler.java

@Override
public ArrayList<ContentProviderOperation> parse(ArrayList<JSONArray> entries, ContentResolver resolver)
        throws JSONException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();
    final HashMap<String, ContentProviderOperation> blockBatchMap = Maps.newHashMap();
    final HashMap<String, ContentProviderOperation> sessionUpdateBatchMap = Maps.newHashMap();

    int nrEntries = 0;
    for (JSONArray schedules : entries) {
        Log.d(TAG, "Retrieved " + schedules.length() + " schedule entries.");
        nrEntries += schedules.length();

        for (int i = 0; i < schedules.length(); i++) {
            JSONObject schedule = schedules.getJSONObject(i);

            final long startTime = ParserUtils.parseDevoxxTime(schedule.getString("fromTime"));
            final long endTime = ParserUtils.parseDevoxxTime(schedule.getString("toTime"));
            final String kind = schedule.getString("kind");

            final String blockId = Blocks.generateBlockId(kind, startTime, endTime);

            if (!blockBatchMap.containsKey(blockId)) {
                final Uri blockUri = Blocks.buildBlockUri(blockId);

                ContentProviderOperation.Builder builder;
                if (isRowExisting(Blocks.buildBlockUri(blockId), BlocksQuery.PROJECTION, resolver)) {
                    builder = ContentProviderOperation.newUpdate(blockUri);
                } else {
                    builder = ContentProviderOperation.newInsert(Blocks.CONTENT_URI);
                    builder.withValue(Blocks.BLOCK_ID, blockId);
                }//  w w  w .java2 s .com
                builder.withValue(Blocks.BLOCK_START, startTime);
                builder.withValue(Blocks.BLOCK_END, endTime);

                final String type = schedule.getString("type");
                final String code = schedule.getString("code");

                if (code.startsWith("D10")) {
                    builder.withValue(Blocks.BLOCK_TITLE, type.replaceAll("\\ \\(.*\\)", ""));
                } else {
                    builder.withValue(Blocks.BLOCK_TITLE, schedule.getString("code"));
                }

                builder.withValue(Blocks.BLOCK_TYPE, kind);
                blockBatchMap.put(blockId, builder.build());
            }

            if (schedule.has("presentationUri")) {
                final Uri presentationUri = Uri.parse(schedule.getString("presentationUri"));
                final String sessionId = presentationUri.getLastPathSegment();
                final Uri sessionUri = Sessions.buildSessionUri(sessionId);

                if (isRowExisting(sessionUri, SessionsQuery.PROJECTION, resolver)) {
                    String roomId = null;
                    if (schedule.has("room")) {
                        final String roomName = schedule.getString("room");
                        Cursor cursor = resolver.query(Rooms.buildRoomsWithNameUri(roomName),
                                RoomsQuery.PROJECTION, null, null, null);
                        if (cursor.moveToNext()) {
                            roomId = cursor.getString(RoomsQuery.ROOM_ID);
                        }
                        cursor.close();
                    }
                    final ContentProviderOperation.Builder builder = ContentProviderOperation
                            .newUpdate(sessionUri);
                    builder.withValue(Sessions.BLOCK_ID, blockId);
                    builder.withValue(Sessions.ROOM_ID, roomId);
                    if (schedule.has("note")) {
                        final String note = schedule.getString("note");
                        if (note != null && note.trim().length() > 0) {
                            builder.withValue(Sessions.NOTE, note.trim());
                        }
                    }

                    sessionUpdateBatchMap.put(sessionId, builder.build());
                }
            }
        }
    }

    batch.addAll(blockBatchMap.values());
    batch.addAll(sessionUpdateBatchMap.values());

    if (isRemoteSync() && nrEntries > 0) {
        for (String lostId : getLostIds(blockBatchMap.keySet(), Blocks.CONTENT_URI, BlocksQuery.PROJECTION,
                BlocksQuery.BLOCK_ID, resolver)) {
            if (!lostId.startsWith("lab")) {
                final Uri lostBlockUri = Blocks.buildBlockUri(lostId);
                batch.add(ContentProviderOperation.newDelete(lostBlockUri).build());
            }
        }
        for (String lostId : getLostIds(sessionUpdateBatchMap.keySet(), Sessions.CONTENT_URI,
                SessionsQuery.PROJECTION, SessionsQuery.SESSION_ID, resolver)) {
            Uri deleteUri = Sessions.buildSpeakersDirUri(lostId);
            batch.add(ContentProviderOperation.newDelete(deleteUri).build());
            deleteUri = Sessions.buildTagsDirUri(lostId);
            batch.add(ContentProviderOperation.newDelete(deleteUri).build());
            deleteUri = Sessions.buildSessionUri(lostId);
            batch.add(ContentProviderOperation.newDelete(deleteUri).build());
        }
    }

    return batch;
}

From source file:org.exfio.weavedroid.resource.LocalAddressBook.java

public void deleteAllExceptUIDs(String[] ids) {
    String where;//w  w w . j  av  a2 s  .  c o  m

    if (ids.length != 0) {
        List<String> sqlFileNames = new LinkedList<String>();
        for (String id : ids)
            sqlFileNames.add(DatabaseUtils.sqlEscapeString(id));
        where = entryColumnUID() + " NOT IN (" + StringUtils.join(sqlFileNames, ",") + ")";
    } else
        where = entryColumnUID() + " IS NOT NULL";

    Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection(where, null);
    pendingOperations.add(builder.withYieldAllowed(true).build());
}

From source file:io.nuclei.box.Query.java

public ContentProviderOperation toDeleteOperation(String... selectionArgs) {
    if (opType != QUERY_OPERATION_DELETE)
        throw new IllegalArgumentException("Not a delete query");
    return ContentProviderOperation.newDelete(uri).withSelection(selection, selectionArgs).build();
}

From source file:org.exfio.csyncdroid.resource.LocalAddressBook.java

public void deleteAllExceptUIDs(String[] preserveUids) {
    String where;//w ww . j  av a 2s.co  m

    if (preserveUids.length != 0) {
        where = entryColumnUID() + " NOT IN (" + SQLUtils.quoteArray(preserveUids) + ")";
    } else
        where = entryColumnUID() + " IS NOT NULL";

    Builder builder = ContentProviderOperation.newDelete(entriesURI()).withSelection(where, null);
    pendingOperations.add(builder.withYieldAllowed(true).build());
}

From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java

private void syncEvents(ContentProviderClient provider, String cookie) {
    try {//w w  w.  j  a  v a  2s . com
        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);
    }
}

From source file:org.c99.SyncProviderDemo.ContactsSyncAdapterService.java

private static void updateContactPhoto(ArrayList<ContentProviderOperation> operationList, long rawContactId,
        byte[] photo) {
    ContentProviderOperation.Builder builder = ContentProviderOperation
            .newDelete(ContactsContract.Data.CONTENT_URI);
    builder.withSelection(ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId + "' AND "
            + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
            + "'", null);
    operationList.add(builder.build());//from www . ja v  a 2s  .c om

    try {
        if (photo != null) {
            builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
            builder.withValue(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID, rawContactId);
            builder.withValue(ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
            builder.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo);
            operationList.add(builder.build());

            builder = ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI);
            builder.withSelection(RawContacts.CONTACT_ID + " = '" + rawContactId + "'", null);
            builder.withValue(PhotoTimestampColumn, String.valueOf(System.currentTimeMillis()));
            operationList.add(builder.build());
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:nuclei.persistence.Query.java

public ContentProviderOperation toDeleteOperation(QueryArgs args) {
    if (opType != QUERY_OPERATION_DELETE)
        throw new IllegalArgumentException("Not a delete query");
    args.validate(this);
    return ContentProviderOperation.newDelete(uri.toUri()).withSelection(selection, args.args()).build();
}