bool StorageHandler::replaceItem( const ItemId& aItemId, StoragePlugin& aPlugin, const QString& aLocalKey, const SyncItemKey& aParentKey, const QString& aType, const QString& aFormat, const QString& aVersion, const QString& aData ) { FUNCTION_CALL_TRACE; LOG_DEBUG( "Processing item for replace:" << aItemId.iCmdId <<"/" << aItemId.iItemIndex ); if( iLargeObject ) { LOG_CRITICAL( "Already processing large object, aborting" ); return false; } SyncItem* item = NULL; // If local key is empty, this Replace should be handled as Add (this is allowed by the protocol) if( !aLocalKey.isEmpty() ) { item = aPlugin.getSyncItem( aLocalKey ); } if( !item ) { LOG_DEBUG( "Could not find item, processing as Add" ); return addItem( aItemId, aPlugin, aLocalKey, aParentKey, aType, aFormat, aVersion, aData ); } item->setParentKey( aParentKey ); item->setType( aType ); item->setFormat( aFormat ); item->setVersion( aVersion ); if( !item->write( 0, aData.toUtf8() ) ) { delete item; LOG_CRITICAL( "Could not write to item" ); return false; } iReplaceList.insert( aItemId, item ); LOG_DEBUG( "Item queued for replace" ); return true; }
bool StorageHandler::startLargeObjectReplace( StoragePlugin& aPlugin, const QString& aLocalKey, const SyncItemKey& aParentKey, const QString& aType, const QString& aFormat, const QString& aVersion, qint64 aSize ) { FUNCTION_CALL_TRACE; if( iLargeObject ) { LOG_CRITICAL( "Already processing large object, aborting" ); return false; } SyncItem* item = NULL; // If local key is empty, this Replace should be handled as Add (this is allowed by the protocol) if( !aLocalKey.isEmpty() ) { item = aPlugin.getSyncItem( aLocalKey ); } if( !item ) { LOG_CRITICAL( "Could not find item, processing as Add" ); return startLargeObjectAdd( aPlugin, aLocalKey, aParentKey, aType, aFormat, aVersion, aSize ); } item->setParentKey( aParentKey ); item->setType( aType ); item->setFormat( aFormat ); item->setVersion( aVersion ); iLargeObject = item; iLargeObjectSize = aSize; iLargeObjectKey = aLocalKey; if( !iLargeObject->resize(0) ) { LOG_DEBUG( "Large object created for replace couldn't be resized" ); } LOG_DEBUG( "Large object created for replace" ); return true; }
bool StorageHandler::addItem( const ItemId& aItemId, StoragePlugin& aPlugin, const SyncItemKey& aLocalKey, const SyncItemKey& aParentKey, const QString& aType, const QString& aFormat, const QString& aVersion, const QString& aData ) { FUNCTION_CALL_TRACE; LOG_DEBUG( "Processing item for add:" << aItemId.iCmdId <<"/" << aItemId.iItemIndex ); if( iLargeObject ) { LOG_CRITICAL( "Already processing large object, aborting" ); return false; } SyncItem* newItem = aPlugin.newItem(); if( !newItem ) { LOG_CRITICAL( "Could not create new item" ); return false; } //Setting empty string as we dont have any local key for it. newItem->setKey( aLocalKey ); newItem->setParentKey( aParentKey ); newItem->setType( aType ); newItem->setFormat( aFormat ); newItem->setVersion( aVersion ); if( !newItem->write( 0, aData.toUtf8() ) ) { delete newItem; LOG_CRITICAL( "Could not write to item" ); return false; } iAddList.insert( aItemId, newItem ); LOG_DEBUG( "Item queued for addition" ); return true; }
bool StorageHandler::startLargeObjectAdd( StoragePlugin& aPlugin, const QString& aRemoteKey, const SyncItemKey& aParentKey, const QString& aType, const QString& aFormat, const QString& aVersion, qint64 aSize ) { FUNCTION_CALL_TRACE; if( iLargeObject ) { LOG_CRITICAL( "Already processing large object, aborting" ); return false; } SyncItem* newItem = aPlugin.newItem(); if( !newItem ) { LOG_CRITICAL( "Could not create new item for large object" ); return false; } //Setting empty string as we dont have any local key for it. newItem->setKey(QString()); newItem->setParentKey( aParentKey ); newItem->setType( aType ); newItem->setFormat( aFormat ); newItem->setVersion( aVersion ); iLargeObject = newItem; iLargeObjectSize = aSize; iLargeObjectKey = aRemoteKey; LOG_DEBUG( "Large object created for addition" ); return true; }