diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-04 10:36:58 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-04 10:36:58 +0100 |
commit | 59aa460cf704d5f1a1fb1fe6b8ede4457da083ff (patch) | |
tree | d1cf394099e4897d2b8abf6817191c488c754667 /common/pipeline.cpp | |
parent | 41006b5cab7b0260f8abc42aa2d2e959a013764e (diff) | |
download | sink-59aa460cf704d5f1a1fb1fe6b8ede4457da083ff.tar.gz sink-59aa460cf704d5f1a1fb1fe6b8ede4457da083ff.zip |
Copy command and proper move
Diffstat (limited to 'common/pipeline.cpp')
-rw-r--r-- | common/pipeline.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 8ace855..b94e3f0 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp | |||
@@ -249,6 +249,7 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size) | |||
249 | } | 249 | } |
250 | 250 | ||
251 | if (modifyEntity->targetResource()) { | 251 | if (modifyEntity->targetResource()) { |
252 | auto isMove = modifyEntity->removeEntity(); | ||
252 | auto targetResource = BufferUtils::extractBuffer(modifyEntity->targetResource()); | 253 | auto targetResource = BufferUtils::extractBuffer(modifyEntity->targetResource()); |
253 | auto changeset = diff.changedProperties(); | 254 | auto changeset = diff.changedProperties(); |
254 | const auto current = d->entityStore.readLatest(bufferType, diff.identifier()); | 255 | const auto current = d->entityStore.readLatest(bufferType, diff.identifier()); |
@@ -276,9 +277,20 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size) | |||
276 | 277 | ||
277 | SinkTrace() << "Moving entity to new resource " << newEntity.identifier() << newEntity.resourceInstanceIdentifier() << targetResource; | 278 | SinkTrace() << "Moving entity to new resource " << newEntity.identifier() << newEntity.resourceInstanceIdentifier() << targetResource; |
278 | auto job = TypeHelper<CreateHelper>{bufferType}.operator()<KAsync::Job<void>, ApplicationDomain::ApplicationDomainType&>(newEntity); | 279 | auto job = TypeHelper<CreateHelper>{bufferType}.operator()<KAsync::Job<void>, ApplicationDomain::ApplicationDomainType&>(newEntity); |
279 | job = job.syncThen<void>([=](const KAsync::Error &error) { | 280 | job = job.syncThen<void>([this, newEntity, isMove, targetResource, bufferType](const KAsync::Error &error) { |
280 | if (!error) { | 281 | if (!error) { |
281 | SinkTrace() << "Move of " << newEntity.identifier() << "was successfull"; | 282 | SinkTrace() << "Move of " << newEntity.identifier() << "was successfull"; |
283 | if (isMove) { | ||
284 | startTransaction(); | ||
285 | flatbuffers::FlatBufferBuilder fbb; | ||
286 | auto entityId = fbb.CreateString(newEntity.identifier()); | ||
287 | auto type = fbb.CreateString(bufferType); | ||
288 | auto location = Sink::Commands::CreateDeleteEntity(fbb, newEntity.revision(), entityId, type, true); | ||
289 | Sink::Commands::FinishDeleteEntityBuffer(fbb, location); | ||
290 | const auto data = BufferUtils::extractBuffer(fbb); | ||
291 | deletedEntity(data, data.size()).exec(); | ||
292 | commit(); | ||
293 | } | ||
282 | } else { | 294 | } else { |
283 | SinkError() << "Failed to move entity " << targetResource << " to resource " << newEntity.identifier(); | 295 | SinkError() << "Failed to move entity " << targetResource << " to resource " << newEntity.identifier(); |
284 | } | 296 | } |