2773
2773
/// @todo sop_copy is now implemented by read/add sequence
2774
2774
/// in localEngineDS, but will be moved here later possibly
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);
2776
2786
// add item and retrieve new localID for it
2777
2787
sta = apiAddItem(*myitemP,localID);
2778
2788
if (IS_SERVER) {
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);
2882
// make sure transaction is rolled back for this item
2883
2891
TP_START(fSessionP->fTPInfo,li);
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);
3299
// return sync item from syncset item (fetches data now if not fetched before)
3300
return getItemFromSyncSetItem(*syncsetpos,aItemP);
3282
3302
} // TCustomImplDS::getItemByID
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
3287
3309
localstatus TCustomImplDS::getItemFromSyncSetItem(TSyncSetItem *aSyncSetItemP, TSyncItem *&aItemP)
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);
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