コード例 #1
0
 public void buildCapsuleUpdate(Capsule capsule, boolean withYield) {
   // URI for updating a Capsule
   Uri uri = ContentUris.withAppendedId(CapsuleContract.Capsules.CONTENT_URI, capsule.getId());
   // Build the UPDATE operation
   ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(uri);
   builder.withValues(Capsules.buildContentValues(capsule));
   builder.withYieldAllowed(withYield);
   // Add it to the collection
   this.mOperations.add(builder.build());
 }
コード例 #2
0
  public void buildCapsuleDelete(Capsule capsule, boolean withYield) {
    // Build the Capsule URI
    Uri uri = ContentUris.withAppendedId(CapsuleContract.Capsules.CONTENT_URI, capsule.getId());

    // Build the DELETE operation
    this.mOperations.add(
        ContentProviderOperation.newDelete(uri).withYieldAllowed(withYield).build());
    // Get the capsule ID
    String capsuleId = String.valueOf(capsule.getId());
    // Build the Discovery DELETE operation
    this.mOperations.add(
        ContentProviderOperation.newDelete(CapsuleContract.Discoveries.CONTENT_URI)
            .withSelection(
                CapsuleContract.Discoveries.CAPSULE_ID + " = ?", new String[] {capsuleId})
            .withYieldAllowed(false)
            .build());
    // Build the Ownership DELETE operation
    this.mOperations.add(
        ContentProviderOperation.newDelete(CapsuleContract.Ownerships.CONTENT_URI)
            .withSelection(CapsuleContract.Ownerships.CAPSULE_ID + " = ?", new String[] {capsuleId})
            .withYieldAllowed(false)
            .build());
  }
コード例 #3
0
 public void buildDiscoverySave(Capsule capsule, CapsuleContract.SyncStateAction syncAction) {
   // Make sure there is a sync ID
   if (capsule.getSyncId() <= 0) {
     throw new InvalidParameterException("The Capsule does not have a sync ID");
   }
   // Determine the best IDs for the Capsule
   CapsuleOperations.Capsules.determineBestId(this.mResolver, this, capsule);
   CapsuleOperations.Discoveries.determineBestId(this.mResolver, this, (CapsuleDiscovery) capsule);
   // Build INSERT/UPDATE operations depending on if the Capsule and Discovery already exist
   if (capsule.getId() > 0) {
     // Capsule UPDATE
     this.buildCapsuleUpdate(capsule, /* withYield */ true);
     // Check if the Discovery exists
     if (((CapsuleDiscovery) capsule).getDiscoveryId() > 0) {
       // Discovery UPDATE
       this.buildDiscoveryUpdate((CapsuleDiscovery) capsule, /* withYield */ false, syncAction);
     } else {
       // Discovery INSERT
       this.buildDiscoveryInsert((CapsuleDiscovery) capsule, /* withYield */ false, syncAction);
     }
   } else {
     // Capsule INSERT
     this.buildCapsuleInsert(capsule, /* withYield */ true);
     // Check if the Discovery exists
     if (((CapsuleDiscovery) capsule).getDiscoveryId() > 0) {
       // Discovery UPDATE
       this.buildDiscoveryUpdate(
           (CapsuleDiscovery) capsule, /* withYield */
           false,
           this.getLastOperationIndex(),
           syncAction);
     } else {
       // Discovery INSERT
       this.buildDiscoveryInsert(
           (CapsuleDiscovery) capsule, /* withYield */
           false,
           this.getLastOperationIndex(),
           syncAction);
     }
   }
 }
コード例 #4
0
 public void buildOwnershipSave(Capsule capsule, CapsuleContract.SyncStateAction syncAction) {
   // Determine the best IDs for the Capsule
   CapsuleOperations.Capsules.determineBestId(this.mResolver, this, capsule);
   CapsuleOperations.Ownerships.determineBestId(this.mResolver, this, (CapsuleOwnership) capsule);
   // Build the INSERT/UPDATE operations depending on if the Capsule and Ownership exist
   if (capsule.getId() > 0) {
     // Capsule UPDATE
     this.buildCapsuleUpdate(capsule, /* withYield */ true);
     // Check if the Ownership exists
     if (((CapsuleOwnership) capsule).getOwnershipId() > 0) {
       // Ownership UPDATE
       this.buildOwnershipUpdate((CapsuleOwnership) capsule, /* withYield */ false, syncAction);
     } else {
       // Ownership INSERT
       this.buildOwnershipInsert((CapsuleOwnership) capsule, /* withYield */ false, syncAction);
     }
   } else {
     // Capsule INSERT
     this.buildCapsuleInsert(capsule, /* withYield */ true);
     // Check if the Ownership exists
     if (((CapsuleOwnership) capsule).getOwnershipId() > 0) {
       // Ownership UPDATE
       this.buildOwnershipUpdate(
           (CapsuleOwnership) capsule, /* withYield */
           false,
           this.getLastOperationIndex(),
           syncAction);
     } else {
       // Ownership INSERT
       this.buildOwnershipInsert(
           (CapsuleOwnership) capsule, /* withYield */
           false,
           this.getLastOperationIndex(),
           syncAction);
     }
   }
 }