~ubuntu-branches/ubuntu/vivid/libsynthesis/vivid-201501071725

« back to all changes in this revision

Viewing changes to src/sysync/customimplds.cpp

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2010-11-20 19:50:44 UTC
  • mfrom: (3.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20101120195044-8s6wxqb2d0nmqdv3
Tags: 3.4.0.6+ds5-2
* Upload to unstable.
* Add missing commit from upstream 3.4.0.6+ds5

Show diffs side-by-side

added added

removed removed

Lines of Context:
2773
2773
      /// @todo sop_copy is now implemented by read/add sequence
2774
2774
      ///       in localEngineDS, but will be moved here later possibly
2775
2775
      case sop_add :
 
2776
        // check for duplicated add
 
2777
        // Note: server must check it here, because map lookup is needed. Contrarily, client
 
2778
        //       can check it on localengineds level against the pending maps list with isAddFromLastSession().
 
2779
        if (IS_SERVER && mappos!=fMapTable.end()) {
 
2780
                // we already know this item
 
2781
          // - status "already exists"
 
2782
          aStatusCommand.setStatusCode(418);
 
2783
          ok = false;
 
2784
          break;
 
2785
        }
2776
2786
        // add item and retrieve new localID for it
2777
2787
        sta = apiAddItem(*myitemP,localID);
2778
2788
        if (IS_SERVER) {
2874
2884
    if (ok) {
2875
2885
      // successful, save new localID in item
2876
2886
      myitemP->setLocalID(localID.c_str());
2877
 
      // make sure transaction is complete after processing the item
2878
2887
      TP_START(fSessionP->fTPInfo,li);
2879
2888
      return true;
2880
2889
    }
2881
2890
    else {
2882
 
      // make sure transaction is rolled back for this item
2883
2891
      TP_START(fSessionP->fTPInfo,li);
2884
2892
      return false;
2885
2893
    }
3275
3283
  string localid;
3276
3284
  LOCALID_TO_STRING(aLocalID,localid);
3277
3285
  TSyncSetList::iterator syncsetpos = findInSyncSet(localid.c_str());
3278
 
  if (syncsetpos==fSyncSetList.end())
3279
 
    return 404; // not found
3280
 
  // return sync item from syncset item (fetches data now if not fetched before)
3281
 
  return getItemFromSyncSetItem(*syncsetpos,aItemP);
 
3286
  if (syncsetpos==fSyncSetList.end()) {
 
3287
        // not found in current sync set, but could be a newly inserted item - try direct load
 
3288
    // - create new empty TMultiFieldItem
 
3289
    aItemP = (TMultiFieldItem *) newItemForRemote(ity_multifield);
 
3290
    if (!aItemP) return 510;
 
3291
    // - assign local id, as it is required e.g. by DoDataSubstitutions
 
3292
    aItemP->setLocalID(localid.c_str());
 
3293
    // - set default operation
 
3294
    aItemP->setSyncOp(sop_replace);
 
3295
                // - now fetch directly from DB
 
3296
        return apiFetchItem(*((TMultiFieldItem *)aItemP),true,NULL);
 
3297
  }
 
3298
  else {
 
3299
    // return sync item from syncset item (fetches data now if not fetched before)
 
3300
    return getItemFromSyncSetItem(*syncsetpos,aItemP);
 
3301
  }
3282
3302
} // TCustomImplDS::getItemByID
3283
3303
 
3284
3304
 
3285
3305
// private helper: get item with data from sync set list. Retrieves item if not already
3286
3306
// there from loading the sync set
 
3307
// Note: can be called with aSyncSetItemP==NULL, which causes directly loading from DB
 
3308
//       in all cases. 
3287
3309
localstatus TCustomImplDS::getItemFromSyncSetItem(TSyncSetItem *aSyncSetItemP, TSyncItem *&aItemP)
3288
3310
{
3289
 
  if (aSyncSetItemP->itemP) {
 
3311
  if (aSyncSetItemP && aSyncSetItemP->itemP) {
3290
3312
    // already fetched - pass it to caller and remove link in syncsetitem
3291
3313
    aItemP = aSyncSetItemP->itemP;
3292
3314
    aSyncSetItemP->itemP = NULL; // syncsetitem does not own it any longer
3298
3320
      (TMultiFieldItem *) newItemForRemote(ity_multifield);
3299
3321
    if (!aItemP)
3300
3322
      return 510;
3301
 
    // - assign local id, as it is required by DoDataSubstitutions
 
3323
    // - assign local id, as it is required e.g. by DoDataSubstitutions
3302
3324
    aItemP->setLocalID(aSyncSetItemP->localid.c_str());
3303
3325
    // - set default operation
3304
3326
    aItemP->setSyncOp(sop_replace);
3305
3327
    // Now fetch item (read phase)
3306
 
    localstatus sta=apiFetchItem(*((TMultiFieldItem *)aItemP),true,aSyncSetItemP);
 
3328
    localstatus sta = apiFetchItem(*((TMultiFieldItem *)aItemP),true,aSyncSetItemP);
3307
3329
    if (sta!=LOCERR_OK)
3308
3330
      return sta; // error
3309
3331
  }