List of usage examples for android.content ContentProviderOperation newInsert
public static Builder newInsert(Uri uri)
From source file:org.totschnig.myexpenses.model.Account.java
/** * deletes all expenses and updates account according to value of handleDelete * * @param filter if not null only expenses matched by filter will be deleted * @param handleDelete if equals {@link #EXPORT_HANDLE_DELETED_UPDATE_BALANCE} opening balance will * be adjusted to account for the deleted expenses, * if equals {@link #EXPORT_HANDLE_DELETED_CREATE_HELPER} a helper transaction * @param helperComment/*w ww .ja v a 2s.c o m*/ */ public void reset(WhereFilter filter, int handleDelete, String helperComment) { ArrayList<ContentProviderOperation> ops = new ArrayList<>(); ContentProviderOperation handleDeleteOperation = null; if (handleDelete == EXPORT_HANDLE_DELETED_UPDATE_BALANCE) { long currentBalance = getFilteredBalance(filter).getAmountMinor(); openingBalance.setAmountMinor(currentBalance); handleDeleteOperation = ContentProviderOperation .newUpdate(CONTENT_URI.buildUpon().appendPath(String.valueOf(getId())).build()) .withValue(KEY_OPENING_BALANCE, currentBalance).build(); } else if (handleDelete == EXPORT_HANDLE_DELETED_CREATE_HELPER) { Transaction helper = new Transaction(this, getTransactionSum(filter)); helper.comment = helperComment; helper.status = STATUS_HELPER; handleDeleteOperation = ContentProviderOperation.newInsert(Transaction.CONTENT_URI) .withValues(helper.buildInitialValues()).build(); } String rowSelect = buildTransactionRowSelect(filter); String[] selectionArgs = new String[] { String.valueOf(getId()) }; if (filter != null && !filter.isEmpty()) { selectionArgs = Utils.joinArrays(selectionArgs, filter.getSelectionArgs(false)); } ops.add(updateTransferPeersForTransactionDelete(rowSelect, selectionArgs)); ops.add(ContentProviderOperation.newDelete(Transaction.CONTENT_URI) .withSelection(KEY_ROWID + " IN (" + rowSelect + ")", selectionArgs).build()); //needs to be last, otherwise helper transaction would be deleted if (handleDeleteOperation != null) ops.add(handleDeleteOperation); try { cr().applyBatch(TransactionProvider.AUTHORITY, ops); } catch (Exception e) { AcraHelper.report(e); e.printStackTrace(); } }
From source file:org.sufficientlysecure.keychain.provider.ProviderHelper.java
/** * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing *//*from w ww . j a v a 2s. c om*/ private ContentProviderOperation buildPublicKeyOperations(long masterKeyId, UncachedPublicKey key, int rank) throws IOException { ContentValues values = new ContentValues(); values.put(Keys.MASTER_KEY_ID, masterKeyId); values.put(Keys.RANK, rank); values.put(Keys.KEY_ID, key.getKeyId()); values.put(Keys.KEY_SIZE, key.getBitStrength()); values.put(Keys.ALGORITHM, key.getAlgorithm()); values.put(Keys.FINGERPRINT, key.getFingerprint()); values.put(Keys.CAN_CERTIFY, key.canCertify()); values.put(Keys.CAN_SIGN, key.canSign()); values.put(Keys.CAN_ENCRYPT, key.canEncrypt()); values.put(Keys.IS_REVOKED, key.maybeRevoked()); values.put(Keys.CREATION, key.getCreationTime().getTime() / 1000); Date expiryDate = key.getExpiryTime(); if (expiryDate != null) { values.put(Keys.EXPIRY, expiryDate.getTime() / 1000); } Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId)); return ContentProviderOperation.newInsert(uri).withValues(values).build(); }
From source file:fr.mixit.android.io.JsonHandlerApplyMembers.java
private void parseSharedLinks(String itemId, JSONArray sharedLinks, ContentResolver resolver) throws JSONException { final HashSet<String> sharedLinksIds = Sets.newHashSet(); for (int j = 0; j < sharedLinks.length(); j++) { final JSONObject sharedLink = sharedLinks.getJSONObject(j); final String id = sharedLink.getString(TAG_ID); sharedLinksIds.add(id);/*from w w w . j a va 2 s .c om*/ final Uri sharedLinkUri = MixItContract.SharedLinks.buildSharedLinkUri(id); boolean sharedLinkUpdated = false; boolean newSharedLink = false; boolean build = false; ContentProviderOperation.Builder builder; if (ProviderParsingUtils.isRowExisting(sharedLinkUri, MixItContract.SharedLinks.PROJ.PROJECTION, resolver)) { builder = ContentProviderOperation.newUpdate(sharedLinkUri); sharedLinkUpdated = isSharedLinkUpdated(sharedLinkUri, itemId, sharedLink, resolver); } else { newSharedLink = true; builder = ContentProviderOperation.newInsert(MixItContract.SharedLinks.CONTENT_URI); builder.withValue(MixItContract.SharedLinks.SHARED_LINK_ID, id); build = true; } if (newSharedLink || sharedLinkUpdated) { if (sharedLink.has(TAG_ORDER_NUM)) { builder.withValue(MixItContract.SharedLinks.ORDER_NUM, sharedLink.getInt(TAG_ORDER_NUM)); } if (sharedLink.has(TAG_NAME)) { builder.withValue(MixItContract.SharedLinks.NAME, sharedLink.getString(TAG_NAME)); } if (sharedLink.has(TAG_URL)) { builder.withValue(MixItContract.SharedLinks.URL, sharedLink.getString(TAG_URL)); } builder.withValue(MixItContract.SharedLinks.MEMBER_ID, itemId); build = true; } if (build) { ProviderParsingUtils.addOpeAndApplyBatch(mAuthority, resolver, mBatch, false, builder.build()); } } mItemSharedLinksIds.put(itemId, sharedLinksIds); }
From source file:org.mythtv.service.dvr.v27.RecordedHelperV27.java
private void processProgramGroups(final Context context, final LocationProfile locationProfile, Program[] programs) throws RemoteException, OperationApplicationException { Log.v(TAG, "processProgramGroups : enter"); if (null == context) throw new RuntimeException("RecordedHelperV27 is not initialized"); Map<String, ProgramGroup> programGroups = new TreeMap<String, ProgramGroup>(); for (Program program : programs) { if (null != program.getRecording()) { if (null != program.getRecording().getRecGroup() && !"livetv".equalsIgnoreCase(program.getRecording().getRecGroup()) && !"deleted".equalsIgnoreCase(program.getRecording().getRecGroup())) { String cleaned = ArticleCleaner.clean(program.getTitle()); if (!programGroups.containsKey(cleaned)) { ProgramGroup programGroup = new ProgramGroup(); programGroup.setTitle(program.getTitle()); programGroup.setCategory(program.getCategory()); programGroup.setInetref(program.getInetref()); programGroup.setSort(0); programGroups.put(cleaned, programGroup); }/*from w w w . j a v a2 s .c o m*/ } } } int processed = -1; int count = 0; ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); Log.v(TAG, "processProgramGroups : adding 'All' program group in programGroups"); ProgramGroup all = new ProgramGroup(null, "All", "All", "All", "", 1); programGroups.put(all.getProgramGroup(), all); String[] programGroupProjection = new String[] { ProgramGroupConstants._ID }; String programGroupSelection = ProgramGroupConstants.FIELD_PROGRAM_GROUP + " = ?"; programGroupSelection = appendLocationHostname(context, locationProfile, programGroupSelection, null); for (String key : programGroups.keySet()) { Log.v(TAG, "processProgramGroups : processing programGroup '" + key + "'"); ProgramGroup programGroup = programGroups.get(key); ContentValues programValues = convertProgramGroupToContentValues(locationProfile, programGroup); Cursor programGroupCursor = context.getContentResolver().query(ProgramGroupConstants.CONTENT_URI, programGroupProjection, programGroupSelection, new String[] { key }, null); if (programGroupCursor.moveToFirst()) { Long id = programGroupCursor .getLong(programGroupCursor.getColumnIndexOrThrow(ProgramGroupConstants._ID)); ops.add(ContentProviderOperation .newUpdate(ContentUris.withAppendedId(ProgramGroupConstants.CONTENT_URI, id)) .withValues(programValues).withYieldAllowed(true).build()); } else { ops.add(ContentProviderOperation.newInsert(ProgramGroupConstants.CONTENT_URI) .withValues(programValues).withYieldAllowed(true).build()); } programGroupCursor.close(); count++; if (count > 100) { Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions"); processBatch(context, ops, processed, count); } } if (!ops.isEmpty()) { Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions"); processBatch(context, ops, processed, count); } Log.v(TAG, "processProgramGroups : remove deleted program groups"); ops = new ArrayList<ContentProviderOperation>(); DateTime lastModified = new DateTime(); lastModified = lastModified.minusHours(1); String deleteProgramGroupSelection = ProgramGroupConstants.FIELD_LAST_MODIFIED_DATE + " < ?"; String[] deleteProgramGroupArgs = new String[] { String.valueOf(lastModified.getMillis()) }; deleteProgramGroupSelection = appendLocationHostname(context, locationProfile, deleteProgramGroupSelection, ProgramGroupConstants.TABLE_NAME); ops.add(ContentProviderOperation.newDelete(ProgramGroupConstants.CONTENT_URI) .withSelection(deleteProgramGroupSelection, deleteProgramGroupArgs).withYieldAllowed(true).build()); if (!ops.isEmpty()) { Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions"); processBatch(context, ops, processed, count); } Log.v(TAG, "processProgramGroups : exit"); }
From source file:org.linphone.ContactEditorFragment.java
private void setContactPhoto() { ContentResolver cr = getActivity().getContentResolver(); Uri updateUri = ContactsContract.Data.CONTENT_URI; if (photoToAdd != null) { //New contact if (isNewContact) { ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, contactID) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd).build()); } else { //update contact picture String w = ContactsContract.Data.CONTACT_ID + "='" + contact.getID() + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'"; Cursor queryCursor = cr.query(updateUri, new String[] { ContactsContract.Data._ID }, w, null, null); if (queryCursor == null) { try { throw new SyncFailedException("EE"); } catch (SyncFailedException e) { e.printStackTrace(); }// w ww. j a va 2 s .c o m } else { if (contact.getPhoto() == null) { String rawContactId = ContactsManager.getInstance().findRawContactID(cr, String.valueOf(contactID)); ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd).build()); } if (queryCursor.moveToFirst()) { // otherwise no photo int colIdx = queryCursor.getColumnIndex(ContactsContract.Data._ID); long id = queryCursor.getLong(colIdx); ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) .withSelection(ContactsContract.Data._ID + "= ?", new String[] { String.valueOf(id) }) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd).build()); } queryCursor.close(); } } } }
From source file:org.sufficientlysecure.keychain.provider.ProviderHelper.java
/** * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing *//* w w w . jav a 2s .c om*/ private ContentProviderOperation buildCertOperations(long masterKeyId, int rank, WrappedSignature cert, int verified) throws IOException { ContentValues values = new ContentValues(); values.put(Certs.MASTER_KEY_ID, masterKeyId); values.put(Certs.RANK, rank); values.put(Certs.KEY_ID_CERTIFIER, cert.getKeyId()); values.put(Certs.TYPE, cert.getSignatureType()); values.put(Certs.CREATION, cert.getCreationTime().getTime() / 1000); values.put(Certs.VERIFIED, verified); values.put(Certs.DATA, cert.getEncoded()); Uri uri = Certs.buildCertsUri(Long.toString(masterKeyId)); return ContentProviderOperation.newInsert(uri).withValues(values).build(); }
From source file:org.thialfihar.android.apg.provider.ProviderHelper.java
/** * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing *//* w ww .ja v a2 s .c o m*/ private ContentProviderOperation buildPublicKeyOperations(long masterKeyId, PGPPublicKey key, int rank) throws IOException { ContentValues values = new ContentValues(); values.put(Keys.MASTER_KEY_ID, masterKeyId); values.put(Keys.RANK, rank); values.put(Keys.KEY_ID, key.getKeyID()); values.put(Keys.KEY_SIZE, key.getBitStrength()); values.put(Keys.ALGORITHM, key.getAlgorithm()); values.put(Keys.FINGERPRINT, key.getFingerprint()); values.put(Keys.CAN_CERTIFY, (PgpKeyHelper.isCertificationKey(key))); values.put(Keys.CAN_SIGN, (PgpKeyHelper.isSigningKey(key))); values.put(Keys.CAN_ENCRYPT, PgpKeyHelper.isEncryptionKey(key)); values.put(Keys.IS_REVOKED, key.isRevoked()); values.put(Keys.CREATION, PgpKeyHelper.getCreationDate(key).getTime() / 1000); Date expiryDate = PgpKeyHelper.getExpiryDate(key); if (expiryDate != null) { values.put(Keys.EXPIRY, expiryDate.getTime() / 1000); } Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId)); return ContentProviderOperation.newInsert(uri).withValues(values).build(); }
From source file:org.totschnig.myexpenses.sync.SyncAdapter.java
private void writeRemoteChangesToDbPart(ContentProviderClient provider, List<TransactionChange> remoteChanges, long accountId) throws RemoteException, OperationApplicationException { ArrayList<ContentProviderOperation> ops = new ArrayList<>(); ops.add(ContentProviderOperation .newInsert(TransactionProvider.DUAL_URI.buildUpon() .appendQueryParameter(TransactionProvider.QUERY_PARAMETER_SYNC_BEGIN, "1").build()) .build());//w ww. j a v a 2 s. c o m Stream.of(remoteChanges).filter(change -> !(change.isCreate() && uuidExists(change.uuid()))) .forEach(change -> collectOperations(change, accountId, ops, -1)); ops.add(ContentProviderOperation.newDelete(TransactionProvider.DUAL_URI.buildUpon() .appendQueryParameter(TransactionProvider.QUERY_PARAMETER_SYNC_END, "1").build()).build()); ContentProviderResult[] contentProviderResults = provider.applyBatch(ops); int opsSize = ops.size(); int resultsSize = contentProviderResults.length; if (opsSize != resultsSize) { AcraHelper.report( String.format(Locale.ROOT, "applied %d operations, received %d results", opsSize, resultsSize)); } }
From source file:org.sufficientlysecure.keychain.provider.ProviderHelper.java
/** * Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing *//* w ww .ja v a 2s. c o m*/ private ContentProviderOperation buildUserIdOperations(long masterKeyId, UserIdItem item, int rank) { ContentValues values = new ContentValues(); values.put(UserIds.MASTER_KEY_ID, masterKeyId); values.put(UserIds.USER_ID, item.userId); values.put(UserIds.IS_PRIMARY, item.isPrimary); values.put(UserIds.IS_REVOKED, item.isRevoked); values.put(UserIds.RANK, rank); Uri uri = UserIds.buildUserIdsUri(Long.toString(masterKeyId)); return ContentProviderOperation.newInsert(uri).withValues(values).build(); }